I am interested in implementing simulated annealing and am having difficulty with my implementation. All the costs are computed and stored in the dist array. From my understanding, simulated annealing works as follows:
- Generate a random solution
- Calculate its cost using some cost function
- Generate a random neighboring solution
- Calculate the new solution's cost
- Compare them:
5.1: If cnew < cold: move to the new solution
5.2: If cnew > cold: maybe move to the new solution- Repeat steps 3-5 above until an acceptable solution is found or you reach some maximum number of iteration
Code:double max = dist[1]; int idx=0; for(int ix = 1; ix < ITERS; ix++){ double temp = (1/500)*((1/ix)- (1/ITERS)); for(int m = 0; m < 100; m++){ if (dist[m] < max) { max = dist[m]; idx = m; } else if (dist[m] > max) { if (((max - dist[m])/temp) > unifRand()) { max = dist[m]; idx = m; } } } } return idx;