コード例 #1
0
ファイル: tests.cpp プロジェクト: Paulxia/gpx_tools
int main() {

    GpxFile gpx("data/quandry.gpx");

    qDebug() << "Total distance: " << meter2mile(gpx.length()) << " miles";
    qDebug() << "Total duration: " << formatDuration(gpx.duration());
    qDebug() << "Max speed: " << meterPerSecond2MilePerHour(gpx.maxSpeed()) << " mph";
    qDebug() << "Average speed: " << meterPerSecond2MilePerHour(gpx.averageSpeed()) << " mph";

    qDebug() << "\nNumber of segments: " << gpx.segmentCount();

    for (int i=0; i<gpx.segmentCount(); ++i) {
        qDebug() << "Segment " << (i+1) << " has " <<
            gpx[i].pointCount() << " points, "
            "length " << meter2mile(gpx[i].length()) << " miles, "
            "duration " << formatDuration(gpx[i].duration()) <<
            "max speed of " << meterPerSecond2MilePerHour(gpx[i].maxSpeed()) << " mph, "
            "and average speed of " << meterPerSecond2MilePerHour(gpx[i].averageSpeed()) << " mph";
    }

    testBounds();

    testFuncCallOp();

    testMerge();
    qDebug() << "All tests passed.";
    return 0;
}
コード例 #2
0
ファイル: spxshift.cpp プロジェクト: aimanqais/gerardus
/*
    This methods assumes correctly setup vectors |pVec| and |coPvec| and bound
    vectors for leaving simplex. Then it checks all values of |pVec| and
    |coPvec| to obey these bounds and enlarges them if neccessary.
 */
void SPxSolver::shiftPvec()
{
   METHOD( "SPxSolver::shiftPvec()" );

   /* the allowed tolerance is (rep() == ROW) ? feastol() : opttol() because thePvec is the primal vector in ROW and the
    * dual vector in COLUMN representation; this is equivalent to leavetol()
    */
   Random mult(10.0 * leavetol(), 100.0 * leavetol());
   Real allow = leavetol() - epsilon();
   int i, tmp;

   assert(type() == LEAVE);
   assert(allow > 0.0);

   for (i = dim() - 1; i >= 0; --i)
   {
      tmp = !isBasic(coId(i));
      if ((*theCoUbound)[i] + allow <= (*theCoPvec)[i] && tmp)
      {
         if ((*theCoUbound)[i] != (*theCoLbound)[i])
            shiftUCbound(i, (*theCoPvec)[i] + Real(mult));
         else
         {
            shiftUCbound(i, (*theCoPvec)[i]);
            (*theCoLbound)[i] = (*theCoUbound)[i];
         }
      }
      else if ((*theCoLbound)[i] - allow >= (*theCoPvec)[i] && tmp)
      {
         if ((*theCoUbound)[i] != (*theCoLbound)[i])
            shiftLCbound(i, (*theCoPvec)[i] - Real(mult));
         else
         {
            shiftLCbound(i, (*theCoPvec)[i]);
            (*theCoUbound)[i] = (*theCoLbound)[i];
         }
      }
   }

   for (i = coDim() - 1; i >= 0; --i)
   {
      tmp = !isBasic(id(i));
      if ((*theUbound)[i] + allow <= (*thePvec)[i] && tmp)
      {
         if ((*theUbound)[i] != (*theLbound)[i])
            shiftUPbound(i, (*thePvec)[i] + Real(mult));
         else
         {
            shiftUPbound(i, (*thePvec)[i]);
            (*theLbound)[i] = (*theUbound)[i];
         }
      }
      else if ((*theLbound)[i] - allow >= (*thePvec)[i] && tmp)
      {
         if ((*theUbound)[i] != (*theLbound)[i])
            shiftLPbound(i, (*thePvec)[i] - Real(mult));
         else
         {
            shiftLPbound(i, (*thePvec)[i]);
            (*theUbound)[i] = (*theLbound)[i];
         }
      }
   }

#ifndef NDEBUG
   testBounds();
   MSG_DEBUG( spxout << "DSHIFT02 shiftPvec: OK" << std::endl; )
#endif
}
コード例 #3
0
ファイル: connect.cpp プロジェクト: DaveInKentucky/micropolis
/**
 * Perform the command, and fix wire/road/rail/zone connections around it.
 * Store modification in the \a effects object.
 * @param x      X world position to perform the command.
 * @param y      Y world position to perform the command.
 * @param cmd    Command to perform.
 * @param effects Modification collecting object.
 * @return Tool result.
 */
ToolResult Micropolis::connectTile(short x, short y,
                                   ConnectTileCommand cmd, ToolEffects *effects)
{
    ToolResult result = TOOLRESULT_OK;

    // Make sure the array subscripts are in bounds.
    if (!testBounds(x, y)) {
        return TOOLRESULT_FAILED;
    }

    // Perform auto-doze if appropriate.
    switch (cmd) {

        case CONNECT_TILE_ROAD:
        case CONNECT_TILE_RAILROAD:
        case CONNECT_TILE_WIRE:

            // Silently skip auto-bulldoze if no money.
            if (autoBulldoze) {

                MapValue mapVal = effects->getMapValue(x, y);

                if (mapVal & BULLBIT) {
                    mapVal &= LOMASK;
                    mapVal = neutralizeRoad(mapVal);

                    /* Maybe this should check BULLBIT instead of checking tile values? */
                    if ((mapVal >= TINYEXP && mapVal <= LASTTINYEXP) ||
                            (mapVal < HBRIDGE && mapVal != DIRT)) {

                        effects->addCost(1);

                        effects->setMapValue(x, y, DIRT);

                    }
                }
            }
            break;

        default:
            // Do nothing.
            break;

    }

    // Perform the command.
    switch (cmd) {

    case CONNECT_TILE_FIX: // Fix zone.
        fixZone(x, y, effects);
        break;

    case CONNECT_TILE_BULLDOZE: // Bulldoze zone.
        result = layDoze(x, y, effects);
        fixZone(x, y, effects);
        break;

    case CONNECT_TILE_ROAD: // Lay road.
        result = layRoad(x, y, effects);
        fixZone(x, y, effects);
        break;

    case CONNECT_TILE_RAILROAD: // Lay railroad.
        result = layRail(x, y, effects);
        fixZone(x, y, effects);
        break;

    case CONNECT_TILE_WIRE: // Lay wire.
        result = layWire(x, y, effects);
        fixZone(x, y, effects);
        break;

    default:
        NOT_REACHED();
        break;

    }

    return result;
}