- Timestamp:
- Aug 3, 2009, 5:15:46 PM (15 years ago)
- Location:
- trunk/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/globals.h
r42 r50 38 38 #define DEF_RAND_MIN 1 39 39 #define DEF_RAND_MAX 10 40 #define DEF_NUM_CITIES 5 40 41 #define DEF_OFFSET 100 41 42 #define DEF_FONT_FAMILY "Courier New" … … 56 57 #define ZKT_VERSION quint8(1) 57 58 59 // Maximum available number of cities 60 #define MAX_NUM_CITIES 20 58 61 // This value means infinity :-) 59 62 #ifndef INFINITY … … 63 66 #define INFSTR "---" 64 67 68 // Let's check that default number of cities is sane (<= MAX_NUM_CITIES) 69 #if DEF_NUM_CITIES > MAX_NUM_CITIES 70 #undef DEF_NUM_CITIES 71 #define DEF_NUM_CITIES MAX_NUM_CITIES 72 #endif 73 65 74 #endif // GLOBALS_H -
trunk/src/mainwindow.cpp
r47 r50 46 46 actionSettingsLanguageEnglish->setActionGroup(groupSettingsLanguageList); 47 47 loadLangList(); 48 spinCities->set Value(settings->value("NumCities",5).toInt());48 spinCities->setMaximum(MAX_NUM_CITIES); 49 49 actionSettingsLanguageAutodetect->setChecked(settings->value("Language","").toString().isEmpty()); 50 50 connect(actionFileNew,SIGNAL(triggered()),this,SLOT(actionFileNewTriggered())); 51 51 connect(actionFileOpen,SIGNAL(triggered()),this,SLOT(actionFileOpenTriggered())); 52 connect(actionFileSave,SIGNAL(triggered()),this,SLOT(actionFileSaveTriggered())); 52 53 connect(actionFileSaveAsTask,SIGNAL(triggered()),this,SLOT(actionFileSaveAsTaskTriggered())); 53 54 connect(actionFileSaveAsSolution,SIGNAL(triggered()),this,SLOT(actionFileSaveAsSolutionTriggered())); … … 62 63 connect(buttonSolve,SIGNAL(clicked()),this,SLOT(buttonSolveClicked())); 63 64 connect(buttonRandom,SIGNAL(clicked()),this,SLOT(buttonRandomClicked())); 65 connect(buttonBackToTask,SIGNAL(clicked()),this,SLOT(buttonBackToTaskClicked())); 64 66 connect(spinCities,SIGNAL(valueChanged(int)),this,SLOT(spinCitiesValueChanged(int))); 67 setCentralWidget(tabWidget); 65 68 QRect rect = geometry(); 66 setCentralWidget(tabWidget);67 69 #ifndef Q_OS_WINCE 68 70 if (settings->value("SavePos",false).toBool()) { … … 82 84 qsrand(QDateTime().currentDateTime().toTime_t()); 83 85 tspmodel = new CTSPModel(); 84 tspmodel->setNumCities(spinCities->value());85 taskView->setModel(tspmodel);86 86 connect(tspmodel,SIGNAL(numCitiesChanged(int)),this,SLOT(numCitiesChanged(int))); 87 87 connect(tspmodel,SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),this,SLOT(dataChanged())); 88 88 connect(tspmodel,SIGNAL(layoutChanged()),this,SLOT(dataChanged())); 89 if ((QCoreApplication::arguments().count() > 1) && (tspmodel->loadTask(QCoreApplication::arguments().at(1)))) {89 if ((QCoreApplication::arguments().count() > 1) && (tspmodel->loadTask(QCoreApplication::arguments().at(1)))) 90 90 setFileName(QCoreApplication::arguments().at(1)); 91 setWindowModified(false); 92 } else 91 else { 93 92 setFileName(); 94 #ifdef Q_OS_WINCE 93 spinCities->setValue(settings->value("NumCities",DEF_NUM_CITIES).toInt()); 94 } 95 taskView->setModel(tspmodel); 96 setWindowModified(false); 95 97 taskView->resizeColumnsToContents(); 96 98 taskView->resizeRowsToContents(); 97 #endif // Q_OS_WINCE98 99 } 99 100 100 101 void MainWindow::enableSolutionActions(bool enable) 101 102 { 103 buttonSaveSolution->setEnabled(enable); 102 104 actionFileSaveAsSolution->setEnabled(enable); 103 105 solutionText->setEnabled(enable); … … 173 175 void MainWindow::spinCitiesValueChanged(int n) 174 176 { 175 #ifdef Q_OS_WINCE176 177 int count = tspmodel->numCities(); 177 #endif // Q_OS_WINCE178 178 tspmodel->setNumCities(n); 179 #ifdef Q_OS_WINCE180 179 if (n > count) 181 180 for (int k = count; k < n; k++) { … … 183 182 taskView->resizeRowToContents(k); 184 183 } 185 #endif // Q_OS_WINCE186 184 } 187 185 … … 204 202 return; 205 203 tspmodel->clear(); 206 #ifdef Q_OS_WINCE207 204 taskView->resizeColumnsToContents(); 208 205 taskView->resizeRowsToContents(); 209 #endif210 206 setFileName(); 211 207 setWindowModified(false); … … 238 234 } 239 235 setFileName(files.first()); 240 #ifdef Q_OS_WINCE241 236 taskView->resizeColumnsToContents(); 242 237 taskView->resizeRowsToContents(); 243 #endif244 238 tabWidget->setCurrentIndex(0); 245 239 setWindowModified(false); … … 247 241 enableSolutionActions(false); 248 242 QApplication::restoreOverrideCursor(); 243 } 244 245 void MainWindow::actionFileSaveTriggered() 246 { 247 if ((fileName == trUtf8("Untitled") + ".tspt") || (!fileName.endsWith(".tspt",Qt::CaseInsensitive))) 248 saveTask(); 249 else { 250 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); 251 if (tspmodel->saveTask(fileName)) 252 setWindowModified(false); 253 QApplication::restoreOverrideCursor(); 254 } 249 255 } 250 256 … … 350 356 tspmodel->randomize(); 351 357 setWindowModified(true); 352 #ifdef Q_OS_WINCE353 358 taskView->resizeColumnsToContents(); 354 359 taskView->resizeRowsToContents(); 355 #endif // Q_OS_WINCE 360 } 361 362 void MainWindow::buttonBackToTaskClicked() 363 { 364 tabWidget->setCurrentIndex(0); 356 365 } 357 366 … … 395 404 } 396 405 CTSPSolver solver; 397 sStep *root = solver.solve( spinCities->value(),matrix);406 sStep *root = solver.solve(n,matrix,this); 398 407 if (!root) 399 408 return; … … 542 551 void MainWindow::numCitiesChanged(int nCities) 543 552 { 553 blockSignals(true); 544 554 spinCities->setValue(nCities); 545 } 555 blockSignals(false); 556 } -
trunk/src/mainwindow.h
r47 r50 46 46 void actionFileNewTriggered(); 47 47 void actionFileOpenTriggered(); 48 void actionFileSaveTriggered(); 48 49 void actionFileSaveAsTaskTriggered(); 49 50 void actionFileSaveAsSolutionTriggered(); … … 58 59 void buttonSolveClicked(); 59 60 void buttonRandomClicked(); 61 void buttonBackToTaskClicked(); 60 62 void spinCitiesValueChanged(int); 61 63 void numCitiesChanged(int); … … 63 65 private: 64 66 QSettings *settings; 67 #ifndef Q_OS_WINCE 65 68 QPrinter *printer; 69 #endif // Q_OS_WINCE 66 70 CTSPModel *tspmodel; 67 71 QString fileName; -
trunk/src/tspmodel.cpp
r49 r50 206 206 if (loadError(ds->status())) 207 207 return false; 208 // Cities number208 // Number of cities 209 209 quint16 size; 210 210 *ds >> size; 211 211 if (loadError(ds->status())) 212 212 return false; 213 if ( size < 3) {213 if ((size < 3) || (size > MAX_NUM_CITIES)) { 214 214 QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec(); 215 215 return false; 216 216 } 217 if (nCities != size) 217 if (nCities != size) { 218 setNumCities(size); 218 219 emit numCitiesChanged(size); 219 // Costs 220 } 221 // Travel costs 220 222 for (int r = 0; r < size; r++) 221 223 for (int c = 0; c < size; c++) … … 246 248 return false; 247 249 } 248 // Cities number250 // Number of cities 249 251 quint8 size; 250 252 ds->readRawData(reinterpret_cast<char *>(&size),1); … … 255 257 return false; 256 258 } 257 if (nCities != size) 259 if (nCities != size) { 260 setNumCities(size); 258 261 emit numCitiesChanged(size); 259 // Costs 262 } 263 // Travel costs 260 264 double val; 261 265 for (int r = 0; r < 5; r++) -
trunk/src/tspmodel.h
r47 r50 54 54 quint16 nCities; 55 55 bool loadError(QDataStream::Status); 56 bool loadTSPT(QDataStream *); 56 57 bool loadZKT(QDataStream *); 57 bool loadTSPT(QDataStream *);58 58 int rand(int, int) const; 59 59 }; -
trunk/src/tspsolver.cpp
r42 r50 97 97 for (int r = 0; r < nCities; r++) 98 98 for (int c = 0; c < nCities; c++) 99 if ((matrix[r][c] == 0) && !forbidden.values(r).contains(c)) { 99 // if ((matrix[r][c] == 0) && !forbidden.values(r).contains(c)) { 100 if (matrix[r][c] == 0) { 100 101 sum = findMinInRow(r,matrix,c) + findMinInCol(c,matrix,r); 101 102 if (sum > h) { … … 154 155 int nRow, nCol; 155 156 while (route.size() < nCities) { 156 forbidden.clear();157 // forbidden.clear(); 157 158 step->alts = findCandidate(step->matrix,nRow,nCol,s); 158 159 while (hasSubCycles(nRow,nCol)) { 159 forbidden[nRow] = nCol;160 // forbidden[nRow] = nCol; 160 161 step->matrix[nRow][nCol] = INFINITY; 161 162 step->price += align(step->matrix); … … 204 205 } 205 206 206 pd.reset(); 207 if (!root && !pd.wasCanceled()) { 208 pd.reset(); 209 QMessageBox(QMessageBox::Warning,trUtf8("Solution Result"),trUtf8("Unable to find solution.\nMaybe, this task has no solutions."),QMessageBox::Ok,parent).exec(); 210 } 211 207 212 qApp->processEvents(); 208 213 209 if (!root && !pd.wasCanceled()) {210 QMessageBox(QMessageBox::Warning,trUtf8("Solution Result"),trUtf8("This task has no solution."),QMessageBox::Ok,parent).exec();211 }212 213 214 return root; 214 215 } -
trunk/src/tspsolver.h
r46 r50 53 53 sStep *root; 54 54 QHash<int,int> route; 55 QHash<int,int> forbidden;55 // QHash<int,int> forbidden; 56 56 double align(tMatrix &); 57 57 void cleanup(); -
trunk/src/version.h
r45 r50 45 45 #endif // BUILD_NUMBER == 65535 46 46 47 // "Converting" number tostring47 // "Converting" x to quoted string 48 48 #define QUOTE_X(x) #x 49 49 #define QUOTE(x) QUOTE_X(x)
Note: See TracChangeset
for help on using the changeset viewer.