Djinni
2.2
|
A generic Annealer capable of working with a variety of different problem types and penalty generators. More...
#include <Annealer.h>
Public Types | |
typedef PenaltyFunc::ReturnType | PenaltyType |
typedef unsigned long | u_int32_t |
Public Member Functions | |
Annealer (PenaltyFunc &pfunc, SolutionType &sol, double multT, double accept, u_int32_t tBI, u_int32_t minIter, u_int32_t maxIter) | |
Annealer (SolutionType &solution, double multT, double accept, u_int32_t tBI, u_int32_t minIter, u_int32_t maxIter) | |
Annealer (PenaltyFunc &pfunc, SolutionType &sol) | |
virtual | ~Annealer () |
PenaltyFunc & | getPenaltyFunc () |
const SolutionType & | best () const |
const SolutionType & | current () const |
void | solve () |
std::string | solution () const |
void | setParameters (double multT, double accept, u_int32_t tBI, u_int32_t minIterations, u_int32_t maxIterations) |
void | setSolutionParameters (const char *foo) |
std::ostream & | dump (std::ostream &os) const |
double | cost () const |
double | penalty () const |
u_int32_t | bestIter () const |
u_int32_t | iterations () const |
u_int32_t | maxIterations () const |
u_int32_t | minIterations () const |
double | multiplier () const |
double | probability () const |
PenaltyType | getLambda () const |
Protected Member Functions | |
void | initializeParam () |
void | tuneTemperature () |
void | testNeigh () |
void | updateParam () |
Protected Attributes | |
SHARED_PTR< SolutionType > | _best |
SHARED_PTR< SolutionType > | _current |
SHARED_PTR< SolutionType > | _neighbor |
u_int32_t | _bestIter |
u_int32_t | _iterations |
u_int32_t | _maxIterations |
u_int32_t | _minIterations |
u_int32_t | _terminalBestIter |
double | _multiplierT |
double | _acceptProb |
double | _currentT |
PenaltyFunc | _pfunc |
PenaltyType | _lambda |
Static Protected Attributes | |
static const int | _sampleSize = 10000 |
A generic Annealer capable of working with a variety of different problem types and penalty generators.
There is no deep magic hidden in this class. You may wish to check the specialization for PenaltyFunc = Compressed, which follows this class declaration.
Definition at line 30 of file Annealer.h.
typedef PenaltyFunc::ReturnType Annealer< PenaltyFunc, SolutionType >::PenaltyType |
A convenience typedef for accessing the ReturnType of a given PenaltyType.
Definition at line 34 of file Annealer.h.
typedef unsigned long Annealer< PenaltyFunc, SolutionType >::u_int32_t |
A typedef representing a 32-bit unsigned integer. This should probably be replaced with a uint_32t at some point, in the interests of portability.
Definition at line 38 of file Annealer.h.
Annealer< PenaltyFunc, SolutionType >::Annealer | ( | PenaltyFunc & | pfunc, |
SolutionType & | sol, | ||
double | multT, | ||
double | accept, | ||
u_int32_t | tBI, | ||
u_int32_t | minIter, | ||
u_int32_t | maxIter | ||
) | [inline] |
An Annealer constructor which takes all necessary parameters in one fell swoop.
pfunc | The penalty function to be applied to this annealer |
sol | A solution, populated randomly, to be applied to this annealer |
multT | A value in the range 0.0 - 0.9999 representing the temperature multiplier |
accept | A value in the range 0.0 - 0.9999 representing our willingness to accept an inferior solution |
tBI | The terminal best iteration |
minIter | The minimum number of annealing iterations to apply |
maxIter | The maximum number of annealing iterations to apply |
Definition at line 52 of file Annealer.h.
References Annealer< PenaltyFunc, SolutionType >::setParameters().
Annealer< PenaltyFunc, SolutionType >::Annealer | ( | SolutionType & | solution, |
double | multT, | ||
double | accept, | ||
u_int32_t | tBI, | ||
u_int32_t | minIter, | ||
u_int32_t | maxIter | ||
) | [inline] |
An Annealer constructor appropriate for use with PenaltyFuncs which have a default constructor.
solution | A solution, populated randomly, to be applied to this annealer |
multT | A value in the range 0.0 - 0.9999 representing the temperature multiplier |
accept | A value in the range 0.0 - 0.9999 representing our willingness to accept an inferior solution |
tBI | The terminal best iteration |
minIter | The minimum number of annealing iterations to apply |
maxIter | The maximum number of annealing iterations to apply |
Definition at line 71 of file Annealer.h.
References Annealer< PenaltyFunc, SolutionType >::setParameters().
Annealer< PenaltyFunc, SolutionType >::Annealer | ( | PenaltyFunc & | pfunc, |
SolutionType & | sol | ||
) | [inline] |
An Annealer constructor for use when the parameters will be set after initialization.
pfunc | The penalty function to be applied to this annealer |
sol | A solution, populated randomly, to be applied to this annealer |
Definition at line 84 of file Annealer.h.
virtual Annealer< PenaltyFunc, SolutionType >::~Annealer | ( | ) | [inline, virtual] |
A no-op destructor.
This destructor is virtualized to allow end users to subclass off this template. Whether an end user should subclass off this template is a different question.
Definition at line 94 of file Annealer.h.
const SolutionType& Annealer< PenaltyFunc, SolutionType >::best | ( | ) | const [inline] |
Returns the best solution found by the annealer.
Definition at line 100 of file Annealer.h.
u_int32_t Annealer< PenaltyFunc, SolutionType >::bestIter | ( | ) | const [inline] |
Returns the number of the iteration on which the best solution was encountered.
Definition at line 214 of file Annealer.h.
double Annealer< PenaltyFunc, SolutionType >::cost | ( | ) | const [inline] |
Returns the cost of the best solution found by the annealer.
Definition at line 205 of file Annealer.h.
const SolutionType& Annealer< PenaltyFunc, SolutionType >::current | ( | ) | const [inline] |
Returns the current solution in use by the annealer.
It is unlikely this method will be of use to end users. Once you hit the solve() method, you're on an uninterruptible trip to the end. However, in the event you want to subclass and do funky things, you have an accessor.
Definition at line 108 of file Annealer.h.
std::ostream& Annealer< PenaltyFunc, SolutionType >::dump | ( | std::ostream & | os | ) | const [inline] |
Allows for an Annealer object's internal state to be dumped in human-readable format to an output stream.
Please note that this is not meant to be called directly. Rather, an operator<< will be set up as a proxy to invoke this method.
os | The output stream to dump it to |
Definition at line 186 of file Annealer.h.
PenaltyType Annealer< PenaltyFunc, SolutionType >::getLambda | ( | ) | const [inline] |
PenaltyFunc& Annealer< PenaltyFunc, SolutionType >::getPenaltyFunc | ( | ) | [inline] |
Returns this Annealer's PenaltyFunc
Definition at line 97 of file Annealer.h.
void Annealer< PenaltyFunc, SolutionType >::initializeParam | ( | ) | [inline, protected] |
Performs housekeeping to make sure our parameters are properly set before entering annealing runs.
Definition at line 246 of file Annealer.h.
Referenced by Annealer< PenaltyFunc, SolutionType >::solve(), and Annealer< Compressed, SolutionType >::solve().
u_int32_t Annealer< PenaltyFunc, SolutionType >::iterations | ( | ) | const [inline] |
Returns the current iteration number.
Definition at line 219 of file Annealer.h.
Referenced by Annealer< Compressed, SolutionType >::tuneTemperature().
u_int32_t Annealer< PenaltyFunc, SolutionType >::maxIterations | ( | ) | const [inline] |
Returns the maximum number of annealer iterations to run.
Definition at line 224 of file Annealer.h.
Referenced by Annealer< PenaltyFunc, SolutionType >::setParameters(), and Annealer< Compressed, SolutionType >::setParameters().
u_int32_t Annealer< PenaltyFunc, SolutionType >::minIterations | ( | ) | const [inline] |
Returns the minimum number of annealer iterations to run.
Definition at line 229 of file Annealer.h.
Referenced by Annealer< PenaltyFunc, SolutionType >::setParameters(), and Annealer< Compressed, SolutionType >::setParameters().
double Annealer< PenaltyFunc, SolutionType >::multiplier | ( | ) | const [inline] |
Returns the temperature multiplier.
Definition at line 233 of file Annealer.h.
double Annealer< PenaltyFunc, SolutionType >::penalty | ( | ) | const [inline] |
Returns the penalty incurred by the best solution found by the annealer.
Definition at line 210 of file Annealer.h.
double Annealer< PenaltyFunc, SolutionType >::probability | ( | ) | const [inline] |
Returns the probability of accepting an inferior move.
Definition at line 238 of file Annealer.h.
void Annealer< PenaltyFunc, SolutionType >::setParameters | ( | double | multT, |
double | accept, | ||
u_int32_t | tBI, | ||
u_int32_t | minIterations, | ||
u_int32_t | maxIterations | ||
) | [inline] |
Sets the parameters of the annealer.
multT | A value in the range 0.0 - 0.9999 representing the temperature multiplier |
accept | A value in the range 0.0 - 0.9999 representing our willingness to accept an inferior solution |
tBI | The terminal best iteration |
minIterations | The minimum number of annealing iterations to apply |
maxIterations | The maximum number of annealing iterations to apply |
Definition at line 160 of file Annealer.h.
References Annealer< PenaltyFunc, SolutionType >::maxIterations(), and Annealer< PenaltyFunc, SolutionType >::minIterations().
Referenced by Annealer< PenaltyFunc, SolutionType >::Annealer(), and Annealer< Compressed, SolutionType >::Annealer().
void Annealer< PenaltyFunc, SolutionType >::setSolutionParameters | ( | const char * | foo | ) | [inline] |
Sets the parameters of this annealer's SolutionType by calling that class' constructor.
foo | A char* containing the solution parameters |
Definition at line 173 of file Annealer.h.
std::string Annealer< PenaltyFunc, SolutionType >::solution | ( | ) | const [inline] |
Return a std::string representation of the best solution found by the annealer.
Definition at line 145 of file Annealer.h.
void Annealer< PenaltyFunc, SolutionType >::solve | ( | ) | [inline] |
For a completely-constructed annealer, initiate the solution process and do not return until termination.
Definition at line 111 of file Annealer.h.
References Annealer< PenaltyFunc, SolutionType >::initializeParam(), Annealer< PenaltyFunc, SolutionType >::testNeigh(), Annealer< PenaltyFunc, SolutionType >::tuneTemperature(), and Annealer< PenaltyFunc, SolutionType >::updateParam().
void Annealer< PenaltyFunc, SolutionType >::testNeigh | ( | ) | [inline, protected] |
Tests a neighbor for superiority or inferiority, and may update our _current solution based on the result.
Definition at line 302 of file Annealer.h.
References Twister::generateDouble().
Referenced by Annealer< PenaltyFunc, SolutionType >::solve(), and Annealer< Compressed, SolutionType >::solve().
void Annealer< PenaltyFunc, SolutionType >::tuneTemperature | ( | ) | [inline, protected] |
Runs some initial annealing iterations in order to set the temperature to the proper initial value.
Definition at line 264 of file Annealer.h.
References Twister::generateDouble().
Referenced by Annealer< PenaltyFunc, SolutionType >::solve(), and Annealer< Compressed, SolutionType >::solve().
void Annealer< PenaltyFunc, SolutionType >::updateParam | ( | ) | [inline, protected] |
Updates the temperature and lambda each iteration.
Definition at line 318 of file Annealer.h.
Referenced by Annealer< PenaltyFunc, SolutionType >::solve(), and Annealer< Compressed, SolutionType >::solve().