I am writing a travelling salesman program, which is to calculate distance between all the points and determine the shortest distance using the BRUTE Force method. This is not homework :)
My approach is to generate all the possible points arrangement first, using the std next_permutation function.
Using the std next_permutation function will generate the output orders:
(assume that there are 3 points)
123
132
213
231
312
321
(same with if there are 4 points)
1234
1243
...
4312
4321
However the program is slow due to repetitive, such as the distance of 123 is the same with 321 (although I did not run the calculations twice, I have saved each distance into a struct). Lets take back the example with 3 points AFTER I eliminate the repeating, the output will now become
123
132
213
saving at least half the work, more as the number of points increases. I have written out a few alternatives to eliminate the repetitive orders however have no idea how to express it out in a code (help).
I will post the few alternatives that I have figured out here, if requested.
If anyone could post your idea in the form of pseudocode, on how can I eliminate the repetitive orders. Thanks!