source: tspsg-svn/trunk/src/tspsolver.h @ 66

Last change on this file since 66 was 66, checked in by laleppa, 15 years ago

Some documentation updates.

  • Property svn:keywords set to Id URL
File size: 2.7 KB
RevLine 
[65]1/*!
2 * \class CTSPSolver
3 * \author Copyright &copy; 2007-2009 Lёppa <contacts[at]oleksii[dot]name>
4 * \brief This class solves Travelling Salesman Problem task.
[12]5 *
6 *  $Id: tspsolver.h 66 2009-10-21 12:48:49Z laleppa $
7 *  $URL: https://tspsg.svn.sourceforge.net/svnroot/tspsg/trunk/src/tspsolver.h $
8 *
[65]9 *  <b>TSPSG: TSP Solver and Generator</b>
10 *
[12]11 *  This file is part of TSPSG.
12 *
13 *  TSPSG is free software: you can redistribute it and/or modify
14 *  it under the terms of the GNU General Public License as published by
15 *  the Free Software Foundation, either version 3 of the License, or
16 *  (at your option) any later version.
17 *
18 *  TSPSG is distributed in the hope that it will be useful,
19 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 *  GNU General Public License for more details.
22 *
23 *  You should have received a copy of the GNU General Public License
24 *  along with TSPSG.  If not, see <http://www.gnu.org/licenses/>.
[65]25 *
26 * \todo TODO: Deletion of solution tree on destroy and cleanup.
[12]27 */
28
29#ifndef TSPSOLVER_H
30#define TSPSOLVER_H
31
[66]32/*!
33 * \file tspsolver.h
34 * \brief Defines #tMatrix typedef, sStep struct and CTSPSolver class.
35 */
36
[31]37#include "globals.h"
[12]38
[64]39#include "tspmodel.h"
40
[65]41//! A matrix of city-to-city travel costs.
[46]42typedef QList<QList<double> > tMatrix;
[13]43
[65]44/*!
45 * \brief This structure represents one step of solving.
46 *
47 *  A tree of such elements will represent the solving process.
48 */
49//! \todo TODO: List alternative candidates.
[12]50struct sStep {
[65]51        tMatrix matrix; //!< This step's matrix
52        double price; //!< The price of travel to this step
53        struct {
54                int nRow; //!< A zero-based row number of the candidate
55                int nCol; //!< A zero-based column number of the candidate
56        } candidate; //!< A candiadate for branching in the current matrix
57        bool alts; //!< Indicates whether or not matrix has alternative candidates
58        sStep *plNode; //!< Pointer to the left branch step
59        sStep *prNode; //!< Pointer to the right branch step
60
61        //! Assigns default values
62        sStep() {
63                price = candidate.nRow = candidate.nCol = -1;
64                alts = false;
65                plNode = prNode = NULL;
66        }
[12]67};
68
69class CTSPSolver
70{
[42]71        Q_DECLARE_TR_FUNCTIONS(CTSPSolver)
72
[12]73public:
74        CTSPSolver();
[60]75        QString getSortedPath() const;
76        bool isOptimal() const;
[42]77        sStep *solve(int, tMatrix, QWidget *parent = 0);
[63]78        static QString getVersionId();
[42]79
[13]80private:
[60]81        bool mayNotBeOptimal;
[13]82        int nCities;
83        sStep *root;
[42]84        QHash<int,int> route;
[50]85//      QHash<int,int> forbidden;
[42]86        double align(tMatrix &);
87        void cleanup();
[60]88        bool findCandidate(tMatrix, int &, int &);
[42]89        double findMinInRow(int, tMatrix, int exc = -1);
90        double findMinInCol(int, tMatrix, int exr = -1);
91        bool hasSubCycles(int, int);
92        void subCol(tMatrix &, int, double);
93        void subRow(tMatrix &, int, double);
[12]94};
95
96#endif // TSPSOLVER_H
Note: See TracBrowser for help on using the repository browser.