Ejemplo n.º 1
0
void PertyMatchScorer::_loadPerturbedMap(const QString perturbedMapInputPath,
                                         const QString perturbedMapOutputPath)
{
  LOG_DEBUG("Loading the reference data to be used by the data to be perturbed; " <<
            "renaming REF1 tags to REF2...");

  //load from the modified reference data output to get the added ref1 tags; don't copy the map,
  //since updates to the names of the ref tags on this map will propagate to the map copied from
  shared_ptr<OsmMap> perturbedMap(new OsmMap());
  OsmUtils::loadMap(perturbedMap, perturbedMapInputPath, false, Status::Unknown2);
  //TODO: should this be removed?
  MapCleaner().apply(perturbedMap);

  shared_ptr<TagRenameKeyVisitor> tagRenameKeyVisitor(new TagRenameKeyVisitor("REF1", "REF2"));
  perturbedMap->visitRw(*tagRenameKeyVisitor);
  //TODO: this could eventually be replaced with a SetTagVisitor passed in from the command line
  //instead
  shared_ptr<SetTagVisitor> setAccuracyVisitor(
    new SetTagVisitor("error:circular", QString::number(_searchDistance)));
  perturbedMap->visitRw(*setAccuracyVisitor);
  LOG_VARD(perturbedMap->getNodeMap().size());
  LOG_VARD(perturbedMap->getWays().size());  
  if (Log::getInstance().getLevel() <= Log::Debug)
  {
    TagCountVisitor tagCountVisitor;
    perturbedMap->visitRo(tagCountVisitor);
    const long numTotalTags = (long)tagCountVisitor.getStat();
    LOG_VARD(numTotalTags);
  }

  LOG_DEBUG("Perturbing the copied reference data and saving it to: " << perturbedMapOutputPath);

  PertyOp pertyOp;
  pertyOp.setConfiguration(_settings);
  LOG_DEBUG("Details: " << pertyOp.toString());
  pertyOp.apply(perturbedMap);
  LOG_VARD(perturbedMap->getNodeMap().size());
  LOG_VARD(perturbedMap->getWays().size());
  if (Log::getInstance().getLevel() <= Log::Debug)
  {
    TagCountVisitor tagCountVisitor;
    perturbedMap->visitRo(tagCountVisitor);
    const long numTotalTags = (long)tagCountVisitor.getStat();
    LOG_VARD(numTotalTags);
  }

  MapProjector::projectToWgs84(perturbedMap);
  OsmUtils::saveMap(perturbedMap, perturbedMapOutputPath);
}
Ejemplo n.º 2
0
  void runDirectSequentialSimulationTest()
  {
    shared_ptr<OsmMap> map(new OsmMap());
    OGREnvelope env;
    env.MinX = 0;
    env.MinY = 0;
    env.MaxX = 1;
    env.MaxY = 1;
    map->setProjection(MapProjector::createAeacProjection(env));
    //OsmReader reader;
    //reader.read("test-files/ToyTestA.osm", map);
    // force the map bounds.
    NodePtr n1(new Node(Status::Unknown1, map->createNextNodeId(), 0, 0, 10));
    NodePtr n2(new Node(Status::Unknown1, map->createNextNodeId(), 500, 500, 10));
    map->addNode(n1);
    map->addNode(n2);

    for (double x = 0.0; x <= 500.0; x += 220)
    {
      for (double y = 0.0; y <= 500.0; y += 260)
      {
        NodePtr n(new Node(Status::Unknown1, map->createNextNodeId(), x, y, 10));
        map->addNode(n);
      }
    }

    PertyOp uut;
    uut.setSeed(1);
    uut.setPermuteAlgorithm(QString::fromStdString(DirectSequentialSimulation::className()));
    uut.setCsmParameters(9, 100);
    uut.setNamedOps(QStringList());
    uut.apply(map);

    ////
    // Handy bit for regenerating the test values, _AFTER_ it has been visually verified.
    ////
    QSet<long> nids;
    NodeMap::const_iterator it = map->getNodeMap().begin();
    while (it != map->getNodeMap().end()) {
      nids.insert(it->first);
      it++;
    }
    QList<long> keys = QList<long>::fromSet(nids);
    qSort(keys);

//    OsmWriter writer;
//    QDir().mkpath("test-output/perty");
//    MapProjector::reprojectToWgs84(map);
//    writer.write(map, "test-output/perty/BasicTest.osm");
//    QString result = "";
//    for (int i = 0; i < keys.size(); i++)
//    {
//      const NodePtr& n = map->getNode(keys[i]);
//      result += QString("n = map->getNode(keys[%1]);\n").arg(i);
//      result += QString("CPPUNIT_ASSERT_DOUBLES_EQUAL(%1, n->getX(), 1e-3);\n").arg(n->getX());
//      result += QString("CPPUNIT_ASSERT_DOUBLES_EQUAL(%1, n->getY(), 1e-3);\n").arg(n->getY());
//    }
//    LOG_INFO(result);

    NodePtr n;
    n = map->getNode(keys[0]);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(418.5, n->getX(), 1e-3);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(210.61, n->getY(), 1e-3);
    n = map->getNode(keys[1]);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(417.754, n->getX(), 1e-3);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(-5.31176, n->getY(), 1e-3);
    n = map->getNode(keys[2]);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(203.892, n->getX(), 1e-3);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(179.617, n->getY(), 1e-3);
    n = map->getNode(keys[3]);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(168.138, n->getX(), 1e-3);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(-28.9846, n->getY(), 1e-3);
    n = map->getNode(keys[4]);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(-12.5047, n->getX(), 1e-3);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(257.038, n->getY(), 1e-3);
    n = map->getNode(keys[5]);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(-14.5567, n->getX(), 1e-3);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.34252, n->getY(), 1e-3);
    n = map->getNode(keys[6]);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(534.813, n->getX(), 1e-3);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(475.291, n->getY(), 1e-3);
    n = map->getNode(keys[7]);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(-14.5567, n->getX(), 1e-3);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.34252, n->getY(), 1e-3);
  }
