EasyLocalpp  3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
moverunnerobserver.hh
Go to the documentation of this file.
1 #if !defined(_MOVE_RUNNER_OBSERVER_HH_)
2 #define _MOVE_RUNNER_OBSERVER_HH_
3 
5 #include <chrono>
6 #include <iostream>
7 
8 namespace EasyLocal {
9  namespace Debug {
10 
11  template <class Input, class State, class Move, typename CFtype = int>
13  {
14  protected:
16  public:
17  LocalSearchObserver(std::ostream& os = std::cout);
18  void operator()(Event event, CostStructure<CFtype> current_state_cost, const EvaluatedMove<Move, CFtype>& em, const std::string& status_string) const;
19  unsigned int events() const
20  {
21  return Event::START | Event::NEW_BEST;
22  }
23  mutable std::chrono::high_resolution_clock::time_point start;
24  std::ostream& os;
25  };
26 
27  template <class Input, class State, class Move, typename CFtype>
29  {}
30 
31  template <class Input, class State, class Move, typename CFtype>
32  void LocalSearchObserver<Input, State, Move, CFtype>::operator()(Event event, CostStructure<CFtype> current_state_cost, const EvaluatedMove<Move, CFtype>& em, const std::string& status_string) const
33  {
34  switch (event)
35  {
36  case Event::START:
37  start = std::chrono::high_resolution_clock::now();
38  break;
39  case Event::NEW_BEST:
40  os << "--New Best " << current_state_cost << " [" << em.cost.total << "] (" << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start).count() / 1000.0 << "s)" << " " << status_string << std::endl;
41  start = std::chrono::high_resolution_clock::now();
42  break;
43  default:
44  break;
45  }
46  }
47  }
48 }
49 
50 
51 #endif
void operator()(Event event, CostStructure< CFtype > current_state_cost, const EvaluatedMove< Move, CFtype > &em, const std::string &status_string) const
LocalSearchObserver(std::ostream &os=std::cout)
std::chrono::high_resolution_clock::time_point start
EasyLocal::Core::LocalSearch< Input, State, Move, CFtype >::Event Event