model tsp.mod; data tsp.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; solve; display distance; #display x; param i default 1; printf "Subtour: 1 -> "; repeat while (1) { let i:= sum {j in V} j*x[i,j]; # the sum gives j where x[i,j]==1. if (i==1) then break; printf "%d -> ", i; } printf "1.\n\n"; let subtours := 1; let S[1] := { 1, 3, 5 }; solve; printf "Hamilton tour: 1 -> "; repeat { let i:= sum {j in V} j*x[i,j]; printf "%d -> ", i; } until i=1; printf "1.\n\n";