dignea
1.0.0
Diverse Instance Generator with Novelty Search and Evolutionary Algorithms
|
Traveling Salesman Problem implemented in dignea. Uses a IntFloat representation where the solutions are integers in a permutation-based approach and the fitness is a float with the cost of a travel. More...
#include <TSP.h>
Public Member Functions | |
TSP () | |
Creates a default TSP object. More... | |
TSP (const int &numberOfVars) | |
Creates a TSP object with a predefined number of cities. More... | |
TSP (const int &numberOfVars, const vector< coords > &coordinates) | |
Creates a TSP object with a predefined number of cities and the coordinates for each one. More... | |
TSP (const string &pathToInstance) | |
Creates a TSP object which loads the data from the filesystem. More... | |
TSP (TSP const *other) | |
Creates a TSP copying the information from other instance. More... | |
float | getUpperLimit (int i) const override |
Get the upper bound of the search space. In this case the upper bound is the number of variables minus one since the starting city is duplicated at the end of the travel. More... | |
int | getOptimizationDirection (const int i) const override |
Get the optimization direction. Only for dimension = 0 and returns Minimize. More... | |
float | getLowerLimit (int i) const override |
Get the lower bound of the search space (1). More... | |
string | getName () const override |
Get the name of the problem. More... | |
const vector< vector< float > > & | getDistances () const |
Get the matrix of distances between each city in the instance. More... | |
const vector< coords > & | getPoints () const |
Get the points of the instances as coordinates. More... | |
const std::string | getPathToInstance () const |
Get the path to the instance if used. More... | |
void | evaluate (IntFloatSolution &solution) const override |
Evaluates a solution to the TSP. More... | |
bool | evaluateConstraints (IntFloatSolution &solution) const override |
Evaluates whether a solution is feasible of not regarding to the TSP formulation. More... | |
IntFloatSolution | createSolution () const override |
Creates and return a random solution for the TSP. More... | |
IntFloatSolution | createSolution (ParallelPRNG &engine) const override |
Creates and return a random solution for the TSP. More... | |
void | readData (const string &path) override |
Reads the instance information from the filesystem. More... | |
json | to_json () const override |
Creates and return the JSON representation of the TSP problem. More... | |
Public Member Functions inherited from Problem< IntFloatSolution > | |
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 Member Functions | |
void | computeDistances () |
Computes the distance from each point to the other in the instance. | |
Protected Attributes | |
std::string | pathToInstance |
vector< coords > | points |
vector< vector< float > > | distances |
Protected Attributes inherited from Problem< IntFloatSolution > | |
int | numberOfVars |
int | numberOfObjs |
int | numberOfCons |
Traveling Salesman Problem implemented in dignea. Uses a IntFloat representation where the solutions are integers in a permutation-based approach and the fitness is a float with the cost of a travel.
|
explicit |
|
explicit |
TSP::TSP | ( | const string & | path | ) |
TSP::TSP | ( | TSP const * | tsp | ) |
|
overridevirtual |
Creates and return a random solution for the TSP.
Creates a new solution for the TSP.
Implements Problem< IntFloatSolution >.
|
overridevirtual |
Creates and return a random solution for the TSP.
Creates a solution for the TSP using a Parallel RNG.
engine |
Implements Problem< IntFloatSolution >.
|
overridevirtual |
Evaluates a solution to the TSP.
solution |
Metodo de evaluacion de una solucion al problema KP
solution |
Implements Problem< IntFloatSolution >.
|
overridevirtual |
Evaluates whether a solution is feasible of not regarding to the TSP formulation.
Evaluates whether the solution does not contain a point more than once Also checks that the solution starts and ends in the first city (aka point 0)
solution |
solution |
Implements Problem< IntFloatSolution >.
|
inline |
Get the matrix of distances between each city in the instance.
|
overridevirtual |
Get the lower bound of the search space (1).
Gets lower limit for TSP. In this case it's fixed to 1.
i |
i |
Implements Problem< IntFloatSolution >.
|
inlineoverridevirtual |
Get the name of the problem.
Implements Problem< IntFloatSolution >.
|
overridevirtual |
Get the optimization direction. Only for dimension = 0 and returns Minimize.
i |
Implements Problem< IntFloatSolution >.
|
inline |
Get the path to the instance if used.
|
inline |
Get the points of the instances as coordinates.
|
overridevirtual |
Get the upper bound of the search space. In this case the upper bound is the number of variables minus one since the starting city is duplicated at the end of the travel.
Gets upper limit for TSP which it's the amount of available cities in the instance.
i |
i |
Implements Problem< IntFloatSolution >.
|
override |
Reads the instance information from the filesystem.
path |
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
path |
|
overridevirtual |
Creates and return the JSON representation of the TSP problem.
Generates a JSON object with the information of the KP problem
Reimplemented from Problem< IntFloatSolution >.
|
protected |
Distance matrix
|
protected |
Path to the instance file
|
protected |
Coordinates of cities (points)