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

Class representing a Knapsack Problem. More...

#include <KP.h>

Inheritance diagram for KP:
Problem< BoolFloatSolution > KPNR

Public Member Functions

 KP (const int &numberOfVars)
 
 KP (const string &pathToInstance)
 
 KP (const int &numberOfVars, const int &capacity, const vector< int > &weights, const vector< int > &profits)
 
 KP (const int &numberOfVars, const int &lowerWeight, const int &upperWeight, const int &lowerProfit, const int &upperProfit)
 
 KP (const KP *)
 
float getUpperLimit (int i) const override
 Returns the upper bound to the problem at dimension i. This method must be implemented in the subclasses. More...
 
int getOptimizationDirection (const int i) const override
 Returns the optimization direction for each objective in the problem. It returns Minimize or Maximize accordingly. This method must be implemented in the subclasses. More...
 
float getLowerLimit (int i) const override
 Returns the lower bound to the problem at dimension i. This method must be implemented in the subclasses. More...
 
string getName () const override
 Returns the name of the problem. This method must be implemented in the subclasses. More...
 
void evaluate (BoolFloatSolution &solution) const override
 
bool evaluateConstraints (BoolFloatSolution &ptr) const override
 
BoolFloatSolution createSolution () const override
 
BoolFloatSolution createSolution (ParallelPRNG &engine) const override
 
int getLowWeight () const
 
void setLowWeight (int lowWeight)
 
int getUpWeight () const
 
void setUpWeight (int upWeight)
 
int getLowProfit () const
 
void setLowProfit (int lowProfit)
 
int getUpProfit () const
 
void setUpProfit (int upProfit)
 
const vector< int > & getProfits () const
 
void setProfits (const vector< int > &profits)
 
const vector< int > & getWeights () const
 
void setWeights (const vector< int > &weights)
 
int getCapacity () const
 
void setCapacity (int capacity)
 
void readData (const string &path) override
 
json to_json () const override
 
vector< iEff > getItemsSortedByEff () const
 
- Public Member Functions inherited from Problem< BoolFloatSolution >
 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...
 

Static Public Attributes

static const string INSTANCE = "Instance"
 
static const string PROFITS = "Profits"
 
static const string WEIGHTS = "Weights"
 
static const string CAPACITY = "Capacity"
 

Protected Member Functions

void computeEfficiency ()
 
void repair (BoolFloatSolution &solution) const
 

Protected Attributes

int lowWeight
 
int upWeight
 
int lowProfit
 
int upProfit
 
vector< int > profits
 
vector< int > weights
 
int capacity
 
std::string pathToInstance
 
vector< iEff > itemsEff
 
- Protected Attributes inherited from Problem< BoolFloatSolution >
int numberOfVars
 
int numberOfObjs
 
int numberOfCons
 

Detailed Description

Class representing a Knapsack Problem.

Constructor & Destructor Documentation

◆ KP() [1/2]

KP::KP ( const string &  path)

Crea una instancia del problema de la mochila a partir de la instancia en el directorio recibido

Parameters
pathTo

◆ KP() [2/2]

KP::KP ( const int &  numberOfVars,
const int &  capacity,
const vector< int > &  newWeights,
const vector< int > &  newProfits 
)

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

Parameters
numberOfVars
capacity
weights
profits

Member Function Documentation

◆ computeEfficiency()

void KP::computeEfficiency ( )
protected

Calcula la eficiencia de cada elemento de la instancia. La eficiencia de un elemento es el ratio p/w del elemento. Los elementos se ordenan descendentemente

◆ createSolution()

BoolFloatSolution KP::createSolution ( ) const
overridevirtual

Crea una solucion aleatoria con true y false

Returns

Implements Problem< BoolFloatSolution >.

◆ evaluate()

void KP::evaluate ( BoolFloatSolution solution) const
overridevirtual

Metodo de evaluacion de una solucion al problema KP

Parameters
solution

Implements Problem< BoolFloatSolution >.

Reimplemented in KPNR.

◆ evaluateConstraints()

bool KP::evaluateConstraints ( BoolFloatSolution solution) const
overridevirtual

Evaluacion de las restricciones para la solucion

Parameters
ptr

Implements Problem< BoolFloatSolution >.

◆ getLowerLimit()

float KP::getLowerLimit ( int  i) const
overridevirtual

Returns the lower bound to the problem at dimension i. This method must be implemented in the subclasses.

Parameters
i
Returns
float

Implements Problem< BoolFloatSolution >.

◆ getName()

string KP::getName ( ) const
inlineoverridevirtual

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

Returns
string

Implements Problem< BoolFloatSolution >.

◆ getOptimizationDirection()

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

Returns the optimization direction for each objective in the problem. It returns Minimize or Maximize accordingly. This method must be implemented in the subclasses.

Parameters
iDimension to check
Returns
Minimize or Maximize constants.

Implements Problem< BoolFloatSolution >.

◆ getUpperLimit()

float KP::getUpperLimit ( int  i) const
overridevirtual

Returns the upper bound to the problem at dimension i. This method must be implemented in the subclasses.

Parameters
iDimension to check
Returns
float

Implements Problem< BoolFloatSolution >.

◆ readData()

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

Método para leer un fichero de instancia del KP. La estructura esperada del fichero es la siguiente: nItems Q w0 p0 w1 p1 ... wn-1 pn-1

Parameters
path

◆ repair()

void KP::repair ( BoolFloatSolution solution) const
protected

Heuristica de reparacion que se encarga de eliminar los elementos menos eficientes

◆ to_json()

json KP::to_json ( ) const
overridevirtual

Generates a JSON object with the information of the KP problem

Returns

Reimplemented from Problem< BoolFloatSolution >.


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