dignea  1.0.0
Diverse Instance Generator with Novelty Search and Evolutionary Algorithms
Solution< V, O > Class Template Reference

Class to represent a solution to the optimization problems in the tool. More...

#include <Solution.h>

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

Public Member Functions

 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...
 
virtual json to_json () const
 Creates and returns a JSON representation of the solution. More...
 

Protected Attributes

int nVars
 
int nObjs
 
int nCons
 
float fitness
 
float constraintCoeff
 
vector< O > objectives
 
vector< V > variables
 
vector< O > constraints
 

Detailed Description

template<typename V, typename O>
class Solution< V, O >

Class to represent a solution to the optimization problems in the tool.

Template Parameters
VType of the variables of the solution (float, bool, int, etc)
OType of the objectives of the solution (float, bool, int, etc)

Constructor & Destructor Documentation

◆ Solution() [1/5]

template<typename V , typename O >
Solution< V, O >::Solution

Creates a Solution with all parameters set to zero.

Template Parameters
V
O

◆ Solution() [2/5]

template<typename V , typename O >
Solution< V, O >::Solution ( const int &  nVars,
const int &  nObjs 
)

Creates a new solution with the given dimension (nVars) and nObjs number of objectives.

Template Parameters
V
O
Parameters
nVars
nObjs

◆ Solution() [3/5]

template<typename V , typename O >
Solution< V, O >::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.

Template Parameters
V
O
Parameters
nVars
nObjs
nCons

◆ Solution() [4/5]

template<typename V , typename O >
Solution< V, O >::Solution ( const Solution< V, O > &  copy)

Creates a new solution with the information from copy.

Template Parameters
V
O
Parameters
copy

◆ Solution() [5/5]

template<typename V , typename O >
Solution< V, O >::Solution ( const Solution< V, O > *  copy)

Creates a new solution with the information from the pointer to other solution.

Template Parameters
V
O
Parameters
copy

Member Function Documentation

◆ getConstAt()

template<typename V , typename O >
O Solution< V, O >::getConstAt ( const int &  index) const
virtual

Returns the ith constraint value if exists.

Template Parameters
V
O
Parameters
index
Returns
O

◆ getConstraintCoeff()

template<typename V , typename O >
float Solution< V, O >::getConstraintCoeff ( ) const
inline

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.

Returns
float

◆ getConstraints()

template<typename V , typename O >
virtual const vector<O>& Solution< V, O >::getConstraints ( ) const
inlinevirtual

Get the constraint values of the solution.

Returns
const vector<O>&

◆ getCrowDistance()

template<typename V , typename O >
virtual float Solution< V, O >::getCrowDistance ( ) const
inlinevirtual

Get the Crow Distance object.

Returns
float

◆ getFitness()

template<typename V , typename O >
virtual float Solution< V, O >::getFitness ( ) const
inlinevirtual

Get the fitness of the solution.

Returns
float

◆ getNumberOfCons()

template<typename V , typename O >
virtual int Solution< V, O >::getNumberOfCons ( ) const
inlinevirtual

Get the number of constraint in the solution.

Returns
int

◆ getNumberOfObjs()

template<typename V , typename O >
virtual int Solution< V, O >::getNumberOfObjs ( ) const
inlinevirtual

Get the number of objectives of the solution.

Returns
int

◆ getNumberOfVars()

template<typename V , typename O >
virtual int Solution< V, O >::getNumberOfVars ( ) const
inlinevirtual

Get the number of variables (dimension) of the solution.

Returns
int

◆ getObjAt()

template<typename V , typename O >
O Solution< V, O >::getObjAt ( const int &  index) const
virtual

Returns the ith objective value if exists.

Template Parameters
V
O
Parameters
index
Returns
O

◆ getObjectives()

template<typename V , typename O >
virtual const vector<O>& Solution< V, O >::getObjectives ( ) const
inlinevirtual

Returns the objective values of the solution.

Returns
const vector<O>&

◆ getRank()

template<typename V , typename O >
virtual int Solution< V, O >::getRank ( ) const
inlinevirtual

Get the identifier of the solution in the population. Only used in the Non-Dominated Sorting operator.

Returns
unsigned int

◆ getVarAt()

template<typename V , typename O >
V Solution< V, O >::getVarAt ( const int &  index) const
virtual

Returns the ith variable if its in the valid range.

Template Parameters
V
O
Parameters
index
Returns
V

◆ getVariables()

template<typename V , typename O >
virtual const vector<V>& Solution< V, O >::getVariables ( ) const
inlinevirtual

Get the variables of the solution.

Returns
const vector<V>&

◆ operator=()

template<typename V , typename O >
Solution< V, O > & Solution< V, O >::operator= ( const Solution< V, O > &  copy)

