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.