dignea  1.0.0
Diverse Instance Generator with Novelty Search and Evolutionary Algorithms
BPP.h
Go to the documentation of this file.
1 
12 #ifndef __DIGNEA_BPP_H__
13 #define __DIGNEA_BPP_H__
14 
15 #include <dignea/core/Problem.h>
16 #include <dignea/types/SolutionTypes.h>
17 #include <dignea/utilities/random/PseudoRandom.h>
18 
19 #include <fstream>
20 #include <iostream>
21 #include <utility>
22 
27 class BPP : public Problem<IntIntSolution> {
28  public:
29  BPP();
30 
31  virtual ~BPP() = default;
32 
33  BPP(const string &pathToInstance);
34 
35  BPP(const int &numberOfVars, const int &capacity, const vector<int> &items);
36 
37  BPP(const BPP *);
38 
39  float getUpperLimit(int i) const override;
40 
41  int getOptimizationDirection(const int i) const override;
42 
43  float getLowerLimit(int i) const override;
44 
45  string getName() const override { return "Bin-Packing Problem"; };
46 
47  void evaluate(IntIntSolution &solution) const override;
48 
49  bool evaluateConstraints(IntIntSolution &ptr) const override {
50  return true;
51  };
52 
53  IntIntSolution createSolution() const override;
54 
55  IntIntSolution createSolution(ParallelPRNG &engine) const override;
56 
57  int getCapacity() const { return capacity; };
58 
59  void setCapacity(int capacity);
60 
61  const vector<int> &getItems() const { return items; };
62 
63  void readData(const string &path) override;
64 
65  json to_json() const override;
66 
67  protected:
68  // Set of items to pack
69  vector<int> items;
70  // Maximum capacity of each bin
71  int capacity;
72  std::string pathToInstance;
73 };
74 
75 #endif // __DIGNEA_BPP_H__
Class to represent the Bin Packing Problem.
Definition: BPP.h:27
json to_json() const override
Definition: BPP.cpp:225
BPP()
Construct a new BPP::BPP object.
Definition: BPP.cpp:10
bool evaluateConstraints(IntIntSolution &ptr) const override
Method to evaluate whether a solution is feasible or not. This method must be implemented in the subc...
Definition: BPP.h:49
void setCapacity(int capacity)
Updates the capacity of the instance.
Definition: BPP.cpp:203
float getLowerLimit(int i) const override
Returns the lower limit of the variable i In this case, the lower limit is 0.
Definition: BPP.cpp:126
void evaluate(IntIntSolution &solution) const override
Evaluates a bin assignment for the BPP instances represented in the object The fitness of the solutio...
Definition: BPP.cpp:145
float getUpperLimit(int i) const override
Returns the upper limit of the variable i In this case, the upper limit is the number of items - 1.
Definition: BPP.cpp:111
int getOptimizationDirection(const int i) const override
Gets the optimization direction of the problem. For the BPP is should always be Minimize.
Definition: BPP.cpp:212
string getName() const override
Returns the name of the problem. This method must be implemented in the subclasses.
Definition: BPP.h:45
void readData(const string &path) override
Reads the data from the file in the path. The file should contain a proper BPP instance with the foll...
Definition: BPP.cpp:80
IntIntSolution createSolution() const override
Creates a random solution for the BPP Each items is assigned to a random bin in the range [0,...
Definition: BPP.cpp:178
Class to represent a Problem in the tool. It includes the basic information for a problem a few metho...
Definition: Problem.h:29
int numberOfVars
Definition: Problem.h:155
Class to represent a solution to the optimization problems in the tool.
Definition: Solution.h:25