Page 1 of 1

finding Hamiltonian Path in TSP

Posted: Mon Jan 21, 2019 6:35 pm
by Parisa
Hello,
I have written piece of Code for controlling that whether the Answer is a complete Cycle(Hamiltonian Cycle) or it is just a Sub-tour in Travelling Salesman Problem. Suppose that we have an Answer which starts from City"1", if we have such a Cycle then "flag=1".
Any Help will be appreciated.

Code: Select all

loop(i$(ord(i)<>1),
         if(x.l('1',i)=1,
                 loop((j,v)$((ord(i)<>ord(j)) and (ord(j)<>ord(v)) and ord(i)<>ord(v)),
                         if(x.l(i,j)=1 and x.l(j,v)=1,
                                 loop(y$(ord(y)<>1),
                                         if(x.l(y,'1')=1,
                                                 flag=1;
                                         );
                                 );
                         );
                 );
         );
);
);
);

Re: finding Hamiltonian Path in TSP

Posted: Mon Jan 21, 2019 9:47 pm
by bussieck
Have you looked at the code of the TSP examples in GAMS Model Library? Some of them implement subtour elimination cuts and therefore need to answer exactly your question. See https://www.gams.com/latest/gamslib_ml/ ... ml#gamslib and search for tsp.

-Michael

Re: finding Hamiltonian Path in TSP

Posted: Tue Jan 22, 2019 5:55 am
by Parisa
I don't want to eliminate this answer, just want to check it's validity.

Re: finding Hamiltonian Path in TSP

Posted: Tue Jan 22, 2019 6:01 am
by bussieck
Same thing. The algorithm (for adding subtour cuts) terminates if there is no subtour. So just try to understand the algorithm to find the subtours.

-Michael

Re: finding Hamiltonian Path in TSP

Posted: Tue Jan 22, 2019 6:06 am
by Parisa
Thank you for that Link, That gave me other Ideas for coding.