This class solves Travelling Salesman Problem task. More...
#include <tspsolver.h>
Public Slots | |
void | cancel () |
Cancels the solution process. | |
Signals | |
void | routePartFound (int n) |
This signal is emitted once every time a part of the route is found. | |
Public Member Functions | |
CTSPSolver (QObject *parent=NULL) | |
Constructs CTSPSolver object. | |
void | cleanup (bool processEvents=false) |
Cleans up the object and frees up memory used by the solution tree. | |
QString | getSortedPath (const QString &city, const QString &separator=" -> ") const |
Returns the sorted optimal path, starting from City 1. | |
int | getTotalSteps () const |
Returns a total number of steps in the current solution. | |
bool | isOptimal () const |
Indicates whether or not the solution is definitely optimal. | |
SStep * | solve (int numCities, const TMatrix &task) |
Solves the given task. | |
bool | wasCanceled () const |
Indicates whether or not the solution process was canceled. | |
Static Public Member Functions | |
static QString | getVersionId () |
Returns CTSPSolver's version ID. |
This class solves Travelling Salesman Problem task.
TSPSolver::CTSPSolver::CTSPSolver | ( | QObject * | parent = NULL |
) |
Constructs CTSPSolver object.
parent | A parent object. |
void TSPSolver::CTSPSolver::cleanup | ( | bool | processEvents = false |
) |
Cleans up the object and frees up memory used by the solution tree.
processEvents | If set to true then QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents) will be called from time to time while cleaning up. |
QString TSPSolver::CTSPSolver::getSortedPath | ( | const QString & | city, | |
const QString & | separator = " -> " | |||
) | const |
Returns the sorted optimal path, starting from City 1.
city | A string that represents city elements in the path. | |
separator | A string that represents separators between cities in the path. |
The resulting path will be in the form city+separator+city+...+separator+city. %1
in city will be replaced by the city number.
int TSPSolver::CTSPSolver::getTotalSteps | ( | ) | const |
Returns a total number of steps in the current solution.
0
if no solution. QString TSPSolver::CTSPSolver::getVersionId | ( | ) | [static] |
Returns CTSPSolver's version ID.
bool TSPSolver::CTSPSolver::isOptimal | ( | ) | const |
Indicates whether or not the solution is definitely optimal.
true
if the solution is definitely optimal, otherwise false
.The solution may need some further iterations to determine whether or not it is optimal. In such cases this function returns false
.
void TSPSolver::CTSPSolver::routePartFound | ( | int | n | ) | [signal] |
This signal is emitted once every time a part of the route is found.
n | Indicates the number of the route parts found. |
Solves the given task.
numCities | Number of cities in the task. | |
task | The matrix of city-to-city travel costs. |
bool TSPSolver::CTSPSolver::wasCanceled | ( | ) | const |
Indicates whether or not the solution process was canceled.
true
if the solution process was canceled, otherwise false
.