36 #include <QStringList>
45 # define INFINITY std::numeric_limits<double>::infinity()
75 return ((cand.
nRow == nRow) && (cand.
nCol == nCol));
99 pNode = plNode = prNode = NULL;
116 void cleanup(
bool processEvents =
false);
121 SStep *
solve(
int numCities,
const TMatrix &task);
136 bool mayNotBeOptimal, canceled, cc;
142 double align(TMatrix &matrix);
143 void deleteTree(
SStep *&root,
bool processEvents =
false);
144 void denormalize(TMatrix &matrix)
const;
146 double findMinInCol(
int nCol,
const TMatrix &matrix,
int exr = -1)
const;
147 double findMinInRow(
int nRow,
const TMatrix &matrix,
int exc = -1)
const;
149 bool hasSubCycles(
int nRow,
int nCol)
const;
150 void normalize(TMatrix &matrix)
const;
151 void subCol(TMatrix &matrix,
int nCol,
double val);
152 void subRow(TMatrix &matrix,
int nRow,
double val);
162 #endif // TSPSOLVER_H
A TSP Solver namespace.
Definition: tspsolver.cpp:35
void routePartFound(int n)
This signal is emitted once every time a part of the route is found.
int getTotalSteps() const
Returns a total number of steps in the current solution.
Definition: tspsolver.cpp:100
A structure that represents a candidate for branching.
Definition: tspsolver.h:65
Left branch was selected for the next step.
Definition: tspsolver.h:82
SStep * plNode
Pointer to the left branch step.
Definition: tspsolver.h:92
SCandidate()
Assigns default values.
Definition: tspsolver.h:70
This class solves Travelling Salesman Problem task.
Definition: tspsolver.h:108
SStep * solve(int numCities, const TMatrix &task)
Solves the given task.
Definition: tspsolver.cpp:140
SStep()
Assigns default values.
Definition: tspsolver.h:97
int nRow
A zero-based row number of the candidate.
Definition: tspsolver.h:66
bool isOptimal() const
Indicates whether or not the solution is definitely optimal.
Definition: tspsolver.cpp:112
CTSPSolver(QObject *parent=NULL)
Constructs CTSPSolver object.
Definition: tspsolver.cpp:50
This structure represents one step of solving.
Definition: tspsolver.h:63
void cleanup(bool processEvents=false)
Cleans up the object and frees up memory used by the solution tree.
Definition: tspsolver.cpp:61
double price
The price of travel to this step.
Definition: tspsolver.h:87
SStep * pNode
Pointer to the parent step.
Definition: tspsolver.h:91
QList< QList< double > > TMatrix
A matrix of city-to-city travel costs.
Definition: tspsolver.h:56
int nCol
A zero-based column number of the candidate.
Definition: tspsolver.h:67
static QString getVersionId()
Returns CTSPSolver's version ID.
Definition: tspsolver.cpp:41
Right branch was selected for the next step.
Definition: tspsolver.h:83
bool wasCanceled() const
Indicates whether or not the solution process was canceled.
Definition: tspsolver.cpp:257
QList< SCandidate > alts
A list of alternative branching candidates.
Definition: tspsolver.h:90
SStep * prNode
Pointer to the right branch step.
Definition: tspsolver.h:93
NextStep
An enum that describes possible selection of the next step.
Definition: tspsolver.h:80
bool operator==(const SCandidate &cand) const
An operator == implementation.
Definition: tspsolver.h:74
No next step (end of solution)
Definition: tspsolver.h:81
void cancel()
Cancels the solution process.
Definition: tspsolver.cpp:266
SCandidate candidate
A candiadate for branching in the current step.
Definition: tspsolver.h:89
void setCleanupOnCancel(bool enable=true)
Sets whether or not to call cleanup() on solution cancel.
Definition: tspsolver.cpp:127
TMatrix matrix
This step's matrix.
Definition: tspsolver.h:86
NextStep next
Indicates what branch was selected for the next step.
Definition: tspsolver.h:94
QString getSortedPath(const QString &city, const QString &separator=QString(" -> ")) const
Returns the sorted optimal path, starting from City 1.
Definition: tspsolver.cpp:78