forked from organicmaps/organicmaps
Review fixes.
This commit is contained in:
parent
82c7adf6b5
commit
14057a9034
9 changed files with 70 additions and 58 deletions
|
@ -48,9 +48,9 @@ public:
|
|||
{
|
||||
if (isEnter)
|
||||
{
|
||||
std::vector<Segment> const & enters =
|
||||
auto const & enters =
|
||||
GetCrossMwmConnectorWithTransitions(numMwmId).GetEnters();
|
||||
for (Segment const & enter : enters)
|
||||
for (auto const & enter : enters)
|
||||
fn(enter);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
// EdgeEstimator overrides:
|
||||
double CalcSegmentWeight(Segment const & segment, RoadGeometry const & road) const override;
|
||||
double CalcHeuristic(m2::PointD const & from, m2::PointD const & to) const override;
|
||||
double CalcLeapEdgeTime(m2::PointD const & from, m2::PointD const & to) const override;
|
||||
double CalcLeapWeight(m2::PointD const & from, m2::PointD const & to) const override;
|
||||
double GetUTurnPenalty() const override;
|
||||
bool LeapIsAllowed(NumMwmId mwmId) const override;
|
||||
|
||||
|
@ -101,7 +101,7 @@ double CarEdgeEstimator::CalcHeuristic(m2::PointD const & from, m2::PointD const
|
|||
return TimeBetweenSec(from, to, m_maxSpeedMPS);
|
||||
}
|
||||
|
||||
double CarEdgeEstimator::CalcLeapEdgeTime(m2::PointD const & from, m2::PointD const & to) const
|
||||
double CarEdgeEstimator::CalcLeapWeight(m2::PointD const & from, m2::PointD const & to) const
|
||||
{
|
||||
// Let us assume for the time being that
|
||||
// leap edges will be added with a half of max speed.
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
// Note 1. The result of the method should be used if it's necessary to add a leap (fake) edge
|
||||
// (|form|, |to|) in road graph.
|
||||
// Note 2. The result of the method should be less or equal to CalcHeuristic(|form|, |to|).
|
||||
virtual double CalcLeapEdgeTime(m2::PointD const & from, m2::PointD const & to) const = 0;
|
||||
virtual double CalcLeapWeight(m2::PointD const & from, m2::PointD const & to) const = 0;
|
||||
virtual double GetUTurnPenalty() const = 0;
|
||||
// The leap is the shortcut edge from mwm border enter to exit.
|
||||
// Router can't use leaps on some mwms: e.g. mwm with loaded traffic data.
|
||||
|
|
|
@ -90,7 +90,7 @@ void IndexGraphStarter::GetFakeToNormalEdge(FakeVertex const & fakeVertex, bool
|
|||
Segment const segment(fakeVertex.GetMwmId(), fakeVertex.GetFeatureId(),
|
||||
fakeVertex.GetSegmentIdx(), forward);
|
||||
m2::PointD const & pointTo = GetPoint(segment, true /* front */);
|
||||
double const weight = m_graph.GetEstimator().CalcLeapEdgeTime(fakeVertex.GetPoint(), pointTo);
|
||||
double const weight = m_graph.GetEstimator().CalcLeapWeight(fakeVertex.GetPoint(), pointTo);
|
||||
edges.emplace_back(segment, weight);
|
||||
}
|
||||
|
||||
|
@ -102,11 +102,13 @@ void IndexGraphStarter::GetNormalToFakeEdge(Segment const & segment, FakeVertex
|
|||
if (segment.GetMwmId() == fakeVertex.GetMwmId() &&
|
||||
m_graph.GetMode() == WorldGraph::Mode::LeapsOnly)
|
||||
{
|
||||
// It's assumed here that GetEstimator().CalcLeapEdgeTime(p1, p2) ==
|
||||
// GetEstimator().CalcLeapEdgeTime(p2, p1).
|
||||
// It's assumed here that GetEstimator().CalcLeapWeight(p1, p2) ==
|
||||
// GetEstimator().CalcLeapWeight(p2, p1).
|
||||
if (m_graph.IsTransition(segment, isOutgoing))
|
||||
{
|
||||
edges.emplace_back(fakeSegment,
|
||||
m_graph.GetEstimator().CalcLeapEdgeTime(pointFrom, fakeVertex.GetPoint()));
|
||||
m_graph.GetEstimator().CalcLeapWeight(pointFrom, fakeVertex.GetPoint()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -114,7 +116,7 @@ void IndexGraphStarter::GetNormalToFakeEdge(Segment const & segment, FakeVertex
|
|||
return;
|
||||
|
||||
edges.emplace_back(fakeSegment,
|
||||
m_graph.GetEstimator().CalcLeapEdgeTime(pointFrom, fakeVertex.GetPoint()));
|
||||
m_graph.GetEstimator().CalcLeapWeight(pointFrom, fakeVertex.GetPoint()));
|
||||
}
|
||||
|
||||
void IndexGraphStarter::ConnectLeapToTransitions(FakeVertex const & fakeVertex, bool isOutgoing,
|
||||
|
@ -129,19 +131,10 @@ void IndexGraphStarter::ConnectLeapToTransitions(FakeVertex const & fakeVertex,
|
|||
// finish mwm should be connected with the finish point. So |isEnter| below should be set to true.
|
||||
m_graph.ForEachTransition(
|
||||
fakeVertex.GetMwmId(), !isOutgoing /* isEnter */, [&](Segment const & transition) {
|
||||
// It's assumed here that GetEstimator().CalcLeapEdgeTime(p1, p2) ==
|
||||
// GetEstimator().CalcLeapEdgeTime(p2, p1).
|
||||
edges.emplace_back(transition, m_graph.GetEstimator().CalcLeapEdgeTime(
|
||||
segmentPoint, GetPoint(transition, isOutgoing)));
|
||||
// It's assumed here that GetEstimator().CalcLeapWeight(p1, p2) ==
|
||||
// GetEstimator().CalcLeapWeight(p2, p1).
|
||||
edges.emplace_back(transition, m_graph.GetEstimator().CalcLeapWeight(
|
||||
segmentPoint, GetPoint(transition, isOutgoing)));
|
||||
});
|
||||
}
|
||||
|
||||
Segment const & IndexGraphStarter::ConvertSegment(Segment const & segment)
|
||||
{
|
||||
if (segment == kStartFakeSegment)
|
||||
return m_start.GetSegment();
|
||||
if (segment == kFinishFakeSegment)
|
||||
return m_finish.GetSegment();
|
||||
return segment;
|
||||
}
|
||||
} // namespace routing
|
||||
|
|
|
@ -49,11 +49,20 @@ public:
|
|||
m2::PointD const m_point;
|
||||
};
|
||||
|
||||
static uint32_t constexpr kFakeFeatureId = numeric_limits<uint32_t>::max();
|
||||
static uint32_t constexpr kFakeSegmentIdx = numeric_limits<uint32_t>::max();
|
||||
static Segment constexpr kStartFakeSegment =
|
||||
Segment(kFakeNumMwmId, kFakeFeatureId, kFakeSegmentIdx, false);
|
||||
static Segment constexpr kFinishFakeSegment =
|
||||
Segment(kFakeNumMwmId, kFakeFeatureId, kFakeSegmentIdx, true);
|
||||
|
||||
IndexGraphStarter(FakeVertex const & start, FakeVertex const & finish, WorldGraph & graph);
|
||||
|
||||
WorldGraph & GetGraph() { return m_graph; }
|
||||
Segment const & GetStart() const { return kStartFakeSegment; }
|
||||
Segment const & GetFinish() const { return kFinishFakeSegment; }
|
||||
FakeVertex const & GetStartVertex() const { return m_start; }
|
||||
FakeVertex const & GetFinishVertex() const { return m_finish; }
|
||||
m2::PointD const & GetPoint(Segment const & segment, bool front);
|
||||
|
||||
static size_t GetRouteNumPoints(vector<Segment> const & route);
|
||||
|
@ -94,16 +103,7 @@ public:
|
|||
return segment.GetFeatureId() == kFakeFeatureId;
|
||||
}
|
||||
|
||||
Segment const & ConvertSegment(Segment const & segment);
|
||||
|
||||
private:
|
||||
static uint32_t constexpr kFakeFeatureId = numeric_limits<uint32_t>::max();
|
||||
static uint32_t constexpr kFakeSegmentIdx = numeric_limits<uint32_t>::max();
|
||||
static Segment constexpr kStartFakeSegment =
|
||||
Segment(kFakeNumMwmId, kFakeFeatureId, kFakeSegmentIdx, false);
|
||||
static Segment constexpr kFinishFakeSegment =
|
||||
Segment(kFakeNumMwmId, kFakeFeatureId, kFakeSegmentIdx, true);
|
||||
|
||||
void GetFakeToNormalEdges(FakeVertex const & fakeVertex, bool isOutgoing,
|
||||
vector<SegmentEdge> & edges);
|
||||
void GetFakeToNormalEdge(FakeVertex const & fakeVertex, bool forward,
|
||||
|
|
|
@ -134,16 +134,20 @@ IRouter::ResultCode IndexRouter::DoCalculateRoute(string const & startCountry,
|
|||
|
||||
TrafficStash::Guard guard(*m_trafficStash);
|
||||
WorldGraph graph(
|
||||
make_unique<CrossMwmGraph>(m_numMwmIds, m_numMwmTree, m_vehicleModelFactory, m_countryRectFn,
|
||||
m_index, m_indexManager),
|
||||
IndexGraphLoader::Create(m_numMwmIds, m_vehicleModelFactory, m_estimator, m_index),
|
||||
m_estimator);
|
||||
make_unique<CrossMwmGraph>(m_numMwmIds, m_numMwmTree, m_vehicleModelFactory, m_countryRectFn,
|
||||
m_index, m_indexManager),
|
||||
IndexGraphLoader::Create(m_numMwmIds, m_vehicleModelFactory, m_estimator, m_index),
|
||||
m_estimator);
|
||||
|
||||
WorldGraph::Mode mode = WorldGraph::Mode::SingleMwm;
|
||||
if (forSingleMwm)
|
||||
mode = WorldGraph::Mode::SingleMwm;
|
||||
else if (AreMwmsNear(start.GetMwmId(), finish.GetMwmId()))
|
||||
mode = WorldGraph::Mode::LeapsIfPossible;
|
||||
else
|
||||
mode = WorldGraph::Mode::LeapsOnly;
|
||||
graph.SetMode(mode);
|
||||
|
||||
auto const getRoutingMode = [&]() {
|
||||
return AreMwmsNear(start.GetMwmId(), finish.GetMwmId()) ? WorldGraph::Mode::LeapsIfPossible
|
||||
: WorldGraph::Mode::LeapsOnly;
|
||||
};
|
||||
graph.SetMode(forSingleMwm ? WorldGraph::Mode::SingleMwm : getRoutingMode());
|
||||
LOG(LINFO, ("Routing in mode:", graph.GetMode()));
|
||||
|
||||
IndexGraphStarter starter(start, finish, graph);
|
||||
|
@ -248,18 +252,29 @@ IRouter::ResultCode IndexRouter::ProcessLeaps(vector<Segment> const & input,
|
|||
continue;
|
||||
}
|
||||
|
||||
Segment const & convertedCurrent = starter.ConvertSegment(input[i]);
|
||||
++i;
|
||||
CHECK_LESS(i, input.size(), ());
|
||||
Segment const & convertedNext = starter.ConvertSegment(input[i]);
|
||||
CHECK_EQUAL(
|
||||
convertedCurrent.GetMwmId(), convertedNext.GetMwmId(),
|
||||
("Different mwm ids for leap enter and exit, i:", i, "size of input:", input.size()));
|
||||
Segment const & next = input[i];
|
||||
|
||||
CHECK_NOT_EQUAL(current, IndexGraphStarter::kFinishFakeSegment, ());
|
||||
CHECK_NOT_EQUAL(next, IndexGraphStarter::kStartFakeSegment, ());
|
||||
if (current != IndexGraphStarter::kStartFakeSegment &&
|
||||
next != IndexGraphStarter::kFinishFakeSegment)
|
||||
{
|
||||
CHECK_EQUAL(
|
||||
current.GetMwmId(), next.GetMwmId(),
|
||||
("Different mwm ids for leap enter and exit, i:", i, "size of input:", input.size()));
|
||||
}
|
||||
|
||||
IndexGraphStarter::FakeVertex const start =
|
||||
(current == IndexGraphStarter::kStartFakeSegment)
|
||||
? starter.GetStartVertex()
|
||||
: IndexGraphStarter::FakeVertex(current, starter.GetPoint(current, true /* front */));
|
||||
IndexGraphStarter::FakeVertex const finish =
|
||||
(next == IndexGraphStarter::kFinishFakeSegment)
|
||||
? starter.GetFinishVertex()
|
||||
: IndexGraphStarter::FakeVertex(next, starter.GetPoint(next, true /* front */));
|
||||
|
||||
IndexGraphStarter::FakeVertex const start(convertedCurrent,
|
||||
starter.GetPoint(convertedCurrent, true /* front */));
|
||||
IndexGraphStarter::FakeVertex const finish(convertedNext,
|
||||
starter.GetPoint(convertedNext, true /* front */));
|
||||
IndexGraphStarter leapStarter(start, finish, starter.GetGraph());
|
||||
|
||||
// Clear previous loaded graphs.
|
||||
|
|
|
@ -68,8 +68,8 @@ double WeightedEdgeEstimator::CalcHeuristic(m2::PointD const & /* from */,
|
|||
return 0.0;
|
||||
}
|
||||
|
||||
double WeightedEdgeEstimator::CalcLeapEdgeTime(m2::PointD const & /* from */,
|
||||
m2::PointD const & /* to */) const
|
||||
double WeightedEdgeEstimator::CalcLeapWeight(m2::PointD const & /* from */,
|
||||
m2::PointD const & /* to */) const
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
|
|
@ -101,8 +101,8 @@ public:
|
|||
// EdgeEstimator overrides:
|
||||
double CalcSegmentWeight(Segment const & segment, RoadGeometry const & /* road */) const override;
|
||||
double CalcHeuristic(m2::PointD const & /* from */, m2::PointD const & /* to */) const override;
|
||||
double CalcLeapEdgeTime(m2::PointD const & /* from */,
|
||||
m2::PointD const & /* to */) const override;
|
||||
double CalcLeapWeight(m2::PointD const & /* from */,
|
||||
m2::PointD const & /* to */) const override;
|
||||
double GetUTurnPenalty() const override;
|
||||
bool LeapIsAllowed(NumMwmId /* mwmId */) const override;
|
||||
|
||||
|
|
|
@ -19,10 +19,14 @@ class WorldGraph final
|
|||
public:
|
||||
enum class Mode
|
||||
{
|
||||
SingleMwm,
|
||||
LeapsOnly,
|
||||
LeapsIfPossible,
|
||||
NoLeaps,
|
||||
SingleMwm, // Mode for building a route within single mwm.
|
||||
LeapsOnly, // Mode for building a cross mwm route contains of only leaps. In case of start and
|
||||
// finish they (start and finish) will be connected with all transition segments of
|
||||
// their mwm with leap (fake) edges.
|
||||
LeapsIfPossible, // Mode for build cross mwm and single mwm routes. In case of cross mwm route
|
||||
// if they are neighboring mwms the route will be made without leaps.
|
||||
// If not the route is made with leaps for intermediate mwms.
|
||||
NoLeaps, // Mode for building route and getting outgoing/ingoing edges without leaps anyway.
|
||||
};
|
||||
|
||||
WorldGraph(std::unique_ptr<CrossMwmGraph> crossMwmGraph, std::unique_ptr<IndexGraphLoader> loader,
|
||||
|
|
Loading…
Add table
Reference in a new issue