MinLCA algorithms
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
minlca::utils::SimulatedAnnealing< Node > Class Template Reference

Generic simulated annealing algorithm. More...

#include <simulated-annealing.hh>

Public Member Functions

 SimulatedAnnealing (int steps, int stIter, int k, double lambda, int seed=0)
 Constructor with seed. More...
 
 SimulatedAnnealing (int maxSteps, int stIter, int k, double lambda, Random &r)
 Constructor using pre-built random number generator. More...
 
 ~SimulatedAnnealing ()
 Default destructor. More...
 
void init (Node *start)
 Initialiser for the class. More...
 
virtual double temperature () const
 Returns the current temperature. More...
 
Node * run ()
 Run the algorithm. More...
 
Node * best ()
 Get the best node. More...
 

Protected Types

typedef lemon::Random Random
 

Protected Member Functions

void runStep ()
 Run a single step. More...
 

Protected Attributes

Node * _current
 Current node.
 
Node * _best
 
int _steps
 Total steps done.
 
int _max_steps
 Maximum number of steps.
 
int _stiter
 Steps per iteration.
 
int _k
 Coefficient for the temperature.
 
double _lambda
 Coefficient in the exponent of the temperature.
 
bool _delete_random
 Delete the random number generator in destructor.
 
Random * _r
 Pointer to random number generator.
 

Detailed Description

template<typename Node>
class minlca::utils::SimulatedAnnealing< Node >

Generic simulated annealing algorithm.

Definition at line 17 of file simulated-annealing.hh.

Constructor & Destructor Documentation

template<typename Node>
minlca::utils::SimulatedAnnealing< Node >::SimulatedAnnealing ( int  steps,
int  stIter,
int  k,
double  lambda,
int  seed = 0 
)
inline

Constructor with seed.

Constructor for the class requesting an initial seed for the random number generator.

Parameters
[in]stepsMaximum number of steps
[in]stIterNumber of steps per iteration group
[in]kCoefficient for temperature function
[in]lambdaFactor in the exponent of the temperature
[in]seedSeed for the random number generator

Definition at line 89 of file simulated-annealing.hh.

template<typename Node>
minlca::utils::SimulatedAnnealing< Node >::SimulatedAnnealing ( int  maxSteps,
int  stIter,
int  k,
double  lambda,
Random &  r 
)
inline

Constructor using pre-built random number generator.

Constructor for the class requiring an existing random number generator.

Parameters
[in]maxStepsMaximum number of steps
[in]stIterNumber of steps per iteration group
[in]kCoefficient for temperature function
[in]lambdaFactor in the exponent of the temperature
[in]rAlready initialised random number generator

Definition at line 106 of file simulated-annealing.hh.

template<typename Node>
minlca::utils::SimulatedAnnealing< Node >::~SimulatedAnnealing ( )
inline

Default destructor.

This destructor takes care of deleting the random number generator if it was not given by the user.

Warning
The destructor does not delete the returned search node from run(), you need to delete it on your own.
See also
run()

Definition at line 127 of file simulated-annealing.hh.

Member Function Documentation

template<typename Node>
Node* minlca::utils::SimulatedAnnealing< Node >::best ( )
inline

Get the best node.

Returns the best node found, the same obtained after executing run().

See also
run()

Definition at line 203 of file simulated-annealing.hh.

template<typename Node>
void minlca::utils::SimulatedAnnealing< Node >::init ( Node *  start)
inline

Initialiser for the class.

Resets the status of the search and sets the initial node to start.

Warning
This function does not remove the returned node from run(), you need to delete it for yourself.
See also
run()
Parameters
startInitial node for the search

Definition at line 146 of file simulated-annealing.hh.

template<typename Node>
Node* minlca::utils::SimulatedAnnealing< Node >::run ( )
inline

Run the algorithm.

Runs the whole search. Needs to have the initial search node set by using function SimulatedAnnealing::init(Node*).

Warning
Make sure to delete the contents of the returned pointer when it is not needed anymore. Neither the destructor nor init(Node*) take care of this.
See also
init(Node*)
~SimulatedAnnealing()

Definition at line 178 of file simulated-annealing.hh.

template<typename Node>
void minlca::utils::SimulatedAnnealing< Node >::runStep ( )
inlineprotected

Run a single step.

This function runs a single simulated annealing step. If SA_VERBOSE is defined during compilation, this function writes to standard output the information about the current step.

Definition at line 36 of file simulated-annealing.hh.

template<typename Node>
virtual double minlca::utils::SimulatedAnnealing< Node >::temperature ( ) const
inlinevirtual

Returns the current temperature.

Returns the current temperature using the formula

\[ k\,\exp\left( -\lambda\,\left\lfloor\frac{steps}{stiter}\right\rfloor\,stiter \right) \]

Definition at line 162 of file simulated-annealing.hh.


The documentation for this class was generated from the following file: