Ejemplo n.º 1
0
/**
 * Load the source data up into memory for later conflation.
 */
void Conflator::loadSource(shared_ptr<OsmMap> map)
{
  LOG_INFO("Preprocessing inputs...");

  _map = map;

  if (_debug)
  {
    _saveMap(QString("/tmp/conflated/pre.osm"));
  }

  MapCleaner().apply(_map);

  if (_debug)
  {
    _saveMap(QString("/tmp/conflated/post.osm"));
  }

  setSource(_map);
}
Ejemplo n.º 2
0
shared_ptr<MatchComparator> PertyMatchScorer::_conflateAndScoreMatches(
    shared_ptr<OsmMap> combinedDataToConflate, const QString conflatedMapOutputPath)
{
  LOG_DEBUG("Conflating the reference data with the perturbed data, scoring the matches, and " <<
            "saving the conflated output to: " << conflatedMapOutputPath);

  shared_ptr<MatchComparator> comparator(new MatchComparator());
  //shared_ptr<MatchThreshold> matchThreshold;
  OsmMapPtr conflationCopy(new OsmMap(combinedDataToConflate));

  ConfigOptions configOptions(_settings);
  if (configOptions.getConflateEnableOldRoads())
  {
    // call the old road conflation routine
    Conflator conflator;
    conflator.loadSource(conflationCopy);
    conflator.conflate();
    conflationCopy.reset(new OsmMap(conflator.getBestMap()));
  }

  UnifyingConflator conflator/*(matchThreshold)*/;
  conflator.setConfiguration(_settings);
  conflator.apply(conflationCopy);

  try
  {
    comparator->evaluateMatches(combinedDataToConflate, conflationCopy);
  }
  catch (const HootException& e)
  {
    // save map modifies the map so we want to make sure comparator runs first. 'finally' would be
    // nice.
    _saveMap(conflationCopy, conflatedMapOutputPath);
    throw e;
  }

  _saveMap(conflationCopy, conflatedMapOutputPath);

  return comparator;
}
Ejemplo n.º 3
0
void Conflator::_applyManipulations()
{
  // create the starting working map
  shared_ptr<WorkingMap> start(new WorkingMap(_map));

  if (_debug)
  {
    FileUtils::removeDir("/tmp/conflated");
    QDir().mkpath("/tmp/conflated");
    _saveMap(QString("/tmp/conflated/start.osm"));
  }


  _bestScore = start->getScore();
  _bestMap = start;

  _searchHeap.push(start);

  int iteration = 0;
  int noImprovement = 0;

  double lastPrint = Time::getTime();
  LOG_INFO("Conflating map. Node count: " <<
           _bestMap->getMap()->getNodeMap().size() <<
           " way count: " <<  _bestMap->getMap()->getWays().size());

  shared_ptr<const WorkingMap> map = start;

  QTime t;
  t.start();

  LOG_INFO("Manipulation heap " << _manipulationHeap.size());

  // go through all the manipulators
  while (_manipulationHeap.size() > 0)
  {
    if (Log::getInstance().isInfoEnabled() && Time::getTime() - lastPrint >= 1.0)
    {
      lastPrint = Time::getTime();
      cout << "Current Score: " << map->getScore() << " it: " << iteration << " remaining: " <<
              _manipulationHeap.size() << " elapsed: " << t.elapsed() << "ms             \r";
      cout.flush();
    }

    noImprovement++;

    ManipulationHolder mh = _manipulationHeap.top();
    shared_ptr<const Manipulation> m = mh.m;
    _manipulationHeap.pop();
    // apply the manipulator to our candidate
    if (m->getProbabilityEstimate() > _minValidScore && m->getProbabilityEstimate() == mh.score &&
        m->isValid(map->getMap()))
    {
      set<ElementId> impactedElements;
      set<ElementId> newElements;

      shared_ptr<OsmMap> newMap = map->takeMap();

      m->applyManipulation(newMap, impactedElements, newElements);
      shared_ptr<WorkingMap> newWm(new WorkingMap(newMap));
      newWm->setScore(map->getScore() + m->getScoreEstimate());

      _updateManipulationEstimates(newMap, impactedElements);
      _createManipulations(newMap, newElements);

      if (newWm->getScore() > _bestScore)
      {
        _bestScore = newWm->getScore();
        _bestMap = newWm;
        noImprovement = 0;
      }

      map = newWm;
    }
    else if (_createBogusReviewTags && m->getProbabilityEstimate() == mh.score &&
             m->isValid(map->getMap()))
    {
      shared_ptr<OsmMap> newMap = map->takeMap();
      shared_ptr<WorkingMap> newWm(new WorkingMap(newMap));
      m->addBogusReviewTags(newMap);
      map = newWm;
      _bestMap = newWm;
    }

    if (_debug)
    {
      _saveMap(QString("/tmp/conflated/conf%1.osm").arg(iteration, 3, 10, QChar('0')));
    }

    iteration++;
  }

  if (Log::getInstance().isInfoEnabled())
  {
    cout << endl;
  }

  LOG_INFO("Conflating map. Node count: " <<
           _bestMap->getMap()->getNodeMap().size() <<
           " way count: " <<  _bestMap->getMap()->getWays().size());

  // remove unnecessary fluff before exporting.
  shared_ptr<OsmMap> tmp = _bestMap->takeMap();
  SuperfluousWayRemover::removeWays(tmp);

  LOG_INFO("Conflating map. Node count: " <<
           tmp->getNodeMap().size() <<
           " way count: " <<  tmp->getWays().size());

  _bestMap.reset(new WorkingMap(tmp));
}