dignea  1.0.0
Diverse Instance Generator with Novelty Search and Evolutionary Algorithms
Heuristic.h
1 
2 
3 #ifndef DIGNEA_HEURISTIC_H
4 #define DIGNEA_HEURISTIC_H
5 
7 
8 #include <nlohmann/json.hpp>
9 
10 using json = nlohmann::json;
11 
18 template <class S>
19 class Heuristic : public AbstractEA<S> {
20  public:
21  Heuristic() = default;
22 
23  virtual ~Heuristic() = default;
24 
25  virtual void run() = 0;
26 
27  virtual string getName() const = 0;
28 
29  virtual string getID() const = 0;
30 
31  virtual json to_json() const;
32 
33  virtual Front<S> getResults() const = 0;
34 
35  protected:
40  virtual void initProgress(){};
41 
46  virtual void updateProgress(){};
47 
48  void finishProgress() override;
49 
55  bool isStoppingConditionReached() override { return false; };
56 
61  virtual void createInitialPopulation(){};
62 
67  virtual void evaluatePopulation(vector<S> &){};
68 
73  virtual void updateEvolution(vector<S> &){};
74 
79  virtual void updateEvolution(const int &checkpoint, vector<S> &){};
80 };
81 
87 template <class S>
89  std::chrono::duration<double> diff = this->endTime - this->startTime;
90  this->elapsedTime = diff.count();
91 }
98 template <class S>
99 json Heuristic<S>::to_json() const {
100  json data;
101  data["name"] = this->getName();
102  return data;
103 }
104 #endif // DIGNEA_HEURISTIC_H
nlohmann::json json
Definition: MinKnap.h:85
Class to define an Abstract Evolutionary Algorithm. This is the base skeleton for future extensions.
Definition: AbstractEA.h:42
Front class which stores the final results of an EA execution.
Definition: Front.h:26
Base heuristic class. This is the skeleton for future heuristic implementations. Extends AbstractEA f...
Definition: Heuristic.h:19
virtual json to_json() const
Returns the JSON representation of the Heuristic.
Definition: Heuristic.h:99
virtual void updateEvolution(const int &checkpoint, vector< S > &)
Not implemented. Nothing really to do here.
Definition: Heuristic.h:79
virtual void createInitialPopulation()
Not implemented. Nothing really to do here.
Definition: Heuristic.h:61
virtual void run()=0
Main method of the EA. Runs the algorithm but must be implemented in the subclasses.
virtual void initProgress()
Not implemented. Nothing really to do here.
Definition: Heuristic.h:40
virtual string getID() const =0
Returns the identificator of the algorithm, this is used in the to_json method. Must be implemented i...
void finishProgress() override
Finishes the progress of the Heuristic by computing the elapsed time.
Definition: Heuristic.h:88
virtual void updateEvolution(vector< S > &)
Not implemented. Nothing really to do here.
Definition: Heuristic.h:73
bool isStoppingConditionReached() override
Always returns false. TODO: Refactor to inherit from Algorithm.
Definition: Heuristic.h:55
virtual Front< S > getResults() const =0
Returns a Front object with all the solutions of the evolutionary process. This method must be implem...
virtual string getName() const =0
Returns the name of the algorithm, this is used in the to_json method. Must be implemented in the sub...
virtual void evaluatePopulation(vector< S > &)
Not implemented. Nothing really to do here.
Definition: Heuristic.h:67
virtual void updateProgress()
Not implemented. Nothing really to do here.
Definition: Heuristic.h:46