20 #include <boost/shared_ptr.hpp> 27 template <
class InstanceType>
37 InstanceType
optimize(InstanceType startInstance)
39 InstanceType selectedInstance = startInstance;
41 double lowestCost = this->
mCostFunction->calculateCost(selectedInstance);
42 bool keepOptimizing =
true;
44 while (keepOptimizing)
46 keepOptimizing =
false;
56 lowestCost = this->
mCostFunction->calculateCost(selectedInstance);
57 keepOptimizing =
true;
64 double nextInstanceCost = this->
mCostFunction->calculateCost(nextInstance);
66 if (nextInstanceCost < lowestCost)
68 selectedInstance = nextInstance;
69 lowestCost = nextInstanceCost;
70 keepOptimizing =
true;
78 return selectedInstance;
83 return selectedInstance;
89 std::uniform_real_distribution<double>
mDistribution = std::uniform_real_distribution<double>(0.0, 1.0);
92 template<
class InstanceType>
InstanceType optimize(InstanceType startInstance)
boost::shared_ptr< CostFunction< InstanceType >> CostFunctionPtr
CostFunctionPtr< InstanceType > mCostFunction
NeighbourhoodFunctionPtr< InstanceType > mNeighbourhoodFunction
std::default_random_engine mGenerator
std::uniform_real_distribution< double > mDistribution
HillClimbingAlogrithm(NeighbourhoodFunctionPtr< InstanceType > neighbourhoodFunction, CostFunctionPtr< InstanceType > costFunction, bool randomWalkProbability=0.0)
bool mRandomWalkProbability
boost::shared_ptr< NeighbourhoodFunction< InstanceType >> NeighbourhoodFunctionPtr
this namespace contains all generally usable classes.
boost::shared_ptr< HillClimbingAlogrithm< InstanceType >> HillClimbingAlogrithmPtr