EasyLocalpp  3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
firstimprovement.hh
Go to the documentation of this file.
1 #if !defined(_FIRST_DESCENT_HH_)
2 #define _FIRST_DESCENT_HH_
3 
7 
8 namespace EasyLocal {
9 
10  namespace Core {
11 
17  template <class Input, class State, class Move, typename CFtype = int>
18  class FirstImprovement : public LocalSearch<Input, State, Move, CFtype>
19  {
20  public:
21  FirstImprovement(const Input& in,
24  std::string name);
25  protected:
26  bool StopCriterion();
27  void SelectMove();
28  };
29 
30  /*************************************************************************
31  * Implementation
32  *************************************************************************/
33 
42  template <class Input, class State, class Move, typename CFtype>
45  std::string name)
46  : LocalSearch<Input, State, Move, CFtype>(in, e_sm, e_ne, name, "First Improvement Engine")
47  {}
48 
52  template <class Input, class State, class Move, typename CFtype>
54  {
55  size_t explored;
56  EvaluatedMove<Move, CFtype> em = this->ne.SelectFirst(*this->p_current_state, explored, [](const Move& mv, CostStructure<CFtype> move_cost) {
57  return move_cost < 0;
58  }, this->weights);
59  this->current_move = em;
60  this->evaluations += explored;
61  }
62 
66  template <class Input, class State, class Move, typename CFtype>
68  {
69  return this->iteration > 0 && !this->current_move.is_valid;
70  }
71  }
72 }
73 
74 #endif // _FIRST_DESCENT_HH_
FirstImprovement(const Input &in, StateManager< Input, State, CFtype > &e_sm, NeighborhoodExplorer< Input, State, Move, CFtype > &e_ne, std::string name)
This component is responsible for all operations on the state which are independent of the neighborho...