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;>>
template<typename S>
class SimulatedAnnealing

Public Functions

inline SimulatedAnnealing(const double startTemperature)
inline void minimize(const S startState, const int nbIterations)

Public Members

double m_startTemperature
S m_state
S m_bestState
double m_score
double m_bestScore