# Simulated Annealing Algorithm for TSP

Today, I am trying to solve TSP (Traveling Salesman Problem) by using simulated annealing algorithm. That means I have to make a loop with injecting other case of path to the algorithm. Here is the pseudo-code for simulated annealing algorithm.

1. Evaluate the initial order
2. current order := initial order
3. BEST-SO-FAR := current order
4. TEMP := constant, STOP_TEMP := constant, COOLING_RATE := constant
5. UNTIL TEMP < constant DO
1. Create new order by swap randomly one pair of current order
2. Evaluate new order
IF
new order is better than the current order THEN{
+current order := new order
+IF
the new order is better than BEST-SO-FAR THEN{
++BEST-SO-FAR := new order }
ELSE IF
the new order is not better than the current order  THEN {
+${\Delta}E$ := distance of current order – distance of new order
+IF
$e^{-{\Delta}E/T}>random(0,1)$ THEN
++current order := new order
}
3. Revised TEMP by multiply with COOLING_RATE
6. Return BEST-SO-FAR as the answer

As I hope you might see 5.1, the algorithm will create another order for evaluation by swapping randomly. This is not good and causes in an ineffective result since the new created order will be the same with the old one again and again. The best solution for this may be permutation. Let’s see the link for how to use permutation in programming.

Advertisements