dignea  1.0.0
Diverse Instance Generator with Novelty Search and Evolutionary Algorithms
KPDomain.h
Go to the documentation of this file.
1 
11 #ifndef DIGNEA_EKPPROBLEM_H
12 #define DIGNEA_EKPPROBLEM_H
13 
16 #include <dignea/problems/KPNR.h>
17 #include <dignea/types/SolutionTypes.h>
18 
27 class KPDomain : public AbstractDomain<KPNR, KPInstance> {
28  public:
29  KPDomain();
30 
31  explicit KPDomain(const int &numberOfVars, const int &numberOfObjs = 1);
32 
33  virtual ~KPDomain();
34 
35  KPDomain(const string &pathToInstance) = delete;
36 
37  KPDomain(const int &numberOfVars, const int &numberOfObjs,
38  const int &numOfInstances, const int &lowerWeight,
39  const int &upperWeight, const int &lowerProfit,
40  const int &upperProfit, bool reducedSpace = false);
41 
42  shared_ptr<KPNR> genOptProblem(const KPInstance &instance) const override;
43 
44  void evaluate(KPInstance &solution) const override;
45 
46  vector<KPInstance> createSolutions(const int &maxSolutions) const override;
47 
48  void beforeEvaluation(vector<KPInstance> &) override;
49 
50  void afterEvaluation(vector<KPInstance> &) override;
51 
52  KPInstance createSolution() const override;
53 
54  KPInstance createSolution(ParallelPRNG &engine) const override;
55 
57 
58  KPInstance createSolution(ParallelPRNG &engine);
59 
60  bool evaluateConstraints(KPInstance &solution) const override {
61  return true;
62  }
63 
64  int getOptimizationDirection(const int i) const override;
65 
66  string getName() const override { return "KPDomain"; }
67 
68  float getUpperLimit(const int i) const override;
69 
70  float getLowerLimit(const int i) const override;
71 
72  int getNumberOfInstances() const { return numberOfInstances; }
73 
74  void setNumberOfInstances(int numberOfInstances) {
75  KPDomain::numberOfInstances = numberOfInstances;
76  }
77 
78  int getLowWeight() const { return lowWeight; }
79 
80  void setLowWeight(int lowWeight) { KPDomain::lowWeight = lowWeight; }
81 
82  int getUpWeight() const { return upWeight; }
83 
84  void setUpWeight(int upWeight) { KPDomain::upWeight = upWeight; }
85 
86  int getLowProfit() const { return lowProfit; }
87 
88  void setLowProfit(int lowProfit) { KPDomain::lowProfit = lowProfit; }
89 
90  int getUpProfit() const { return upProfit; }
91 
92  void setUpProfit(int upProfit) { KPDomain::upProfit = upProfit; }
93 
94  int getGeneratedInstances() const { return generatedInstances; }
95 
96  void setGeneratedInstances(int generatedInstances) {
97  KPDomain::generatedInstances = generatedInstances;
98  }
99 
102  bool isReducedSpace() const { return reducedSpace; }
103 
104  json to_json() const override;
105 
106  private:
107  KPInstance createSolution(const int &instanceIndex,
108  const int &maxInstances) const;
109 
110  protected:
111  int numberOfInstances;
112  int lowWeight;
113  int upWeight;
114  int lowProfit;
115  int upProfit;
116  // This allows to call createSolution without args
117  int generatedInstances;
118 
119  bool reducedSpace; // <! Flag to consider searching in the PCA space !>
120 
121  public:
122  // Unimplemented Methods
123  void readData(const string &path) override{};
124 };
125 
126 #endif
EIG Instance Generation Problem. Abstract Problem for the EIG. This problem will be used as a supercl...
Definition: AbstractDomain.h:28
Instance Generator Knapsack Problem. Problem for the Instance Generator to generate Knapsack Problem ...
Definition: KPDomain.h:27
void evaluate(KPInstance &solution) const override
Definition: KPDomain.cpp:52
void beforeEvaluation(vector< KPInstance > &) override
Definition: KPDomain.cpp:201
void afterEvaluation(vector< KPInstance > &) override
Method applied after evaluation the population of solutions.
Definition: KPDomain.cpp:223
bool isReducedSpace() const
Check if the search is performed in a PCA space.
Definition: KPDomain.h:102
shared_ptr< KPNR > genOptProblem(const KPInstance &instance) const override
Definition: KPDomain.cpp:143
vector< KPInstance > createSolutions(const int &maxSolutions) const override
Definition: KPDomain.cpp:188
float getUpperLimit(const int i) const override
Definition: KPDomain.cpp:109
int getOptimizationDirection(const int i) const override
Definition: KPDomain.cpp:174
float getLowerLimit(const int i) const override
Definition: KPDomain.cpp:126
json to_json() const override
Creates a JSON object with the information of the Problem.
Definition: KPDomain.cpp:307
string getName() const override
Returns the name of the problem. This method must be implemented in the subclasses.
Definition: KPDomain.h:66
KPInstance createSolution() const override
Definition: KPDomain.cpp:82
Instance Knapsack Problem Solution. Class which represents the solution for the Instance Knapsack Pro...
Definition: KPInstance.h:27
int numberOfVars
Definition: Problem.h:155
int numberOfObjs
Definition: Problem.h:159