i have seen many solution that try to solve the problem of travelling salesman problem if p!=np ,but i want to know the optimum solution if there is 6 or 5 cities only,which algorithm will give the optimum solution in this case?
-
1With only six cities, exhaustive search is not a problem, since there are just 720 paths possible, hence this is solved in milliseconds. Note that if all parameters have an upperbound, there is no *asymptotic behavior*, so P and NP do not have "much meaning" here. – Willem Van Onsem Jan 26 '19 at 13:43
-
i want just to know which algorithm will tell me the optimum solution in this case ? – Mohamed Abo AL Kear Jan 26 '19 at 13:45
-
just use a [*branch and bound*](https://en.wikipedia.org/wiki/Branch_and_bound) approach. – Willem Van Onsem Jan 26 '19 at 13:47
-
because all solution of np problems not optimum because it take long time ,so algorithms appear to try save time but give sub optimum solution – Mohamed Abo AL Kear Jan 26 '19 at 13:47
-
those are *strictly* speaking not solutions, but *heuristic* algorithms that come up with an *approximative* solution. – Willem Van Onsem Jan 26 '19 at 13:48
-
thanks for help ...@WillemVanOnsem – Mohamed Abo AL Kear Jan 26 '19 at 13:53
1 Answers
For 6
cities, compute the 15
inter-city distances once for all, then choose a starting point and evaluate the possible 5!/2=60
cycles (half of them are identical by direction reversal).
For maximum efficiency, you could hard-code the permutation table. Another possible measure is to arrange the cycle length computation in such a way that some partial sums can be reused, also with the help of hard-coded tables.
Premature abortion of some summations is possible as soon as they exceed the current shortest. It is likely that some more can be gained by trying the shortest segments in the first place.
A thorough exploration of these topics seems an endeavour, and the savings are probably not worth the care, unless you have millions 6-cities problems to solve.
-
Yes, big-oh is only relevant if one reaches a threshold, as is micro-optimisation. – Deduplicator Jan 26 '19 at 14:27
-
@Deduplicator: I have the feeling that by combining some micro-optimizations a factor 2 to 4 could be achieved. Depending on context, the effort may make sense or not. – Jan 26 '19 at 14:44
-
And you can solve these kind of problems easily with Genetics-Algorithm. – Khan Saab Jan 26 '19 at 20:08
-
@KhanSaab: for small-sized problems, the genetic approach is quite inappropriate. Read the question. – Jan 27 '19 at 15:47