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

Instance Knapsack Problem Solution. Class which represents the solution for the Instance Knapsack Problem (EKPP). This class is used to represent an actual Knapsack Problem instance. More...

#include <KPInstance.h>

Inheritance diagram for KPInstance:
AbstractInstance< int, float > Solution< V, O >

Public Member Functions

 KPInstance (const int &nVars, const int &nObjs=1, bool reducedSpace=false)
 
 KPInstance (const KPInstance &solution)
 
 KPInstance (const KPInstance *solution)
 
 KPInstance (unique_ptr< KPInstance > &ptr)=delete
 
KPInstanceoperator= (const KPInstance &copy)
 Copies a solution using the assignment operator. More...
 
bool operator== (const KPInstance &other) const
 Compares whether two solutions are equal. More...
 
void setCapacity (const int &Q)
 
int getCapacity (void) const
 
vector< float > getFeatures () const override
 Get the features. If reducedSpace is true in IKProblem the features are the (x0, x1) principal components after applying PCA. More...
 
void setVariables (const vector< int > &vars) override
 Sets the variables of the solution. Expected to be twice of number of vars since it stores the pairs (wi,pi). More...
 
bool isReducedSpace () const
 Check if the search is performed in a PCA space. More...
 
json to_json () const override
 Creates a JSON object with the information of the KPInstance. More...
 
virtual void to_instance (std::ostream &os) const
 Generates a instance representation of the KP problem. More...
 
- Public Member Functions inherited from AbstractInstance< int, float >
 AbstractInstance ()
 Construct a new AbstractInstance<V, O>::AbstractInstance object. More...
 
 AbstractInstance (const int &nVars, const int &nObjs=1, const int &nCons=0)
 Construct a new AbstractInstance<V, O>::AbstractInstance object from the data given in the arguments. More...
 
 AbstractInstance (const AbstractInstance &solution)
 Construct a new AbstractInstance<V, O>::AbstractInstance object from the data in the given solution. More...
 
 AbstractInstance (const AbstractInstance *solution)
 Construct a new AbstractInstance<V, O>::AbstractInstance object from the data in the given solution. More...
 
 AbstractInstance (unique_ptr< AbstractInstance > &ptr)=delete
 
AbstractInstanceoperator= (const AbstractInstance &copy)
 Copies a solution using the assignment operator. More...
 
bool operator== (const AbstractInstance &other) const
 Compares whether two solutions are equal. More...
 
json to_json () const override
 Creates a JSON format representation of the solution. It must be override by the subclasses. More...
 
void setFeatures (const vector< float > &v)
 Set the features descriptor of this instance. More...
 
float getDiversity () const
 Get the Diversity of the solution. More...
 
void setDiversity (float diversity)
 Set the Diversity of the solution. The diversity of the instance is computed using the Novelty Search. More...
 
float getBiasedFitness () const
 Get the Biased Fitness value. The BiasedFitness is the fitness value compute exclusively from the difference in performance between the target and the other algorithms in the portfolio. To get the fitness value computed with the WFF use the getFitness() method. More...
 
void setBiasedFitness (float bFitness)
 Set the Biased Fitness value. The BiasedFitness is the fitness value compute exclusively from the difference in performance between the target and the other algorithms in the portfolio. More...
 
void setConfigFitness (const vector< vector< float >> &fitness)
 Set the fitness of each algorithm in the porftolio over this instance. More...
 
void setAvgConfigFitness (const vector< float > &fitness)
 Set the average fitness of each algorithm in the porftolio over this instance. More...
 
vector< vector< float > > getPortFitness () const
 Get the Config Fitness matrix. More...
 
vector< float > getAvgPortFitness () const
 Get the Avg Config Fitness vector. More...
 
- Public Member Functions inherited from Solution< V, O >
 Solution ()
 Creates a Solution with all parameters set to zero. More...
 
 Solution (const int &nVars, const int &nObjs)
 Creates a new solution with the given dimension (nVars) and nObjs number of objectives. More...
 
 Solution (const int &nVars, const int &nObjs, const int &nCons)
 Creates a new solution with the given dimension (nVars), nObjs number of objectives and nCons number of constraints. More...
 
 Solution (const Solution< V, O > &)
 Creates a new solution with the information from copy. More...
 
 Solution (const Solution< V, O > *)
 Creates a new solution with the information from the pointer to other solution. More...
 
Solutionoperator= (const Solution &copy)
 Copies a solution using the assignment operator. More...
 
bool operator== (const Solution &other) const
 Compares whether two solutions are equal. More...
 
virtual const vector< O > & getObjectives () const
 Returns the objective values of the solution. More...
 
virtual void setObjectives (const vector< O > &objs)
 Updates the objective values of the solution. More...
 
virtual const vector< V > & getVariables () const
 Get the variables of the solution. More...
 
virtual void setVariables (const vector< V > &vars)
 Updates the variable values (dimension) of the solution. More...
 
virtual const vector< O > & getConstraints () const
 Get the constraint values of the solution. More...
 
