Changeset e4ae9e95f7 in tspsg for src
- Timestamp:
- Jan 12, 2010, 4:27:52 PM (15 years ago)
- Branches:
- 0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
- Children:
- 3e46075789
- Parents:
- fcd8c1e4c1
- Location:
- src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/globals.h
rfcd8c1e4c1 re4ae9e95f7 96 96 * \return \c true if \a x countains an integer, oherwise \c false. 97 97 */ 98 inline bool isInteger( qrealx)98 inline bool isInteger(double x) 99 99 { 100 qreali;100 double i; 101 101 return (modf(x, &i) == 0.0); 102 102 } -
src/mainwindow.cpp
rfcd8c1e4c1 re4ae9e95f7 383 383 { 384 384 TMatrix matrix; 385 QList< qreal> row;385 QList<double> row; 386 386 int n = spinCities->value(); 387 387 bool ok; … … 389 389 row.clear(); 390 390 for (int c = 0; c < n; c++) { 391 row.append(tspmodel->index(r,c).data(Qt::UserRole).to Real(&ok));391 row.append(tspmodel->index(r,c).data(Qt::UserRole).toDouble(&ok)); 392 392 if (!ok) { 393 393 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 281 281 for (int c = 0; c < nCities; c++) 282 282 if (r != c) { 283 ds << static_cast<double>(table[r][c]); // We cast to double because qrealmay be float on some platforms and we store double values in file283 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 284 284 if (f.error() != QFile::NoError) { 285 285 f.close(); … … 312 312 else { 313 313 bool ok; 314 qreal tmp = value.toReal(&ok);314 double tmp = value.toDouble(&ok); 315 315 if (!ok || tmp < 0) 316 316 return false; … … 399 399 } 400 400 401 double x; // We need this as qrealmay be float on some platforms and we store double values in file401 double x; // We need this as double may be float on some platforms and we store double values in file 402 402 // Travel costs 403 403 for (int r = 0; r < size; r++) … … 447 447 } 448 448 // Travel costs 449 qrealval;449 double val; 450 450 for (int r = 0; r < 5; r++) 451 451 for (int c = 0; c < 5; c++) … … 469 469 } 470 470 471 inline qrealCTSPModel::rand(int min, int max) const472 { 473 qrealr;471 inline double CTSPModel::rand(int min, int max) const 472 { 473 double r; 474 474 if (settings->value("Task/FractionalRandom", DEF_FRACTIONAL_RANDOM).toBool()) { 475 qrealx = qPow(10, settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt());476 r = ( qreal)qRound((qreal)qrand() / RAND_MAX * (max - min) * x) / x;475 double x = qPow(10, settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()); 476 r = (double)qRound((double)qrand() / RAND_MAX * (max - min) * x) / x; 477 477 } else 478 r = qRound(( qreal)qrand() / RAND_MAX * (max - min));478 r = qRound((double)qrand() / RAND_MAX * (max - min)); 479 479 return min + r; 480 480 } -
src/tspmodel.h
rfcd8c1e4c1 re4ae9e95f7 64 64 private: 65 65 QSettings *settings; 66 QVector<QVector< qreal> > table;66 QVector<QVector<double> > table; 67 67 quint16 nCities; 68 68 bool loadError(QDataStream::Status); 69 69 bool loadTSPT(QDataStream *); 70 70 bool loadZKT(QDataStream *); 71 qrealrand(int, int) const;71 double rand(int, int) const; 72 72 }; 73 73 -
src/tspsolver.cpp
rfcd8c1e4c1 re4ae9e95f7 106 106 int nRow, nCol; 107 107 bool firstStep = true; 108 qrealcheck;108 double check; 109 109 while (this->route.size() < nCities) { 110 110 // forbidden.clear(); … … 188 188 /* Privates **********************************************************/ 189 189 190 qrealCTSPSolver::align(TMatrix &matrix)191 { 192 qrealr = 0;193 qrealmin;190 double CTSPSolver::align(TMatrix &matrix) 191 { 192 double r = 0; 193 double min; 194 194 for (int k = 0; k < nCities; k++) { 195 195 min = findMinInRow(k,matrix); … … 240 240 QList<SCandidate> alts; 241 241 SCandidate cand; 242 qrealh = -1;243 qrealsum;242 double h = -1; 243 double sum; 244 244 for (int r = 0; r < nCities; r++) 245 245 for (int c = 0; c < nCities; c++) … … 261 261 } 262 262 263 qrealCTSPSolver::findMinInCol(int nCol, const TMatrix &matrix, int exr) const264 { 265 qrealmin = INFINITY;263 double CTSPSolver::findMinInCol(int nCol, const TMatrix &matrix, int exr) const 264 { 265 double min = INFINITY; 266 266 for (int k = 0; k < nCities; k++) 267 267 if ((k != exr) && (min > matrix.at(k).at(nCol))) … … 270 270 } 271 271 272 qrealCTSPSolver::findMinInRow(int nRow, const TMatrix &matrix, int exc) const273 { 274 qrealmin = INFINITY;272 double CTSPSolver::findMinInRow(int nRow, const TMatrix &matrix, int exc) const 273 { 274 double min = INFINITY; 275 275 for (int k = 0; k < nCities; k++) 276 276 if (((k != exc)) && (min > matrix.at(nRow).at(k))) … … 293 293 } 294 294 295 void CTSPSolver::subCol(TMatrix &matrix, int nCol, qrealval)295 void CTSPSolver::subCol(TMatrix &matrix, int nCol, double val) 296 296 { 297 297 for (int k = 0; k < nCities; k++) … … 300 300 } 301 301 302 void CTSPSolver::subRow(TMatrix &matrix, int nRow, qrealval)302 void CTSPSolver::subRow(TMatrix &matrix, int nRow, double val) 303 303 { 304 304 for (int k = 0; k < nCities; k++) -
src/tspsolver.h
rfcd8c1e4c1 re4ae9e95f7 34 34 35 35 //! A matrix of city-to-city travel costs. 36 typedef QList<QList< qreal> > TMatrix;36 typedef QList<QList<double> > TMatrix; 37 37 38 38 /*! … … 60 60 struct SStep { 61 61 TMatrix matrix; //!< This step's matrix 62 qrealprice; //!< The price of travel to this step62 double price; //!< The price of travel to this step 63 63 SCandidate candidate; //!< A candiadate for branching in the current matrix 64 64 QList<SCandidate> alts; //!< A list of alternative branching candidates … … 98 98 // QHash<int,int> forbidden; 99 99 100 qrealalign(TMatrix &matrix);100 double align(TMatrix &matrix); 101 101 void cleanup(); 102 102 void deleteNode(SStep *&node); 103 103 QList<SCandidate> findCandidate(const TMatrix &matrix, int &nRow, int &nCol) const; 104 qrealfindMinInCol(int nCol, const TMatrix &matrix, int exr = -1) const;105 qrealfindMinInRow(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; 106 106 bool hasSubCycles(int nRow, int nCol) const; 107 void subCol(TMatrix &matrix, int nCol, qrealval);108 void subRow(TMatrix &matrix, int nRow, qrealval);107 void subCol(TMatrix &matrix, int nCol, double val); 108 void subRow(TMatrix &matrix, int nRow, double val); 109 109 }; 110 110
Note: See TracChangeset
for help on using the changeset viewer.