Ejemplo n.º 3
0
  /**
   * Runs a debug version of perty for visualizing the results. Not necessary for normal testing.
   */
  void runDebugTest()
  {
    shared_ptr<OsmMap> map(new OsmMap());
    OGREnvelope env;
    env.MinX = 0;
    env.MinY = 0;
    env.MaxX = 1;
    env.MaxY = 1;
    map->setProjection(MapProjector::createAeacProjection(env));
    //OsmReader reader;
    //reader.read("test-files/ToyTestA.osm", map);
    // force the map bounds.
    NodePtr n1(new Node(Status::Unknown1, map->createNextNodeId(), 0, 0, 10));
    NodePtr n2(new Node(Status::Unknown1, map->createNextNodeId(), 100, 100, 10));
    map->addNode(n1);
    map->addNode(n2);

    double gridSpacing = 2.5;

    for (double x = 0.0; x < 200.0; x += gridSpacing / 4)
    {
      for (double y = 0.0; y < 100.0; y += gridSpacing / 4)
      {
        NodePtr n(new Node(Status::Unknown1, map->createNextNodeId(), x, y, 10));
        //n->setTag("note", QString::number(n->getId()));
        map->addNode(n);
      }
    }

    OsmWriter writer;
    QDir().mkpath("test-output/perty");

    shared_ptr<OsmMap> original(new OsmMap(map));
    MapProjector::projectToWgs84(original);
    writer.write(original, "test-output/perty/Original.osm");

    PertyOp uut;
    uut.setGridSpacing(gridSpacing);
    uut.setRandomError(0.0, 0.0);
    uut.setSeed(1);
    uut.setSystematicError(10.0, 10.0);
    uut.setCsmParameters(9, 10);
    //uut.apply(map);
//    for (int i = 0; i < 100; i++)
//    {
//      shared_ptr<OsmMap> tmp(new OsmMap(map));
//      uut.permute(tmp);
//    }
    //tbs::SampleStats ss(uut._x);
    //LOG_INFO("sd: " << ss.calculateUnbiasedStandardDeviation());
    shared_ptr<OsmMap> debug = uut.generateDebugMap(map);
    //    for (int i = 0; i < 100; i++)
    //    {
    //      shared_ptr<OsmMap> tmp(new OsmMap(map));
    //      uut.permute(tmp);
    //    }
        //tbs::SampleStats ss(uut._x);
        //LOG_INFO("sd: " << ss.calculateUnbiasedStandardDeviation


    MapProjector::projectToWgs84(debug);
    writer.write(debug, "test-output/perty/Debug.osm");
    MapProjector::projectToWgs84(map);
    writer.write(map, "test-output/perty/Permuted.osm");
  }
