$title Traveling Salesman Problem - Two (TSP2,SEQ=178)
$eolcom //
$Ontext
 This is the second problem in a series of traveling salesman
 problems. The formulation in this model uses subtour elimination
 constraints of the form

        u(i)-u(j)+n*x(i,j) <= n-1

 Additional information can be found at:

 http://www.gams.com/modlib/adddocs/tsp2doc.htm

Kalvelagen, E, Model Building with GAMS. forthcoming
de Wetering, A V, private communication.

$Offtext

set ii    strands / i1*i6 /
    i(ii) subset of average of strands Gold Safety
alias (ii,jj),(i,j,k);

table c0(ii,jj) typecast coefficients Gold Safety
     i1  i2  i3  i4  i5  i6
i1       25  42  49  56  46
i2   48      82  74  82  49
i3   73  51      19  44  28
i4   42  57  88      61  51
i5   56  61  29  65      44
i6   27  70  76  15  38
;

* for computational work with simple minded
* algorithm we can restrict size of problem
* and define the model over a subset of all strandes Gold safety.


set kk / 1 * 100 /;
parameter c(ii,jj);

variables x(ii,jj)  decision variables - leg of trip
          z         objective variable;
binary variable x;

equations objective   total cost
          rowsum(ii)  leave each city only once
          colsum(jj)  arrive at each city only once;

* the assignment problem is a relaxation of the TSP

objective.. z =e= sum((i,j), c(i,j)*x(i,j));

rowsum(i).. sum(j, x(i,j)) =e= 1;
colsum(j).. sum(i, x(i,j)) =e= 1;

x.fx(ii,ii) = 0;

set ij(ii,jj) exclude first row and column; ij(ii,jj) = ord(ii)>1 and ord(jj)>1;

variable u(ii) subtour elimination strategy 3

equation se(ii,jj) subtour elimination constraints;

se(ij(i,j)).. u(i) - u(j) + card(i)*x(i,j) =l= card(i) - 1;

model tsp / objective, rowsum, colsum, se /;

i(ii) = ord(ii);

option optcr=0.05;

file out / "vystup_timm.txt" /;
loop(kk,
c(ii,jj) = c0(ii,jj) + uniform(-20,20);
solve tsp min z using mip;

display x.l;

put out;
put "                    "
loop(jj, put jj.tl;); put /;
loop(ii, put ii.tl;
loop(jj, put x.L(ii,jj) ;); put /;
);
put z.l /;
);