virtual void setConstraints (const vector< O > &constr)
 Updates the constraints of the solution. More...
 
virtual int getNumberOfVars () const
 Get the number of variables (dimension) of the solution. More...
 
virtual void setNumberOfVars (const int &numberOfVars)
 Set the number of variables (dimension) of the solution. More...
 
virtual int getNumberOfObjs () const
 Get the number of objectives of the solution. More...
 
virtual void setNumberOfbjs (const int &numberOfObjs)
 Set the number of objectives of the solution. More...
 
virtual int getNumberOfCons () const
 Get the number of constraint in the solution. More...
 
virtual void setNumberOfCons (const int &nConstraints)
 Set the number of constraints of the solution. More...
 
virtual void setRank (int id)
 Set the identifier of the solution in the population. Only used in the Non-Dominated Sorting operator. More...
 
virtual int getRank () const
 Get the identifier of the solution in the population. Only used in the Non-Dominated Sorting operator. More...
 
virtual void setCrowDistance (float d)
 Set the Crow Distance object. More...
 
virtual float getCrowDistance () const
 Get the Crow Distance object. More...
 
virtual void setVarAt (const int &, const V &v)
 Updates the ith variable of the solution with the value v. More...
 
virtual void setObjAt (const int &, const O &obj)
 Updates the ith objective with the value obj. More...
 
virtual void setConstAt (const int &, const O &cons)
 Updates the ith constraint value with the value. More...
 
virtual V getVarAt (const int &index) const
 Returns the ith variable if its in the valid range. More...
 
virtual O getObjAt (const int &index) const
 Returns the ith objective value if exists. More...
 
virtual O getConstAt (const int &index) const
 Returns the ith constraint value if exists. More...
 
virtual float getFitness () const
 Get the fitness of the solution. More...
 
virtual void setFitness (const float &f)
 Set the fitness of the solution. More...
 
float getConstraintCoeff () const
 Get the constraint coefficient of the solutions. This value means different for every problem. In most cases is the weighted sum of constraint violation values. More...
 
void setConstraintCoeff (float constraintCoeff)
 Set the constraint coefficient value. More...
 

Protected Attributes

int capacity
 
bool reducedSpace
 
- Protected Attributes inherited from AbstractInstance< int, float >
vector< float > features
 Vector of features of the instance. This is problem dependent and must defined in order and computed after each evaluation of the instance.
 
float diversity
 Individual diversity respect to the rest of the population.
 
float biasedFitness
 Individual's fitness regarding to the performance of the target algorithm.
 
vector< vector< float > > portFitness
 Best fitness founds for all the algorithms in the portfolio that has solved the instance.
 
vector< float > avgPortFitness
 Average best fitness founds for all the algorithms in the portfolio that has solved the instance in the number of repetitions performed.
 
- Protected Attributes inherited from Solution< V, O >
int nVars
 
int nObjs
 
int nCons
 
float fitness
 
float constraintCoeff
 
vector< O > objectives
 
vector< V > variables
 
vector< O > constraints
 

Detailed Description

Instance Knapsack Problem Solution. Class which represents the solution for the Instance Knapsack Problem (EKPP). This class is used to represent an actual Knapsack Problem instance.

  • The variables inherited from the Solution<int, float> class contains the pairs [(w0,p0), ..., (wn-1,pn-1)] in a single array.
  • The capacity is stored separately.

Member Function Documentation

◆ getFeatures()

vector< float > KPInstance::getFeatures ( ) const
overridevirtual

Get the features. If reducedSpace is true in IKProblem the features are the (x0, x1) principal components after applying PCA.

Returns
vector<float>

Reimplemented from AbstractInstance< int, float >.

◆ isReducedSpace()

bool KPInstance::isReducedSpace ( ) const
inline

Check if the search is performed in a PCA space.

Returns
true if reducedSpace false otherwise

◆ operator=()

KPInstance & KPInstance::operator= ( const KPInstance copy)

Copies a solution using the assignment operator.

Template Parameters
VVariable type for the solution representation
OObjective type for the fitness
Parameters
copyKPInstance to create a copy of
Returns
KPInstance

◆ operator==()

bool KPInstance::operator== ( const KPInstance other) const

Compares whether two solutions are equal.

Template Parameters
VVariable type for the solution representation
OObjective type for the fitness
Parameters
otherAbstractInstance to compare to
Returns
true
false

◆ setVariables()

void KPInstance::setVariables ( const vector< int > &  vars)
override

Sets the variables of the solution. Expected to be twice of number of vars since it stores the pairs (wi,pi).

Parameters
vars

◆ to_instance()

void KPInstance::to_instance ( std::ostream &  os) const
virtual

Generates a instance representation of the KP problem.

Parameters
os

Reimplemented from AbstractInstance< int, float >.

◆ to_json()

json KPInstance::to_json ( ) const
overridevirtual

Creates a JSON object with the information of the KPInstance.

Returns

Reimplemented from Solution< V, O >.


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