Copies a solution using the assignment operator.

Template Parameters
V
O
Parameters
copy
Returns
Solution<V, O>&

◆ operator==()

template<typename V , typename O >
bool Solution< V, O >::operator== ( const Solution< V, O > &  other) const

Compares whether two solutions are equal.

Template Parameters
V
O
Parameters
other
Returns
true
false

◆ setConstAt()

template<typename V , typename O >
void Solution< V, O >::setConstAt ( const int &  index,
const O &  value 
)
virtual

Updates the ith constraint value with the value.

Template Parameters
V
O
Parameters
index
value

◆ setConstraintCoeff()

template<typename V , typename O >
void Solution< V, O >::setConstraintCoeff ( float  constraintCoeff)
inline

Set the constraint coefficient value.

Parameters
constraintCoeff

◆ setConstraints()

template<typename V , typename O >
void Solution< V, O >::setConstraints ( const vector< O > &  constr)
virtual

Updates the constraints of the solution.

Template Parameters
V
O
Parameters
constr

◆ setCrowDistance()

template<typename V , typename O >
virtual void Solution< V, O >::setCrowDistance ( float  d)
inlinevirtual

Set the Crow Distance object.

Parameters
d

◆ setFitness()

template<typename V , typename O >
virtual void Solution< V, O >::setFitness ( const float &  f)
inlinevirtual

Set the fitness of the solution.

Parameters
f

◆ setNumberOfbjs()

template<typename V , typename O >
virtual void Solution< V, O >::setNumberOfbjs ( const int &  numberOfObjs)
inlinevirtual

Set the number of objectives of the solution.

Parameters
numberOfObjs

◆ setNumberOfCons()

template<typename V , typename O >
virtual void Solution< V, O >::setNumberOfCons ( const int &  nConstraints)
inlinevirtual

Set the number of constraints of the solution.

Parameters
nConstraints

◆ setNumberOfVars()

template<typename V , typename O >
virtual void Solution< V, O >::setNumberOfVars ( const int &  numberOfVars)
inlinevirtual

Set the number of variables (dimension) of the solution.

Parameters
numberOfVars

◆ setObjAt()

template<typename V , typename O >
void Solution< V, O >::setObjAt ( const int &  index,
const O &  obj 
)
virtual

Updates the ith objective with the value obj.

Template Parameters
V
O
Parameters
index
obj

◆ setObjectives()

template<typename V , typename O >
void Solution< V, O >::setObjectives ( const vector< O > &  objs)
virtual

Updates the objective values of the solution.

Template Parameters
V
O
Parameters
objs

◆ setRank()

template<typename V , typename O >
virtual void Solution< V, O >::setRank ( int  id)
inlinevirtual

Set the identifier of the solution in the population. Only used in the Non-Dominated Sorting operator.

Parameters
id

◆ setVarAt()

template<typename V , typename O >
void Solution< V, O >::setVarAt ( const int &  index,
const V &  v 
)
virtual

Updates the ith variable of the solution with the value v.

Template Parameters
V
O
Parameters
index
v

◆ setVariables()

template<typename V , typename O >
void Solution< V, O >::setVariables ( const vector< V > &  vars)
virtual

Updates the variable values (dimension) of the solution.

Template Parameters
V
O
Parameters
vars

◆ to_json()

template<typename V , typename O >
json Solution< V, O >::to_json
virtual

Creates and returns a JSON representation of the solution.

Template Parameters
V
O
Returns
a JSON object

Reimplemented in TSPInstance, KPInstance, BPPInstance, AbstractInstance< V, O >, AbstractInstance< float, float >, AbstractInstance< int, int >, and AbstractInstance< int, float >.

Member Data Documentation

◆ constraintCoeff

template<typename V , typename O >
float Solution< V, O >::constraintCoeff
protected

Coefficient of constraint violation.

◆ constraints

template<typename V , typename O >
vector<O> Solution< V, O >::constraints
protected

Constraint values of the solution

◆ fitness

template<typename V , typename O >
float Solution< V, O >::fitness
protected

Fitness value of the solution. Always float.

◆ nCons

template<typename V , typename O >
int Solution< V, O >::nCons
protected

Number of constraints of the solution.

◆ nObjs

template<typename V , typename O >
int Solution< V, O >::nObjs
protected

Number of objectives of the solution.

◆ nVars

template<typename V , typename O >
int Solution< V, O >::nVars
protected

Number of variables of the solution (dimension).

◆ objectives

template<typename V , typename O >
vector<O> Solution< V, O >::objectives
protected

Objective values of the solution

◆ variables

template<typename V , typename O >
vector<V> Solution< V, O >::variables
protected

Variable values of the solution (genotype)


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