Changeset f0464480db in tspsg for src/tspsolver.h


Ignore:
Timestamp:
Dec 16, 2009, 11:22:05 PM (14 years ago)
Author:
Oleksii Serdiuk
Branches:
0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
Children:
0bd0e1aca7
Parents:
53f11f0e6c
Message:

+ CTSPSolver class now deletes all solution tree on cleanup and delete to avoid memory leaks.
+ List of alternate candidates for branching is now saved in every solution step and displayed on output.
+ New struct TCandidate that represents a candidate for branching.

  • Renamed sStep to SStep and tMatrix to TMatrix.
  • Made a better and more readable About window.
  • English translation is now loaded too. This is needed to support plurals (e.g., 1 candidate, 4 candidates).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tspsolver.h

    r53f11f0e6c rf0464480db  
    3434
    3535//! A matrix of city-to-city travel costs.
    36 typedef QList<QList<double> > tMatrix;
     36typedef QList<QList<double> > TMatrix;
     37
     38/*!
     39 * \brief A structure that represents a candidate for branching.
     40 */
     41struct 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};
    3754
    3855/*!
     
    4158 *  A tree of such elements will represent the solving process.
    4259 */
    43 //! \todo TODO: List alternative candidates.
    44 struct sStep {
    45         tMatrix matrix; //!< This step's matrix
     60struct SStep {
     61        TMatrix matrix; //!< This step's matrix
    4662        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
    5467
    5568        //! Assigns default values
    56         sStep() {
    57                 price = candidate.nRow = candidate.nCol = -1;
    58                 alts = false;
     69        SStep() {
     70                price = -1;
    5971                plNode = prNode = NULL;
    6072        }
     
    7688        static QString getVersionId();
    7789        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();
    7992
    8093private:
    8194        bool mayNotBeOptimal;
    8295        int nCities;
    83         sStep *root;
     96        SStep *root;
    8497        QHash<int,int> route;
    8598//      QHash<int,int> forbidden;
    8699
    87         double align(tMatrix &matrix);
     100        double align(TMatrix &matrix);
    88101        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;
    92106        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);
    95109};
    96110
Note: See TracChangeset for help on using the changeset viewer.