Changeset f1fb54b9f7 in tspsg for src
- Timestamp:
- Jan 7, 2010, 2:24:18 AM (15 years ago)
- Branches:
- 0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
- Children:
- 946f442ab0
- Parents:
- 4ccf855df8
- Location:
- src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/globals.h
r4ccf855df8 rf1fb54b9f7 46 46 //! Default number of cities 47 47 #define DEF_NUM_CITIES 5 48 //! Default value for generating fractional random values 49 #define DEF_FRACTIONAL_RANDOM false 48 50 //! Default value for showing or not solution step matrices 49 51 #define DEF_SHOW_MATRIX true … … 52 54 //! Default maximum number of cities to show solution step matrices 53 55 #define DEF_SHOW_MATRIX_CITY_LIMIT 15 56 //! Default for scrolling to the end of output after solving 57 #define DEF_SCROLL_TO_END true 54 58 //! Default font name 55 59 #define DEF_FONT_FAMILY "Courier New" … … 108 112 #define INFSTR "---" 109 113 114 // FUNCTIONS 115 /*! 116 * \brief Checks whether \a x contains an integer value 117 * \param x A value to check 118 * \return \c true if \a x countains an integer, oherwise \c false 119 */ 120 inline bool isInteger(double x) 121 { 122 double i; 123 return (modf(x, &i) == 0.0); 124 } 125 110 126 // Sanity checks 111 127 // Check that default number of cities is sane (<= MAX_NUM_CITIES) -
src/mainwindow.cpp
r4ccf855df8 rf1fb54b9f7 450 450 output.append("<p>" + trUtf8("Resulting path:") + "</p>"); 451 451 output.append("<p> " + solver.getSortedPath() + "</p>"); 452 output.append("<p>" + trUtf8("The price is <b>%n</b> unit(s).", "", step->price) + "</p>"); 452 if (isInteger(step->price)) 453 output.append("<p>" + trUtf8("The price is <b>%n</b> unit(s).", "", step->price) + "</p>"); 454 else 455 output.append("<p>" + trUtf8("The price is <b>%1</b> units.").arg(step->price, 0, 'f', 2) + "</p>"); 453 456 if (!solver.isOptimal()) { 454 457 output.append("<p> </p>"); … … 460 463 solutionText->setDocumentTitle(trUtf8("Solution of Variant #%1 task").arg(spinVariant->value())); 461 464 462 // Scrolling to the end of text. 463 solutionText->moveCursor(QTextCursor::End); 465 if (settings->value("Output/ScrollToEnd", DEF_SCROLL_TO_END).toBool()) { 466 // Scrolling to the end of text. 467 solutionText->moveCursor(QTextCursor::End); 468 } 464 469 465 470 toggleSolutionActions(); … … 655 660 line += "<td align=\"center\">"INFSTR"</td>"; 656 661 else 657 line += "<td align=\"center\">" + QVariant(matrix.at(r).at(c)).toString() + "</td>";662 line += isInteger(matrix.at(r).at(c)) ? QString("<td align=\"center\">%1</td>").arg(matrix.at(r).at(c)) : QString("<td align=\"center\">%1</td>").arg(matrix.at(r).at(c), 0, 'f', 2); 658 663 } 659 664 line += "</tr>"; … … 674 679 line += "<td align=\"center\">"INFSTR"</td>"; 675 680 else if ((r == step.candidate.nRow) && (c == step.candidate.nCol)) 676 line += "<td align=\"center\" class=\"selected\">" + QVariant(step.matrix.at(r).at(c)).toString() + "</td>";681 line += isInteger(step.matrix.at(r).at(c)) ? QString("<td align=\"center\" class=\"selected\">%1</td>").arg(step.matrix.at(r).at(c)) : QString("<td align=\"center\" class=\"selected\">%1</td>").arg(step.matrix.at(r).at(c), 0, 'f', 2); 677 682 else { 678 683 SCandidate cand; … … 680 685 cand.nCol = c; 681 686 if (step.alts.contains(cand)) 682 line += "<td align=\"center\" class=\"alternate\">" + QVariant(step.matrix.at(r).at(c)).toString() + "</td>";687 line += isInteger(step.matrix.at(r).at(c)) ? QString("<td align=\"center\" class=\"alternate\">%1</td>").arg(step.matrix.at(r).at(c)) : QString("<td align=\"center\" class=\"alternate\">%1</td>").arg(step.matrix.at(r).at(c), 0, 'f', 2); 683 688 else 684 line += "<td align=\"center\">" + QVariant(step.matrix.at(r).at(c)).toString() + "</td>";689 line += isInteger(step.matrix.at(r).at(c)) ? QString("<td align=\"center\">%1</td>").arg(step.matrix.at(r).at(c)) : QString("<td align=\"center\">%1</td>").arg(step.matrix.at(r).at(c), 0, 'f', 2); 685 690 } 686 691 } -
src/settingsdialog.cpp
r4ccf855df8 rf1fb54b9f7 63 63 vbox2->addWidget(groupOutputSettings); 64 64 vbox2->addStretch(); 65 vbox2->addWidget(cbFractionalRandom); 65 66 vbox2->addWidget(cbShowMatrix); 66 67 vbox2->addLayout(layoutCitiesLimit); 68 vbox2->addWidget(cbScrollToEnd); 67 69 vbox2->addWidget(cbAutosize); 68 70 … … 150 152 vbox2->addStretch(); 151 153 vbox2->addLayout(hbox2); 154 vbox2->addWidget(cbFractionalRandom); 152 155 vbox2->addWidget(cbShowMatrix); 153 156 vbox2->addLayout(layoutCitiesLimit); 157 vbox2->addWidget(cbScrollToEnd); 154 158 vbox2->addWidget(cbAutosize); 155 159 vbox2->addWidget(cbSaveState); … … 188 192 spinRandMax->setMaximum(MAX_RAND_VALUE); 189 193 spinRandMax->setValue(settings->value("MaxCost",DEF_RAND_MAX).toInt()); 194 cbFractionalRandom->setChecked(settings->value("FractionalRandom", DEF_FRACTIONAL_RANDOM).toBool()); 190 195 cbAutosize->setChecked(settings->value("Autosize",true).toBool()); 191 196 #ifndef Q_OS_WINCE … … 200 205 spinCitiesLimit->setValue(settings->value("ShowMatrixCitiesLimit", DEF_SHOW_MATRIX_CITY_LIMIT).toInt()); 201 206 spinCitiesLimit->setMaximum(MAX_NUM_CITIES); 207 cbScrollToEnd->setChecked(settings->value("ScrollToEnd", DEF_SCROLL_TO_END).toBool()); 202 208 203 209 font = settings->value("Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>(); … … 236 242 settings->setValue("MinCost", spinRandMin->value()); 237 243 settings->setValue("MaxCost", spinRandMax->value()); 244 settings->setValue("FractionalRandom", cbFractionalRandom->isChecked()); 238 245 239 246 settings->beginGroup("Output"); … … 242 249 if (cbCitiesLimit->isChecked()) 243 250 settings->setValue("ShowMatrixCitiesLimit", spinCitiesLimit->value()); 251 settings->setValue("ScrollToEnd", cbScrollToEnd->isChecked()); 244 252 if (newFont) 245 253 settings->setValue("Font", font); -
src/tspmodel.cpp
r4ccf855df8 rf1fb54b9f7 466 466 } 467 467 468 inline int CTSPModel::rand(int min, int max) const 469 { 470 return min + (int)floor(((double)qrand() / RAND_MAX) * (max + 1 - min)); 471 } 468 inline double CTSPModel::rand(int min, int max) const 469 { 470 double r; 471 if (settings->value("FractionalRandom", DEF_FRACTIONAL_RANDOM).toBool()) 472 r = (double)qRound((double)qrand() / RAND_MAX * (max - min) * 100) / 100; 473 else 474 r = qRound((double)qrand() / RAND_MAX * (max - min)); 475 return min + r; 476 } -
src/tspmodel.h
r4ccf855df8 rf1fb54b9f7 69 69 bool loadTSPT(QDataStream *); 70 70 bool loadZKT(QDataStream *); 71 intrand(int, int) const;71 double rand(int, int) const; 72 72 }; 73 73
Note: See TracChangeset
for help on using the changeset viewer.