void Simulated_Annealing::cooling() { //Setting up initial temperature. T = current_best_solution.first.size() * 10000; do { for (int i = 0; i < cooling_schedule; i++) { //Getting new solution in the neighborhood. candidate = newSolution(current_best_solution); //If the new solution is better than our current best solution, this new solution becomes our current best solution. //Otherwise, we eval new solution using metropolis step. If metropolis step returns true, the new solution becomes //the current best solution. if (current_best_solution.second >= candidate.second) { current_best_solution = candidate; } else if(metropolisStep(current_best_solution.second, candidate.second)){ current_best_solution = candidate; } //If our current best solution is better than the historical better solution, it becomes the new historical best solution. if (current_best_solution.second <= historical_best_solution.second) historical_best_solution = current_best_solution; } //Cooling temperature. T *= 0.90; } while (T > 0.1); }
/******************************************* sweep ******************************************/ void Simulation::sweep() { /*int i; int N1 = N/2; //number of Metropolis steps before Wolff step int N2 = N - N1; //number of Metropolis steps after Wolff step for( i=0; i<N1; i++ ) { metropolisStep(); } if( lambda==1 ) { wolffStep(); } for( i=0; i<N2; i++ ) { metropolisStep(); }*/ for( int i=0; i<N; i++ ) { metropolisStep(); } }