Changeset f1fb54b9f7 in tspsg for src


Ignore:
Timestamp:
Jan 7, 2010, 2:24:18 AM (14 years ago)
Author:
Oleksii Serdiuk
Branches:
0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
Children:
946f442ab0
Parents:
4ccf855df8
Message:

+ Added the ability to generate fractional random numbers.
+ Added "Scroll to the end of solution output after solving" option.

  • Set the accuracy for fractional numbers on output to 2 decimail places.
  • Updated translations to reflect changes.
Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/globals.h

    r4ccf855df8 rf1fb54b9f7  
    4646//! Default number of cities
    4747#define DEF_NUM_CITIES 5
     48//! Default value for generating fractional random values
     49#define DEF_FRACTIONAL_RANDOM false
    4850//! Default value for showing or not solution step matrices
    4951#define DEF_SHOW_MATRIX true
     
    5254//! Default maximum number of cities to show solution step matrices
    5355#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
    5458//! Default font name
    5559#define DEF_FONT_FAMILY "Courier New"
     
    108112#define INFSTR "---"
    109113
     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 */
     120inline bool isInteger(double x)
     121{
     122double i;
     123        return (modf(x, &i) == 0.0);
     124}
     125
    110126// Sanity checks
    111127// Check that default number of cities is sane (<= MAX_NUM_CITIES)
  • src/mainwindow.cpp

    r4ccf855df8 rf1fb54b9f7  
    450450                output.append("<p>" + trUtf8("Resulting path:") + "</p>");
    451451        output.append("<p>&nbsp;&nbsp;" + 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>");
    453456        if (!solver.isOptimal()) {
    454457                output.append("<p>&nbsp;</p>");
     
    460463        solutionText->setDocumentTitle(trUtf8("Solution of Variant #%1 task").arg(spinVariant->value()));
    461464
    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        }
    464469
    465470        toggleSolutionActions();
     
    655660                                line += "<td align=\"center\">"INFSTR"</td>";
    656661                        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);
    658663                }
    659664                line += "</tr>";
     
    674679                                line += "<td align=\"center\">"INFSTR"</td>";
    675680                        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);
    677682                        else {
    678683SCandidate cand;
     
    680685                                cand.nCol = c;
    681686                                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);
    683688                                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);
    685690                        }
    686691                }
  • src/settingsdialog.cpp

    r4ccf855df8 rf1fb54b9f7  
    6363        vbox2->addWidget(groupOutputSettings);
    6464        vbox2->addStretch();
     65        vbox2->addWidget(cbFractionalRandom);
    6566        vbox2->addWidget(cbShowMatrix);
    6667        vbox2->addLayout(layoutCitiesLimit);
     68        vbox2->addWidget(cbScrollToEnd);
    6769        vbox2->addWidget(cbAutosize);
    6870
     
    150152        vbox2->addStretch();
    151153        vbox2->addLayout(hbox2);
     154        vbox2->addWidget(cbFractionalRandom);
    152155        vbox2->addWidget(cbShowMatrix);
    153156        vbox2->addLayout(layoutCitiesLimit);
     157        vbox2->addWidget(cbScrollToEnd);
    154158        vbox2->addWidget(cbAutosize);
    155159        vbox2->addWidget(cbSaveState);
     
    188192        spinRandMax->setMaximum(MAX_RAND_VALUE);
    189193        spinRandMax->setValue(settings->value("MaxCost",DEF_RAND_MAX).toInt());
     194        cbFractionalRandom->setChecked(settings->value("FractionalRandom", DEF_FRACTIONAL_RANDOM).toBool());
    190195        cbAutosize->setChecked(settings->value("Autosize",true).toBool());
    191196#ifndef Q_OS_WINCE
     
    200205        spinCitiesLimit->setValue(settings->value("ShowMatrixCitiesLimit", DEF_SHOW_MATRIX_CITY_LIMIT).toInt());
    201206        spinCitiesLimit->setMaximum(MAX_NUM_CITIES);
     207        cbScrollToEnd->setChecked(settings->value("ScrollToEnd", DEF_SCROLL_TO_END).toBool());
    202208
    203209        font = settings->value("Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>();
     
    236242        settings->setValue("MinCost", spinRandMin->value());
    237243        settings->setValue("MaxCost", spinRandMax->value());
     244        settings->setValue("FractionalRandom", cbFractionalRandom->isChecked());
    238245
    239246        settings->beginGroup("Output");
     
    242249        if (cbCitiesLimit->isChecked())
    243250                settings->setValue("ShowMatrixCitiesLimit", spinCitiesLimit->value());
     251        settings->setValue("ScrollToEnd", cbScrollToEnd->isChecked());
    244252        if (newFont)
    245253                settings->setValue("Font", font);
  • src/tspmodel.cpp

    r4ccf855df8 rf1fb54b9f7  
    466466}
    467467
    468 inline int CTSPModel::rand(int min, int max) const
    469 {
    470         return min + (int)floor(((double)qrand() / RAND_MAX) * (max + 1 - min));
    471 }
     468inline double CTSPModel::rand(int min, int max) const
     469{
     470double 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  
    6969        bool loadTSPT(QDataStream *);
    7070        bool loadZKT(QDataStream *);
    71         int rand(int, int) const;
     71        double rand(int, int) const;
    7272};
    7373
Note: See TracChangeset for help on using the changeset viewer.