dignea  1.0.0
Diverse Instance Generator with Novelty Search and Evolutionary Algorithms
BPP Class Reference

Class to represent the Bin Packing Problem. More...

#include <BPP.h>

Inheritance diagram for BPP:
Problem< IntIntSolution >

Public Member Functions

 BPP ()
 Construct a new BPP::BPP object.
 
 BPP (const string &pathToInstance)
 Construct a new BPP::BPP object from the data in the file in the path. More...
 
 BPP (const int &numberOfVars, const int &capacity, const vector< int > &items)
 
 BPP (const BPP *)
 Construct a new BPP::BPP object from another BPP object. More...
 
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. More...
 
int getOptimizationDirection (const int i) const override
 Gets the optimization direction of the problem. For the BPP is should always be Minimize. More...
 
float getLowerLimit (int i) const override
 Returns the lower limit of the variable i In this case, the lower limit is 0. More...
 
string getName () const override
 Returns the name of the problem. This method must be implemented in the subclasses. More...
 
void evaluate (IntIntSolution &solution) const override
 Evaluates a bin assignment for the BPP instances represented in the object The fitness of the solution is the amount of unused space, as well as the number of bins for a specific solution. Falkenauer (1998) performance metric defined as: More...
 
bool evaluateConstraints (IntIntSolution &ptr) const override
 Method to evaluate whether a solution is feasible or not. This method must be implemented in the subclasses. More...
 
IntIntSolution createSolution () const override
 Creates a random solution for the BPP Each items is assigned to a random bin in the range [0, numberOfVars) More...
 
IntIntSolution createSolution (ParallelPRNG &engine) const override
 Creates a random solution for the BPP Each items is assigned to a random bin in the range [0, numberOfVars) More...
 
int getCapacity () const
 
void setCapacity (int capacity)
 Updates the capacity of the instance. More...
 
const vector< int > & getItems () const
 
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 following format: nItems Q w0 w1 ... wn-1. More...
 
json to_json () const override
 
- Public Member Functions inherited from Problem< IntIntSolution >
 Problem ()
 Creates a new Problem with all parameters to zero. More...
 
 Problem (const int &numberOfVars, const int &numberOfObjectives, const int &nCons)
 Construct a new Problem with all the given parameters. More...
 
 Problem (const Problem *copy)
 
virtual void readData (const std::string &path)=0
 Method to read problem information from the given path. This method must be implemented in the subclasses. More...
 
int getNumberOfVars () const
 Get the number of variables (dimension) of the problem. More...
 
void setNumberOfVars (int nVars)
 Sets the number of variables (dimension) of the problem. More...
 
int getNumberOfObjs () const
 Get the number of objectives of the problem. More...
 
void setNumberOfObjs (int nObjs)
 Sets the number of objectives to the problem. More...
 
int getNumberOfCons () const
 Get the number the constraint of the problem. More...
 
void setNumberOfCons (int nCons)
 Sets the number of constraint of the problem. More...
 

Protected Attributes

vector< int > items
 
int capacity
 
std::string pathToInstance
 
- Protected Attributes inherited from Problem< IntIntSolution >
int numberOfVars
 
int numberOfObjs
 
int numberOfCons
 

Detailed Description

Class to represent the Bin Packing Problem.

Constructor & Destructor Documentation

◆ BPP() [1/3]

BPP::BPP ( const string &  path)

Construct a new BPP::BPP object from the data in the file in the path.

Parameters
path

◆ BPP() [2/3]

BPP::BPP ( const int &  numberOfVars,
const int &  capacity,
const vector< int > &  items 
)

Generates a BPP problem with all the data given in the arguments

Parameters
numberOfVars
capacity
weights
profits

◆ BPP() [3/3]

BPP::BPP ( const BPP bpp)

Construct a new BPP::BPP object from another BPP object.

Parameters
bpp

Member Function Documentation

◆ createSolution() [1/2]

IntIntSolution BPP::createSolution ( ) const
overridevirtual

Creates a random solution for the BPP Each items is assigned to a random bin in the range [0, numberOfVars)

Returns
IntIntSolution

Implements Problem< IntIntSolution >.

◆ createSolution() [2/2]

IntIntSolution BPP::createSolution ( ParallelPRNG &  engine) const
overridevirtual

Creates a random solution for the BPP Each items is assigned to a random bin in the range [0, numberOfVars)

Returns
IntIntSolution

Implements Problem< IntIntSolution >.

◆ evaluate()

void BPP::evaluate ( IntIntSolution solution) const
overridevirtual

Evaluates a bin assignment for the BPP instances represented in the object The fitness of the solution is the amount of unused space, as well as the number of bins for a specific solution. Falkenauer (1998) performance metric defined as:

(x) = \frac{\sum_{k=1}^{N} \left(\frac{fill_k}{C}\right)^2}{N}

Parameters
solution

Implements Problem< IntIntSolution >.

◆ evaluateConstraints()

bool BPP::evaluateConstraints ( IntIntSolution sol) const
inlineoverridevirtual

Method to evaluate whether a solution is feasible or not. This method must be implemented in the subclasses.

Parameters
solSolution (S) to evaluate
Returns
true if the solution is feasible
false otherwise

Implements Problem< IntIntSolution >.

◆ getLowerLimit()

float BPP::getLowerLimit ( int  i) const
overridevirtual

Returns the lower limit of the variable i In this case, the lower limit is 0.

Parameters
i
Returns
float

Implements Problem< IntIntSolution >.

◆ getName()

string BPP::getName ( ) const
inlineoverridevirtual

Returns the name of the problem. This method must be implemented in the subclasses.

Returns
string

Implements Problem< IntIntSolution >.

◆ getOptimizationDirection()

int BPP::getOptimizationDirection ( const int  i) const
overridevirtual

Gets the optimization direction of the problem. For the BPP is should always be Minimize.

Parameters
i
Returns
int

Implements Problem< IntIntSolution >.

◆ getUpperLimit()

float BPP::getUpperLimit ( int  i) const
overridevirtual

Returns the upper limit of the variable i In this case, the upper limit is the number of items - 1.

Parameters
i
Returns
float

Implements Problem< IntIntSolution >.

◆ readData()

void BPP::readData ( const string &  path)
override

Reads the data from the file in the path. The file should contain a proper BPP instance with the following format: nItems Q w0 w1 ... wn-1.

Parameters
path

◆ setCapacity()

void BPP::setCapacity ( int  Q)

Updates the capacity of the instance.

Parameters
Q

◆ to_json()

json BPP::to_json ( ) const
overridevirtual

Generates a JSON object with the information of the BPP problem

Returns

Reimplemented from Problem< IntIntSolution >.


The documentation for this class was generated from the following files: