20 #include <boost/shared_ptr.hpp> 27 using boost::filesystem::path;
29 template <
class InstanceType>
40 InstanceType
optimize(InstanceType startInstance)
44 InstanceType selectedInstance = startInstance;
45 InstanceType bestInstance = startInstance;
47 unsigned visitedInstanceCounter = 0;
48 double lowestCost = this->
mCostFunction->calculateCost(bestInstance);
52 double oldCost = this->
mCostFunction->calculateCost(selectedInstance);
57 bool foundAcceptable =
false;
61 double nextInstanceCost = this->
mCostFunction->calculateCost(nextInstance);
65 foundAcceptable =
true;
66 selectedInstance = nextInstance;
68 if (nextInstanceCost < lowestCost)
70 bestInstance = nextInstance;
71 lowestCost = nextInstanceCost;
75 if (++visitedInstanceCounter %
mCoolingSchedule->getRepetitionsBeforeUpdate() == 0)
85 return selectedInstance;
97 template<
class InstanceType>
boost::shared_ptr< CostFunction< InstanceType >> CostFunctionPtr
boost::shared_ptr< SimulatedAnnealingAlgorithm< InstanceType >> SimulatedAnnealingAlgorithmPtr
CostFunctionPtr< InstanceType > mCostFunction
NeighbourhoodFunctionPtr< InstanceType > mNeighbourhoodFunction
boost::shared_ptr< CoolingSchedule > CoolingSchedulePtr
SimulatedAnnealingAlgorithm(NeighbourhoodFunctionPtr< InstanceType > neighbourhoodFunction, CostFunctionPtr< InstanceType > costFunction, CoolingSchedulePtr coolingSchedule)
boost::shared_ptr< NeighbourhoodFunction< InstanceType >> NeighbourhoodFunctionPtr
InstanceType optimize(InstanceType startInstance)
this namespace contains all generally usable classes.
CoolingSchedulePtr mCoolingSchedule