Ejemplo n.º 4
0
  void runFullCovarianceTest()
  {
    shared_ptr<OsmMap> map(new OsmMap());
    OGREnvelope env;
    env.MinX = 0;
    env.MinY = 0;
    env.MaxX = 1;
    env.MaxY = 1;
    map->setProjection(MapReprojector::createAeacProjection(env));
    //OsmReader reader;
    //reader.read("test-files/ToyTestA.osm", map);
    // force the map bounds.
    NodePtr n1(new Node(Status::Unknown1, map->createNextNodeId(), 0, 0, 10));
    NodePtr n2(new Node(Status::Unknown1, map->createNextNodeId(), 500, 500, 10));
    map->addNode(n1);
    map->addNode(n2);

    for (double x = 0.0; x <= 500.0; x += 220)
    {
      for (double y = 0.0; y <= 500.0; y += 260)
      {
        NodePtr n(new Node(Status::Unknown1, map->createNextNodeId(), x, y, 10));
        map->addNode(n);
      }
    }

    PertyOp uut;
    uut.setSeed(1);
    uut.setCsmParameters(9, 100);
    uut.setPermuteAlgorithm(QString::fromStdString(FullCovariance::className()));
    uut.setNamedOps(QStringList());
    uut.apply(map);

    ////
    // Handy bit for regenerating the test values, _AFTER_ it has been visually verified.
    ////
    QList<long> keys = map->getNodeMap().uniqueKeys();
    qSort(keys);
//    OsmWriter writer;
//    QDir().mkpath("test-output/perty");
//    MapReprojector::reprojectToWgs84(map);
//    writer.write(map, "test-output/perty/BasicTest.osm");
//    QString result = "";
//    for (int i = 0; i < keys.size(); i++)
//    {
//      const NodePtr& n = map->getNode(keys[i]);
//      result += QString("n = map->getNode(keys[%1]);\n").arg(i);
//      result += QString("CPPUNIT_ASSERT_DOUBLES_EQUAL(%1, n->getX(), 1e-3);\n").arg(n->getX());
//      result += QString("CPPUNIT_ASSERT_DOUBLES_EQUAL(%1, n->getY(), 1e-3);\n").arg(n->getY());
//    }
//    LOG_INFO(result);

    NodePtr n;
    n = map->getNode(keys[0]);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(442.786, n->getX(), 1e-3);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(280.686, n->getY(), 1e-3);
    n = map->getNode(keys[1]);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(427.903, n->getX(), 1e-3);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(30.3295, n->getY(), 1e-3);
    n = map->getNode(keys[2]);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(258.949, n->getX(), 1e-3);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(270.03, n->getY(), 1e-3);
    n = map->getNode(keys[3]);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(259.729, n->getX(), 1e-3);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(20.6173, n->getY(), 1e-3);
    n = map->getNode(keys[4]);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(21.9168, n->getX(), 1e-3);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(283.485, n->getY(), 1e-3);
    n = map->getNode(keys[5]);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(-5.71276, n->getX(), 1e-3);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(8.83212, n->getY(), 1e-3);
    n = map->getNode(keys[6]);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(499.789, n->getX(), 1e-3);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(486.422, n->getY(), 1e-3);
    n = map->getNode(keys[7]);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(-5.71276, n->getX(), 1e-3);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(8.83212, n->getY(), 1e-3);
  }