Djinni  2.2
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
Annealer< PenaltyFunc, SolutionType > Class Template Reference

A generic Annealer capable of working with a variety of different problem types and penalty generators. More...

#include <Annealer.h>

List of all members.

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

Detailed Description

template<class PenaltyFunc, class SolutionType>
class Annealer< PenaltyFunc, SolutionType >

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.

Author:
Hansen, Thiede
Since:
2.1

Definition at line 30 of file Annealer.h.


Member Typedef Documentation

template<class PenaltyFunc, class SolutionType>
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.

template<class PenaltyFunc, class SolutionType>
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.


Constructor & Destructor Documentation

template<class PenaltyFunc, class SolutionType>
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.

Parameters:
pfuncThe penalty function to be applied to this annealer
solA solution, populated randomly, to be applied to this annealer
multTA value in the range 0.0 - 0.9999 representing the temperature multiplier
acceptA value in the range 0.0 - 0.9999 representing our willingness to accept an inferior solution
tBIThe terminal best iteration
minIterThe minimum number of annealing iterations to apply
maxIterThe maximum number of annealing iterations to apply

Definition at line 52 of file Annealer.h.

References Annealer< PenaltyFunc, SolutionType >::setParameters().

template<class PenaltyFunc, class SolutionType>
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.

Parameters:
solutionA solution, populated randomly, to be applied to this annealer
multTA value in the range 0.0 - 0.9999 representing the temperature multiplier
acceptA value in the range 0.0 - 0.9999 representing our willingness to accept an inferior solution
tBIThe terminal best iteration
minIterThe minimum number of annealing iterations to apply
maxIterThe maximum number of annealing iterations to apply

Definition at line 71 of file Annealer.h.

References Annealer< PenaltyFunc, SolutionType >::setParameters().

template<class PenaltyFunc, class SolutionType>
Annealer< PenaltyFunc, SolutionType >::Annealer ( PenaltyFunc &  pfunc,
SolutionType &  sol 
) [inline]

An Annealer constructor for use when the parameters will be set after initialization.

Parameters:
pfuncThe penalty function to be applied to this annealer
solA solution, populated randomly, to be applied to this annealer

Definition at line 84 of file Annealer.h.

template<class PenaltyFunc, class SolutionType>
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.


Member Function Documentation

template<class PenaltyFunc, class SolutionType>
const SolutionType& Annealer< PenaltyFunc, SolutionType >::best ( ) const [inline]

Returns the best solution found by the annealer.

Definition at line 100 of file Annealer.h.

template<class PenaltyFunc, class SolutionType>
u_int32_t Annealer< PenaltyFunc, SolutionType >::bestIter ( ) const [inline]

Returns the number of the iteration on which the best solution was encountered.

Returns:
The number of the iteration on which the best solution was encountered.

Definition at line 214 of file Annealer.h.

template<class PenaltyFunc, class SolutionType>
double Annealer< PenaltyFunc, SolutionType >::cost ( ) const [inline]

Returns the cost of the best solution found by the annealer.

Returns:
The cost of the best solution found by the annealer.

Definition at line 205 of file Annealer.h.

template<class PenaltyFunc, class SolutionType>
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.

template<class PenaltyFunc, class SolutionType>
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.

Parameters:
osThe output stream to dump it to
Returns:
The output stream os after the operation completes

Definition at line 186 of file Annealer.h.

template<class PenaltyFunc, class SolutionType>
PenaltyType Annealer< PenaltyFunc, SolutionType >::getLambda ( ) const [inline]

Returns the current lambda.

Returns:
The current lambda.

Definition at line 242 of file Annealer.h.

template<class PenaltyFunc, class SolutionType>
PenaltyFunc& Annealer< PenaltyFunc, SolutionType >::getPenaltyFunc ( ) [inline]

Returns this Annealer's PenaltyFunc

Definition at line 97 of file Annealer.h.

template<class PenaltyFunc, class SolutionType>
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().

template<class PenaltyFunc, class SolutionType>
u_int32_t Annealer< PenaltyFunc, SolutionType >::iterations ( ) const [inline]

Returns the current iteration number.

Returns:
The current iteration number.

Definition at line 219 of file Annealer.h.

Referenced by Annealer< Compressed, SolutionType >::tuneTemperature().

template<class PenaltyFunc, class SolutionType>
u_int32_t Annealer< PenaltyFunc, SolutionType >::maxIterations ( ) const [inline]

Returns the maximum number of annealer iterations to run.

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().

template<class PenaltyFunc, class SolutionType>
u_int32_t Annealer< PenaltyFunc, SolutionType >::minIterations ( ) const [inline]

Returns the minimum number of annealer iterations to run.

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().

template<class PenaltyFunc, class SolutionType>
double Annealer< PenaltyFunc, SolutionType >::multiplier ( ) const [inline]

Returns the temperature multiplier.

Returns:
The temperature multiplier.

Definition at line 233 of file Annealer.h.

template<class PenaltyFunc, class SolutionType>
double Annealer< PenaltyFunc, SolutionType >::penalty ( ) const [inline]

Returns the penalty incurred by the best solution found by the annealer.

Returns:
The penalty incurred by the best solution found by the annealer.

Definition at line 210 of file Annealer.h.

template<class PenaltyFunc, class SolutionType>
double Annealer< PenaltyFunc, SolutionType >::probability ( ) const [inline]

Returns the probability of accepting an inferior move.

Returns:
The probability of accepting an inferior move.

Definition at line 238 of file Annealer.h.

template<class PenaltyFunc, class SolutionType>
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.

Parameters:
multTA value in the range 0.0 - 0.9999 representing the temperature multiplier
acceptA value in the range 0.0 - 0.9999 representing our willingness to accept an inferior solution
tBIThe terminal best iteration
minIterationsThe minimum number of annealing iterations to apply
maxIterationsThe 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().

template<class PenaltyFunc, class SolutionType>
void Annealer< PenaltyFunc, SolutionType >::setSolutionParameters ( const char *  foo) [inline]

Sets the parameters of this annealer's SolutionType by calling that class' constructor.

Parameters:
fooA char* containing the solution parameters

Definition at line 173 of file Annealer.h.

template<class PenaltyFunc, class SolutionType>
std::string Annealer< PenaltyFunc, SolutionType >::solution ( ) const [inline]

Return a std::string representation of the best solution found by the annealer.

Returns:
A std::string representation of the best solution found by the annealer.

Definition at line 145 of file Annealer.h.

template<class PenaltyFunc, class SolutionType>
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().

template<class PenaltyFunc, class SolutionType>
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().

template<class PenaltyFunc, class SolutionType>
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().

template<class PenaltyFunc, class SolutionType>
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().


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