Changeset f0464480db in tspsg for src/tspsolver.h
- Timestamp:
- Dec 16, 2009, 11:22:05 PM (14 years ago)
- Branches:
- 0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
- Children:
- 0bd0e1aca7
- Parents:
- 53f11f0e6c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tspsolver.h
r53f11f0e6c rf0464480db 34 34 35 35 //! A matrix of city-to-city travel costs. 36 typedef QList<QList<double> > tMatrix; 36 typedef QList<QList<double> > TMatrix; 37 38 /*! 39 * \brief A structure that represents a candidate for branching. 40 */ 41 struct TCandidate { 42 int nRow; //!< A zero-based row number of the candidate 43 int nCol; //!< A zero-based column number of the candidate 44 45 //! Assigns default values 46 TCandidate() { 47 nCol = nRow = -1; 48 } 49 //! An operator == implementation 50 bool operator ==(const TCandidate &cand) const { 51 return ((cand.nRow == nRow) && (cand.nCol == nCol)); 52 } 53 }; 37 54 38 55 /*! … … 41 58 * A tree of such elements will represent the solving process. 42 59 */ 43 //! \todo TODO: List alternative candidates. 44 struct sStep { 45 tMatrix matrix; //!< This step's matrix 60 struct SStep { 61 TMatrix matrix; //!< This step's matrix 46 62 double price; //!< The price of travel to this step 47 struct { 48 int nRow; //!< A zero-based row number of the candidate 49 int nCol; //!< A zero-based column number of the candidate 50 } candidate; //!< A candiadate for branching in the current matrix 51 bool alts; //!< Indicates whether or not matrix has alternative candidates 52 sStep *plNode; //!< Pointer to the left branch step 53 sStep *prNode; //!< Pointer to the right branch step 63 TCandidate candidate; //!< A candiadate for branching in the current matrix 64 QList<TCandidate> alts; //!< A list of alternative branching candidates 65 SStep *plNode; //!< Pointer to the left branch step 66 SStep *prNode; //!< Pointer to the right branch step 54 67 55 68 //! Assigns default values 56 sStep() { 57 price = candidate.nRow = candidate.nCol = -1; 58 alts = false; 69 SStep() { 70 price = -1; 59 71 plNode = prNode = NULL; 60 72 } … … 76 88 static QString getVersionId(); 77 89 bool isOptimal() const; 78 sStep *solve(int numCities, tMatrix task, QWidget *parent = 0); 90 SStep *solve(int numCities, TMatrix task, QWidget *parent = 0); 91 ~CTSPSolver(); 79 92 80 93 private: 81 94 bool mayNotBeOptimal; 82 95 int nCities; 83 sStep *root;96 SStep *root; 84 97 QHash<int,int> route; 85 98 // QHash<int,int> forbidden; 86 99 87 double align( tMatrix &matrix);100 double align(TMatrix &matrix); 88 101 void cleanup(); 89 bool findCandidate(const tMatrix &matrix, int &nRow, int &nCol) const; 90 double findMinInCol(int nCol, const tMatrix &matrix, int exr = -1) const; 91 double findMinInRow(int nRow, const tMatrix &matrix, int exc = -1) const; 102 void deleteNode(SStep *node); 103 QList<TCandidate> findCandidate(const TMatrix &matrix, int &nRow, int &nCol) const; 104 double findMinInCol(int nCol, const TMatrix &matrix, int exr = -1) const; 105 double findMinInRow(int nRow, const TMatrix &matrix, int exc = -1) const; 92 106 bool hasSubCycles(int nRow, int nCol) const; 93 void subCol( tMatrix &matrix, int nCol, double val);94 void subRow( tMatrix &matrix, int nRow, double val);107 void subCol(TMatrix &matrix, int nCol, double val); 108 void subRow(TMatrix &matrix, int nRow, double val); 95 109 }; 96 110
Note: See TracChangeset
for help on using the changeset viewer.