Changeset e4ae9e95f7 in tspsg for src


Ignore:
Timestamp:
Jan 12, 2010, 4:27:52 PM (15 years ago)
Author:
Oleksii Serdiuk
Branches:
0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
Children:
3e46075789
Parents:
fcd8c1e4c1
Message:

Back to double to maintain compatibility between platforms.

Location:
src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/globals.h

    rfcd8c1e4c1 re4ae9e95f7  
    9696 * \return \c true if \a x countains an integer, oherwise \c false.
    9797 */
    98 inline bool isInteger(qreal x)
     98inline bool isInteger(double x)
    9999{
    100 qreal i;
     100double i;
    101101        return (modf(x, &i) == 0.0);
    102102}
  • src/mainwindow.cpp

    rfcd8c1e4c1 re4ae9e95f7  
    383383{
    384384TMatrix matrix;
    385 QList<qreal> row;
     385QList<double> row;
    386386int n = spinCities->value();
    387387bool ok;
     
    389389                row.clear();
    390390                for (int c = 0; c < n; c++) {
    391                         row.append(tspmodel->index(r,c).data(Qt::UserRole).toReal(&ok));
     391                        row.append(tspmodel->index(r,c).data(Qt::UserRole).toDouble(&ok));
    392392                        if (!ok) {
    393393                                QMessageBox(QMessageBox::Critical,tr("Data error"),tr("Error in cell [Row %1; Column %2]: Invalid data format.").arg(r + 1).arg(c + 1),QMessageBox::Ok,this).exec();
  • src/tspmodel.cpp

    rfcd8c1e4c1 re4ae9e95f7  
    281281                for (int c = 0; c < nCities; c++)
    282282                        if (r != c) {
    283                                 ds << static_cast<double>(table[r][c]); // We cast to double because qreal may be float on some platforms and we store double values in file
     283                                ds << static_cast<double>(table[r][c]); // We cast to double because double may be float on some platforms and we store double values in file
    284284                                if (f.error() != QFile::NoError) {
    285285                                        f.close();
     
    312312                else {
    313313bool ok;
    314 qreal tmp = value.toReal(&ok);
     314double tmp = value.toDouble(&ok);
    315315                        if (!ok || tmp < 0)
    316316                                return false;
     
    399399        }
    400400
    401 double x; // We need this as qreal may be float on some platforms and we store double values in file
     401double x; // We need this as double may be float on some platforms and we store double values in file
    402402        // Travel costs
    403403        for (int r = 0; r < size; r++)
     
    447447        }
    448448        // Travel costs
    449 qreal val;
     449double val;
    450450        for (int r = 0; r < 5; r++)
    451451                for (int c = 0; c < 5; c++)
     
    469469}
    470470
    471 inline qreal CTSPModel::rand(int min, int max) const
    472 {
    473 qreal r;
     471inline double CTSPModel::rand(int min, int max) const
     472{
     473double r;
    474474        if (settings->value("Task/FractionalRandom", DEF_FRACTIONAL_RANDOM).toBool()) {
    475 qreal x = qPow(10, settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt());
    476                 r = (qreal)qRound((qreal)qrand() / RAND_MAX * (max - min) * x) / x;
     475double x = qPow(10, settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt());
     476                r = (double)qRound((double)qrand() / RAND_MAX * (max - min) * x) / x;
    477477        } else
    478                 r = qRound((qreal)qrand() / RAND_MAX * (max - min));
     478                r = qRound((double)qrand() / RAND_MAX * (max - min));
    479479        return min + r;
    480480}
  • src/tspmodel.h

    rfcd8c1e4c1 re4ae9e95f7  
    6464private:
    6565        QSettings *settings;
    66         QVector<QVector<qreal> > table;
     66        QVector<QVector<double> > table;
    6767        quint16 nCities;
    6868        bool loadError(QDataStream::Status);
    6969        bool loadTSPT(QDataStream *);
    7070        bool loadZKT(QDataStream *);
    71         qreal rand(int, int) const;
     71        double rand(int, int) const;
    7272};
    7373
  • src/tspsolver.cpp

    rfcd8c1e4c1 re4ae9e95f7  
    106106int nRow, nCol;
    107107bool firstStep = true;
    108 qreal check;
     108double check;
    109109        while (this->route.size() < nCities) {
    110110//              forbidden.clear();
     
    188188/* Privates **********************************************************/
    189189
    190 qreal CTSPSolver::align(TMatrix &matrix)
    191 {
    192 qreal r = 0;
    193 qreal min;
     190double CTSPSolver::align(TMatrix &matrix)
     191{
     192double r = 0;
     193double min;
    194194        for (int k = 0; k < nCities; k++) {
    195195                min = findMinInRow(k,matrix);
     
    240240QList<SCandidate> alts;
    241241SCandidate cand;
    242 qreal h = -1;
    243 qreal sum;
     242double h = -1;
     243double sum;
    244244        for (int r = 0; r < nCities; r++)
    245245                for (int c = 0; c < nCities; c++)
     
    261261}
    262262
    263 qreal CTSPSolver::findMinInCol(int nCol, const TMatrix &matrix, int exr) const
    264 {
    265 qreal min = INFINITY;
     263double CTSPSolver::findMinInCol(int nCol, const TMatrix &matrix, int exr) const
     264{
     265double min = INFINITY;
    266266        for (int k = 0; k < nCities; k++)
    267267                if ((k != exr) && (min > matrix.at(k).at(nCol)))
     
    270270}
    271271
    272 qreal CTSPSolver::findMinInRow(int nRow, const TMatrix &matrix, int exc) const
    273 {
    274 qreal min = INFINITY;
     272double CTSPSolver::findMinInRow(int nRow, const TMatrix &matrix, int exc) const
     273{
     274double min = INFINITY;
    275275        for (int k = 0; k < nCities; k++)
    276276                if (((k != exc)) && (min > matrix.at(nRow).at(k)))
     
    293293}
    294294
    295 void CTSPSolver::subCol(TMatrix &matrix, int nCol, qreal val)
     295void CTSPSolver::subCol(TMatrix &matrix, int nCol, double val)
    296296{
    297297        for (int k = 0; k < nCities; k++)
     
    300300}
    301301
    302 void CTSPSolver::subRow(TMatrix &matrix, int nRow, qreal val)
     302void CTSPSolver::subRow(TMatrix &matrix, int nRow, double val)
    303303{
    304304        for (int k = 0; k < nCities; k++)
  • src/tspsolver.h

    rfcd8c1e4c1 re4ae9e95f7  
    3434
    3535//! A matrix of city-to-city travel costs.
    36 typedef QList<QList<qreal> > TMatrix;
     36typedef QList<QList<double> > TMatrix;
    3737
    3838/*!
     
    6060struct SStep {
    6161        TMatrix matrix; //!< This step's matrix
    62         qreal price; //!< The price of travel to this step
     62        double price; //!< The price of travel to this step
    6363        SCandidate candidate; //!< A candiadate for branching in the current matrix
    6464        QList<SCandidate> alts; //!< A list of alternative branching candidates
     
    9898//      QHash<int,int> forbidden;
    9999
    100         qreal align(TMatrix &matrix);
     100        double align(TMatrix &matrix);
    101101        void cleanup();
    102102        void deleteNode(SStep *&node);
    103103        QList<SCandidate> findCandidate(const TMatrix &matrix, int &nRow, int &nCol) const;
    104         qreal findMinInCol(int nCol, const TMatrix &matrix, int exr = -1) const;
    105         qreal findMinInRow(int nRow, const TMatrix &matrix, int exc = -1) 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;
    106106        bool hasSubCycles(int nRow, int nCol) const;
    107         void subCol(TMatrix &matrix, int nCol, qreal val);
    108         void subRow(TMatrix &matrix, int nRow, qreal val);
     107        void subCol(TMatrix &matrix, int nCol, double val);
     108        void subRow(TMatrix &matrix, int nRow, double val);
    109109};
    110110
Note: See TracChangeset for help on using the changeset viewer.