0

I've been developing a small program that allows you to plot vertices in a graph and compute the shortest path between all of them. i.e. solves the Travelling Salesman Problem. I've programmed in the Simulated Annealing algorithm and the 2-opt algorithm. The problem I'm facing is that the results I get by using SA+2opt aren't any better than regular 2opt.

For the initial temperature, I use the average of the length of each edge in the random initial path I create, to be more invariant against rescaling. For the cooling rate, I make it inversely proportional to the number of vertices.

unsigned int dummy_int;
for (unsigned int i = 0; i < N; i++) {
    dummy_int = rand() % (N - i);
    TSPperm.push_back(vertexset[dummy_int]);
    vertexset.erase(vertexset.begin() + dummy_int);
}
vertexset = ID_PERM;

TSPvalue = 0;
for (unsigned int i = 0; i < N; i++) {
    TSPvalue += gra.get_weight(TSPperm[i], TSPperm[(i + 1) % N]);
}
tempmax = TSPvalue / N; //Scales temperature to be proportional to the average length of the graph's edges
temp = tempmax;
alpha = exp(-1 / (50 * double(N)));

At each step of the algorithm, I change the target temperature to be proportional to the average edge length of the path I currently have. This is because the edges I have as time passes are much shorter than the edges I have at first. I use the 2-opt swap to obtain neighbour paths and exp(difference/temp) for the acceptance probability.

S-Erase
  • 3
  • 1
  • It is really difficult to guess where the error is. But for sure, you can get good results by combining SA + 2opt. Can you explain your proposal function? Can you also debug info, the number of accepted states, for each batch of say 100 proposals? You can lower the temperature after 100 proposals, to get this debug into. – Willem Hendriks Aug 19 '20 at 08:26
  • What is the potential next-state, based on current state? There are various ways to create modifications on current. – Willem Hendriks Aug 19 '20 at 13:39
  • https://i.stack.imgur.com/QnkJZ.jpg – Willem Hendriks Aug 19 '20 at 13:39
  • @user3184950 I've been using the block-reverse mutation (2-opt swap) – S-Erase Aug 19 '20 at 16:14
  • That should work, and should be at least as good as normal 2-opt. You really need to print information about the process. The temperature lowering is uncommon. I would first go with a simple Tnew = Tcurrent * 0.8, and during each lowering do 100 or 1000 proposals. Print the number of proposals which are accepted, that would give you valuable information. During the beginning it should be >90%, at the end <10% – Willem Hendriks Aug 20 '20 at 09:23
  • Also, when the annealing is finished, to a final round of 2-opt. Compare that with regular 2-opt, directly on a (random) start solution. – Willem Hendriks Aug 20 '20 at 09:25

0 Answers0