forked from organicmaps/organicmaps
another PR fixes
This commit is contained in:
parent
34ed0224ed
commit
97f1f8ce84
4 changed files with 37 additions and 27 deletions
|
@ -141,20 +141,20 @@ void CrossMwmGraph::GetOutgoingEdgesListImpl(TCrossPair const & v,
|
|||
currentMapping->LoadCrossContext();
|
||||
|
||||
CrossRoutingContextReader const & currentContext = currentMapping->m_crossContext;
|
||||
auto current_in_iterators = currentContext.GetIngoingIterators();
|
||||
auto current_out_iterators = currentContext.GetOutgoingIterators();
|
||||
auto inRange = currentContext.GetIngoingIterators();
|
||||
auto outRange = currentContext.GetOutgoingIterators();
|
||||
|
||||
// Find income node.
|
||||
auto iit = current_in_iterators.first;
|
||||
while (iit != current_in_iterators.second)
|
||||
auto iit = inRange.first;
|
||||
while (iit != inRange.second)
|
||||
{
|
||||
if (iit->m_nodeId == v.second.node)
|
||||
break;
|
||||
++iit;
|
||||
}
|
||||
CHECK(iit != current_in_iterators.second, ());
|
||||
CHECK(iit != inRange.second, ());
|
||||
// Find outs. Generate adjacency list.
|
||||
for (auto oit = current_out_iterators.first; oit != current_out_iterators.second; ++oit)
|
||||
for (auto oit = outRange.first; oit != outRange.second; ++oit)
|
||||
{
|
||||
EdgeWeight const outWeight = currentContext.getAdjacencyCost(iit, oit);
|
||||
if (outWeight != INVALID_CONTEXT_EDGE_WEIGHT && outWeight != 0)
|
||||
|
@ -166,9 +166,10 @@ void CrossMwmGraph::GetOutgoingEdgesListImpl(TCrossPair const & v,
|
|||
}
|
||||
}
|
||||
|
||||
double CrossMwmGraph::HeuristicCostEstimateImpl(const TCrossPair &v, const TCrossPair &w) const
|
||||
double CrossMwmGraph::HeuristicCostEstimateImpl(TCrossPair const & v, TCrossPair const & w) const
|
||||
{
|
||||
return ms::DistanceOnEarth(v.second.point.y, v.second.point.x, w.second.point.y, w.second.point.x) / kMediumSpeedMPS;
|
||||
return ms::DistanceOnEarth(v.second.point.y, v.second.point.x,
|
||||
w.second.point.y, w.second.point.x) / kMediumSpeedMPS;
|
||||
}
|
||||
|
||||
} // namespace routing
|
||||
|
|
|
@ -26,12 +26,12 @@ struct CrossNode
|
|||
inline bool IsValid() const { return node != INVALID_NODE_ID; }
|
||||
};
|
||||
|
||||
bool operator==(CrossNode const & a, CrossNode const & b)
|
||||
inline bool operator==(CrossNode const & a, CrossNode const & b)
|
||||
{
|
||||
return a.node == b.node && a.mwmName == b.mwmName;
|
||||
}
|
||||
|
||||
bool operator<(CrossNode const & a, CrossNode const & b)
|
||||
inline bool operator<(CrossNode const & a, CrossNode const & b)
|
||||
{
|
||||
if (a.node < b.node)
|
||||
return true;
|
||||
|
@ -50,9 +50,9 @@ inline string DebugPrint(CrossNode const & t)
|
|||
/// Representation of border crossing. Contains node on previous map and node on next map.
|
||||
using TCrossPair = pair<CrossNode, CrossNode>;
|
||||
|
||||
bool operator==(TCrossPair const & a, TCrossPair const & b) { return a.first == b.first; }
|
||||
inline bool operator==(TCrossPair const & a, TCrossPair const & b) { return a.first == b.first; }
|
||||
|
||||
bool operator<(TCrossPair const & a, TCrossPair const & b) { return a.first < b.first; }
|
||||
inline bool operator<(TCrossPair const & a, TCrossPair const & b) { return a.first < b.first; }
|
||||
|
||||
inline string DebugPrint(TCrossPair const & t)
|
||||
{
|
||||
|
@ -62,13 +62,15 @@ inline string DebugPrint(TCrossPair const & t)
|
|||
}
|
||||
|
||||
/// A class which represents an cross mwm weighted edge used by CrossMwmGraph.
|
||||
struct CrossWeightedEdge
|
||||
class CrossWeightedEdge
|
||||
{
|
||||
CrossWeightedEdge(TCrossPair const & target, double weight) : target(target), weight(weight) {}
|
||||
public:
|
||||
explicit CrossWeightedEdge(TCrossPair const & target, double weight) : target(target), weight(weight) {}
|
||||
|
||||
inline TCrossPair const & GetTarget() const { return target; }
|
||||
inline double GetWeight() const { return weight; }
|
||||
|
||||
private:
|
||||
TCrossPair target;
|
||||
double weight;
|
||||
};
|
||||
|
@ -77,7 +79,7 @@ struct CrossWeightedEdge
|
|||
class CrossMwmGraph : public Graph<TCrossPair, CrossWeightedEdge, CrossMwmGraph>
|
||||
{
|
||||
public:
|
||||
CrossMwmGraph(RoutingIndexManager & indexManager) : m_indexManager(indexManager) {}
|
||||
explicit CrossMwmGraph(RoutingIndexManager & indexManager) : m_indexManager(indexManager) {}
|
||||
|
||||
IRouter::ResultCode SetStartNode(CrossNode const & startNode);
|
||||
IRouter::ResultCode SetFinalNode(CrossNode const & finalNode);
|
||||
|
|
|
@ -14,15 +14,14 @@ IRouter::ResultCode CalculateRoute(TCrossPair const & startPos, TCrossPair const
|
|||
TAlgorithm m_algo;
|
||||
m_algo.SetGraph(roadGraph);
|
||||
|
||||
TAlgorithm::OnVisitedVertexCallback onVisitedVertexCallback = nullptr;
|
||||
if (nullptr != routingVisualizer)
|
||||
onVisitedVertexCallback = [routingVisualizer](TCrossPair const & cross)
|
||||
TAlgorithm::OnVisitedVertexCallback onVisitedVertex = nullptr;
|
||||
if (routingVisualizer)
|
||||
onVisitedVertex = [&routingVisualizer](TCrossPair const & cross)
|
||||
{
|
||||
routingVisualizer(cross.first.point);
|
||||
};
|
||||
|
||||
TAlgorithm::Result const result =
|
||||
m_algo.FindPath(startPos, finalPos, route, onVisitedVertexCallback);
|
||||
TAlgorithm::Result const result =m_algo.FindPath(startPos, finalPos, route, onVisitedVertex);
|
||||
switch (result)
|
||||
{
|
||||
case TAlgorithm::Result::OK:
|
||||
|
@ -47,6 +46,8 @@ IRouter::ResultCode CalculateCrossMwmPath(TRoutingNodes const & startGraphNodes,
|
|||
FeatureGraphNode startGraphNode, finalGraphNode;
|
||||
CrossNode startNode, finalNode;
|
||||
IRouter::ResultCode code;
|
||||
|
||||
// Finding start node.
|
||||
for (FeatureGraphNode const & start : startGraphNodes)
|
||||
{
|
||||
startNode = CrossNode(start.node.forward_node_id, start.mwmName, start.segmentPoint);
|
||||
|
@ -59,6 +60,8 @@ IRouter::ResultCode CalculateCrossMwmPath(TRoutingNodes const & startGraphNodes,
|
|||
}
|
||||
if (code != IRouter::NoError)
|
||||
return IRouter::StartPointNotFound;
|
||||
|
||||
// Finding final node.
|
||||
for (FeatureGraphNode const & final : finalGraphNodes)
|
||||
{
|
||||
finalNode = CrossNode(final.node.reverse_node_id, final.mwmName, final.segmentPoint);
|
||||
|
@ -71,24 +74,28 @@ IRouter::ResultCode CalculateCrossMwmPath(TRoutingNodes const & startGraphNodes,
|
|||
}
|
||||
if (code != IRouter::NoError)
|
||||
return IRouter::EndPointNotFound;
|
||||
|
||||
// Finding path through maps.
|
||||
vector<TCrossPair> tempRoad;
|
||||
code = CalculateRoute({startNode, startNode}, {finalNode, finalNode}, roadGraph, tempRoad,
|
||||
routingVisualizer);
|
||||
if (code != IRouter::NoError)
|
||||
return code;
|
||||
|
||||
// Final path conversion to output type.
|
||||
for (size_t i = 0; i < tempRoad.size() - 1; ++i)
|
||||
{
|
||||
route.emplace_back(tempRoad[i].second.node, tempRoad[i + 1].first.node,
|
||||
tempRoad[i].second.mwmName);
|
||||
}
|
||||
|
||||
if (!route.empty())
|
||||
{
|
||||
route.front().startNode = startGraphNode;
|
||||
route.back().finalNode = finalGraphNode;
|
||||
return IRouter::NoError;
|
||||
}
|
||||
else
|
||||
return IRouter::RouteNotFound;
|
||||
return IRouter::NoError;
|
||||
return IRouter::RouteNotFound;
|
||||
}
|
||||
|
||||
} // namespace routing
|
||||
|
|
|
@ -15,6 +15,8 @@ INCLUDEPATH += $$ROOT_DIR/3party/jansson/src \
|
|||
SOURCES += \
|
||||
astar_router.cpp \
|
||||
async_router.cpp \
|
||||
cross_mwm_road_graph.cpp \
|
||||
cross_mwm_router.cpp \
|
||||
cross_routing_context.cpp \
|
||||
features_road_graph.cpp \
|
||||
nearest_edge_finder.cpp \
|
||||
|
@ -30,14 +32,14 @@ SOURCES += \
|
|||
turns.cpp \
|
||||
turns_generator.cpp \
|
||||
vehicle_model.cpp \
|
||||
cross_mwm_router.cpp \
|
||||
cross_mwm_road_graph.cpp
|
||||
|
||||
HEADERS += \
|
||||
astar_router.hpp \
|
||||
async_router.hpp \
|
||||
base/astar_algorithm.hpp \
|
||||
base/graph.hpp \
|
||||
cross_mwm_road_graph.hpp \
|
||||
cross_mwm_router.hpp \
|
||||
cross_routing_context.hpp \
|
||||
features_road_graph.hpp \
|
||||
nearest_edge_finder.hpp \
|
||||
|
@ -55,5 +57,3 @@ HEADERS += \
|
|||
turns.hpp \
|
||||
turns_generator.hpp \
|
||||
vehicle_model.hpp \
|
||||
cross_mwm_router.hpp \
|
||||
cross_mwm_road_graph.hpp
|
||||
|
|
Loading…
Add table
Reference in a new issue