Actual model
| 235 | public: |
| 236 | /// Actual model |
| 237 | TSP(const SizeOptions& opt) |
| 238 | : IntMinimizeScript(opt), |
| 239 | p(ps[opt.size()]), |
| 240 | succ(*this, p.size(), 0, p.size()-1), |
| 241 | total(*this, 0, p.max()) { |
| 242 | int n = p.size(); |
| 243 | |
| 244 | // Cost matrix |
| 245 | IntArgs c(n*n, p.d()); |
| 246 | |
| 247 | // Disallow disconnected nodes |
| 248 | for (int i=0; i<n; i++) |
| 249 | for (int j=0; j<n; j++) |
| 250 | if (p.d(i,j) == 0) |
| 251 | rel(*this, succ[i], IRT_NQ, j); |
| 252 | |
| 253 | // Cost of each edge |
| 254 | IntVarArgs costs(*this, n, Int::Limits::min, Int::Limits::max); |
| 255 | |
| 256 | // Enforce that the successors yield a tour with appropriate costs |
| 257 | circuit(*this, c, succ, costs, total, opt.ipl()); |
| 258 | |
| 259 | // Just assume that the circle starts forwards |
| 260 | { |
| 261 | IntVar p0(*this, 0, n-1); |
| 262 | element(*this, succ, p0, 0); |
| 263 | rel(*this, p0, IRT_LE, succ[0]); |
| 264 | } |
| 265 | |
| 266 | // First enumerate cost values, prefer those that maximize cost reduction |
| 267 | branch(*this, costs, INT_VAR_REGRET_MAX_MAX(), INT_VAL_MIN()); |
| 268 | |
| 269 | // Then fix the remaining successors |
| 270 | branch(*this, succ, INT_VAR_MIN_MIN(), INT_VAL_MIN()); |
| 271 | } |
| 272 | /// Return solution cost |
| 273 | virtual IntVar cost(void) const { |
| 274 | return total; |
nothing calls this directly
no test coverage detected