Welcome to mirror list, hosted at ThFree Co, Russian Federation.

waypoints.cpp « routing_quality « routing - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8e657fabb641e1166ee84a75020205db8afe12af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "routing/routing_quality/waypoints.hpp"
#include "routing/routing_quality/utils.hpp"

#include "geometry/mercator.hpp"
#include "geometry/point2d.hpp"

#include "base/assert.hpp"
#include "base/logging.hpp"

#include <algorithm>
#include <utility>

using namespace std;

namespace routing_quality
{
namespace metrics
{
Similarity CompareByNumberOfMatchedWaypoints(routing::FollowedPolyline && polyline, ReferenceRoutes && candidates)
{
  auto constexpr kMaxDistanceFromRouteM = 15;
  Similarity bestResult = 0.0;
  for (size_t j = 0; j < candidates.size(); ++j)
  {
    routing::FollowedPolyline current = polyline;
    auto const & candidate = candidates[j];
    auto const & waypoints = candidate.m_waypoints;
    auto const size = waypoints.size();
    CHECK_GREATER(size, 0, ());
    size_t numberOfErrors = 0;
    for (size_t i = 0; i < size; ++i)
    {
      auto const & ll = waypoints[i];
      m2::RectD const rect = MercatorBounds::MetresToXY(ll.lon, ll.lat, kMaxDistanceFromRouteM /* metresR */);
      auto const iter = current.UpdateProjection(rect);
      if (iter.IsValid())
      {
        auto const distFromRouteM = MercatorBounds::DistanceOnEarth(iter.m_pt, MercatorBounds::FromLatLon(ll));
        if (distFromRouteM <= kMaxDistanceFromRouteM)
          continue;
      }

      LOG(LINFO, ("Can't find point", ll, "with index", i));
      ++numberOfErrors;
    }

    CHECK_LESS_OR_EQUAL(numberOfErrors, size, ());
    auto const result = ((size - numberOfErrors) / static_cast<double>(size)) * candidate.m_factor;
    LOG(LINFO, ("Matching result", result, "for route with index", j));
    bestResult = max(bestResult, result);
  }

  LOG(LINFO, ("Best result", bestResult));
  return bestResult;
}
}  // namespace metrics

Similarity CheckWaypoints(RouteParams && params, ReferenceRoutes && candidates)
{
  return metrics::CompareByNumberOfMatchedWaypoints(GetRouteFollowedPolyline(move(params)), move(candidates));
}

bool CheckRoute(routing::VehicleType type, ms::LatLon const & start, ms::LatLon const & finish,
                vector<Coordinates> && referenceTracks)
{
  RouteParams params;
  params.m_waypoints = {start, finish};
  params.m_type = type;

  ReferenceRoutes candidates(referenceTracks.size());

  for (size_t i = 0; i < candidates.size(); ++i)
    candidates[i].m_waypoints = move(referenceTracks[i]);

  return CheckWaypoints(move(params), move(candidates)) == 1.0;
}

bool CheckCarRoute(ms::LatLon const & start, ms::LatLon const & finish,
                   std::vector<Coordinates> && referenceTracks)
{
  return CheckRoute(routing::VehicleType::Car, start, finish, move(referenceTracks));
}
}  // namespace routing_quality