Changeset 149 in tspsg-svn for trunk/src/tspsolver.h
- Timestamp:
- Dec 20, 2010, 9:53:45 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tspsolver.h
r124 r149 40 40 */ 41 41 #ifdef INFINITY 42 #undef INFINITY42 # undef INFINITY 43 43 #endif 44 44 #define INFINITY std::numeric_limits<double>::infinity() … … 60 60 */ 61 61 struct SStep { 62 63 64 65 62 //! A structure that represents a candidate for branching 63 struct SCandidate { 64 int nRow; //!< A zero-based row number of the candidate 65 int nCol; //!< A zero-based column number of the candidate 66 66 67 68 69 70 71 72 73 74 75 67 //! Assigns default values 68 SCandidate() { 69 nCol = nRow = -1; 70 } 71 //! An operator == implementation 72 bool operator ==(const SCandidate &cand) const { 73 return ((cand.nRow == nRow) && (cand.nCol == nCol)); 74 } 75 }; 76 76 77 78 79 80 81 82 77 //! An enum that describes possible selection of the next step 78 enum NextStep { 79 NoNextStep, //!< No next step (end of solution) 80 LeftBranch, //!< Left branch was selected for the next step 81 RightBranch //!< Right branch was selected for the next step 82 }; 83 83 84 85 84 TMatrix matrix; //!< This step's matrix 85 double price; //!< The price of travel to this step 86 86 87 88 89 90 91 92 87 SCandidate candidate; //!< A candiadate for branching in the current step 88 QList<SCandidate> alts; //!< A list of alternative branching candidates 89 SStep *pNode; //!< Pointer to the parent step 90 SStep *plNode; //!< Pointer to the left branch step 91 SStep *prNode; //!< Pointer to the right branch step 92 NextStep next; //!< Indicates what branch was selected for the next step 93 93 94 95 96 97 98 99 94 //! Assigns default values 95 SStep() { 96 price = -1; 97 pNode = plNode = prNode = NULL; 98 next = NoNextStep; 99 } 100 100 }; 101 101 … … 106 106 class CTSPSolver: public QObject 107 107 { 108 108 Q_OBJECT 109 109 110 110 public: 111 111 static QString getVersionId(); 112 112 113 114 115 116 117 118 119 120 121 113 CTSPSolver(QObject *parent = NULL); 114 void cleanup(bool processEvents = false); 115 QString getSortedPath(const QString &city, const QString &separator = QString(" -> ")) const; 116 int getTotalSteps() const; 117 bool isOptimal() const; 118 void setCleanupOnCancel(bool enable = true); 119 SStep *solve(int numCities, const TMatrix &task); 120 bool wasCanceled() const; 121 ~CTSPSolver(); 122 122 123 123 public slots: 124 124 void cancel(); 125 125 126 126 signals: 127 128 129 130 131 127 /*! 128 * \brief This signal is emitted once every time a part of the route is found. 129 * \param n Indicates the number of the route parts found. 130 */ 131 void routePartFound(int n); 132 132 133 133 private: 134 135 136 137 138 134 bool mayNotBeOptimal, canceled, cc; 135 int nCities, total; 136 SStep *root; 137 QHash<int,int> route; 138 mutable QMutex mutex; 139 139 140 141 142 143 144 145 146 147 148 149 150 140 double align(TMatrix &matrix); 141 void deleteTree(SStep *&root, bool processEvents = false); 142 void denormalize(TMatrix &matrix) const; 143 QList<SStep::SCandidate> findCandidate(const TMatrix &matrix, int &nRow, int &nCol) const; 144 double findMinInCol(int nCol, const TMatrix &matrix, int exr = -1) const; 145 double findMinInRow(int nRow, const TMatrix &matrix, int exc = -1) const; 146 void finishRoute(); 147 bool hasSubCycles(int nRow, int nCol) const; 148 void normalize(TMatrix &matrix) const; 149 void subCol(TMatrix &matrix, int nCol, double val); 150 void subRow(TMatrix &matrix, int nRow, double val); 151 151 }; 152 152
Note: See TracChangeset
for help on using the changeset viewer.