MCPcopy Create free account
hub / github.com/Gecode/gecode / TSP

Method TSP

examples/tsp.cpp:237–271  ·  view source on GitHub ↗

Actual model

Source from the content-addressed store, hash-verified

235public:
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;

Callers

nothing calls this directly

Calls 12

circuitFunction · 0.85
INT_VAR_REGRET_MAX_MAXFunction · 0.85
INT_VAL_MINFunction · 0.85
INT_VAR_MIN_MINFunction · 0.85
relFunction · 0.50
elementFunction · 0.50
branchFunction · 0.50
sizeMethod · 0.45
maxMethod · 0.45
dMethod · 0.45
iplMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected