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

Instance Traveling Salesman Problem Solution. Class which represents the solution for the Instance Traveling Salesman Problem (TSPDomain). The variables inherited from the Solution<float, float> class contains the pairs of coordinates for each point (city) in the instance. [(x0,y0), ..., (xn-1,yn-1)] in a single array. More...

#include <TSPInstance.h>

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

Public Member Functions

 TSPInstance ()
 Creates a default TSPInstance. More...
 
 TSPInstance (const int &nVars, const int &nObjs=1)
 Creates a TSPInstance with a specified dimension. Notice that passing nVars = 100 will create a 50 cities since the number of variables must be divided by two to contain the coordinates for each city. More...
 
 TSPInstance (const TSPInstance &solution)
 Creates a new TSPInstance object with the information from other solution. More...
 
 TSPInstance (const TSPInstance *solution)
 Creates a new TSPInstance object with the information from other solution. More...
 
 TSPInstance (unique_ptr< TSPInstance > &ptr)=delete
 Cannot be used in the AbstractInstance. More...
 
void setVariables (const vector< float > &vars) override
 Set the variables for the instance. More...
 
json to_json () const override
 Creates and returns a JSON object with the information from the TSP. More...
 
virtual void to_instance (std::ostream &os) const
 Generates the instance representation of the TSP and puts it in the ostream. More...
 
vector< coordsto_coords () const
 Generates the vector of coordinates for the instance. Look the TSP getPoints() method. More...
 
- Public Member Functions inherited from AbstractInstance< float, 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...
 
virtual vector< float > getFeatures () const
 Get 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...
 

Additional Inherited Members

- Protected Attributes inherited from AbstractInstance< float, 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 Traveling Salesman Problem Solution. Class which represents the solution for the Instance Traveling Salesman Problem (TSPDomain). The variables inherited from the Solution<float, float> class contains the pairs of coordinates for each point (city) in the instance. [(x0,y0), ..., (xn-1,yn-1)] in a single array.

Constructor & Destructor Documentation

◆ TSPInstance() [1/5]

TSPInstance::TSPInstance ( )

Creates a default TSPInstance.

Construct a new TSPInstance::TSPInstance object.

◆ TSPInstance() [2/5]

TSPInstance::TSPInstance ( const int &  nVars,
const int &  nObjs = 1 
)
explicit

Creates a TSPInstance with a specified dimension. Notice that passing nVars = 100 will create a 50 cities since the number of variables must be divided by two to contain the coordinates for each city.

Construct a new TSPInstance::TSPInstance object.

Parameters
nVars

◆ TSPInstance() [3/5]

TSPInstance::TSPInstance ( const TSPInstance solution)

Creates a new TSPInstance object with the information from other solution.

Construct a new TSPInstance::TSPInstance object.

Parameters
solution

◆ TSPInstance() [4/5]

TSPInstance::TSPInstance ( const TSPInstance solution)
explicit

Creates a new TSPInstance object with the information from other solution.

Construct a new TSPInstance::TSPInstance object.

Parameters
solution

◆ TSPInstance() [5/5]

TSPInstance::TSPInstance ( unique_ptr< TSPInstance > &  ptr)
delete

Cannot be used in the AbstractInstance.

Parameters
ptr

Member Function Documentation

◆ setVariables()

void TSPInstance::setVariables ( const vector< float > &  vars)
override

Set the variables for the instance.

Parameters
vars

Sets the variables of the solution. Expected to be pairs (x,y).

Parameters
vars

◆ to_coords()

vector< coords > TSPInstance::to_coords ( ) const

Generates the vector of coordinates for the instance. Look the TSP getPoints() method.

Converts the variables into a vector of pairs (x, y) coords.

Returns
coords

◆ to_instance()

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

Generates the instance representation of the TSP and puts it in the ostream.

Generates a instance representation of the TSP problem.

Parameters
os

Reimplemented from AbstractInstance< float, float >.

◆ to_json()

json TSPInstance::to_json ( ) const
overridevirtual

Creates and returns a JSON object with the information from the TSP.

Returns

Creates a JSON object with the information of the TSPInstance

Returns

Reimplemented from Solution< V, O >.


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