Simulated annealing
SimulatedAnnealing
can minimize a function using the simulated annealing algorithm. Ths solution is
progressively improved by performing small changes to it.
The user must define a solution struct representing a solution to the problem. The struct must define the following methods:
Solution struct
struct Solution {
Solution() {
// ...
}
Solution randomNeighbor() const {
// ...
}
double score() const {
// ...
}
};
Then, the user can create a SimulatedAnnealing
object and call the SimulatedAnnealing::minimize()
method to minimize the function.
Finding a good solution
Solution sol;
SimulatedAnnealing<Solution> sa(1);
sa.minimize(sol, 100000);
cout << sa.m_bestScore << endl;>>