http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> Hi there, i need some help for the traveling salesman prob in C

> I have an array with distances to cities

>

> A B C D E

> A 0 5 7 1 9

> B 5 0

> C 7 0

> D 1 0

> E 9 0

> etc.................................

>

>

> With a brute force i get all combinations ABCDE ABDCE ABCED ...........

>

> I guess i have to use 5 for loops. Not sure how to do that.

> In a corresponding array i store the distances by claculating with the

> help of the table look up.

> SOS....HELP URGENT

>

>

> THANKING YOU ALL IN ADVANCE

>

>

> CLUESSSSS????????
No , you don't have to write 5 for loops. What if you

had 10 cities , would you write 10 loops ? What you

do need is a way to generate all permutations of the

string ABCDE. Search this group for the word

"permutations" and you'll find threads with plenty

of advice and possibly a complete solution.

The other thing to consider is that there are two

variations of the salesman problem. In the first

variation the salesman has to return to the city

where he started his trip so he visits this city and

only this twice. In the second variation he visits

every city exactly once. If it is the first variation

you want to solve then you need to take into account

that for every permutation there are 4 others which

produce the same total distance. For example the

permutations ABCDE , BCDEA , CDEAB , DEABC ,

EABCD all describe a trip with the same total distance.