# tsp2.run model tsp.mod; #data tsp.dat; data ger_part.dat; for {i in V, j in V : i > j} { # distance matrix must be symmetric let d[i,j] := d[j,i]; } option solver cplex; option solver_msg 0; # don't print CPLEX messages let subtours := 0; # data structures required for the algorithm param current >= 0, integer; param termination binary; let termination := 0; repeat while (termination = 0) { # iterative part solve; # solve the problem let subtours := subtours + 1; # find a subtour let current := 1; let S[subtours] := {}; repeat { let S[subtours] := S[subtours] union {current}; let current := sum{j in V} j * x[current,j]; # the sum gives j where x[current,j]==1. } until (current = 1); # until we arrive back to 1 printf "(sub)tour: ("; # print the subtour we wish to eliminate for {i in S[subtours]} { printf "%d -> ", i ; } printf "1)\n"; if (card(S[subtours]) >= n) then { # termination condition let termination := 1; } } printf "travelled distance in the optimal tour: %f\n", distance;