1 #ifndef HILL_CLIMBING_HPP 2 #define HILL_CLIMBING_HPP 4 #if defined(_MSC_VER) && (_MSC_VER >= 1400) 6 #pragma warning(disable:4510) 7 #pragma warning(disable:4610) 10 #include <boost/concept_check.hpp> 21 typedef typename Space::Individual Individual;
22 typedef typename Individual::PNode PNode;
31 typedef typename Space::Fitness Fitness;
32 Fitness best_fitness = Space::fitness(*initial);
36 typedef typename Individual::Children Children;
37 Children ch = initial->getChildren();
38 for(
typename Children::const_iterator it = ch.begin(); it != ch.end(); ++it ) {
39 const PNode neighbour = *it;
40 Fitness neighbour_fitness = Space::fitness(*neighbour);
41 if (best_fitness < neighbour_fitness) {
42 best_neighbour = neighbour;
43 best_fitness = neighbour_fitness;
46 return best_neighbour;
52 template<
typename Space,
56 typedef typename Space::Individual Individual;
57 typedef typename Individual::PNode PNode;
58 typedef typename Space::Fitness Fitness;
63 PNode
solve(
const PNode& initial) {
69 typename Individual::PNode current = initial;
70 typename Individual::PNode best_neighbour = current;
72 current = best_neighbour;
73 best_neighbour = NextNodeStrategy<Space>::nextNode(current);
75 while( best_neighbour != 0L );
84 #endif // HILL_CLIMBING_HPP
the concept for node with children
Definition: Node.hpp:44
PNode solve(const PNode &initial)
the hill climbing algorithm - until stop repeat searching all adjacent nodes.
Definition: HillClimbing.hpp:63
the hill climbing algorithm. Search the neighbour for the better solution
Definition: HillClimbing.hpp:54
static PNode nextNode(const PNode &initial)
next node as the better neighbour
Definition: HillClimbing.hpp:25
the typedef-s for space, where the fitness is defined as double
Definition: Space.hpp:25
the concept for space with fitness
Definition: Space.hpp:33
the policy class for HillClimbing, check all neighbours
Definition: HillClimbing.hpp:19