forked from organicmaps/organicmaps
More PR fixes
This commit is contained in:
parent
97f1f8ce84
commit
dfe5819a6b
9 changed files with 57 additions and 53 deletions
|
@ -123,7 +123,7 @@ void FindCrossNodes(osrm::NodeDataVectorT const & nodeData, gen::OsmID2FeatureID
|
|||
// for old format compatibility
|
||||
intersection = m2::PointD(MercatorBounds::XToLon(intersection.x), MercatorBounds::YToLat(intersection.y));
|
||||
if (!outStart && outEnd)
|
||||
crossContext.addIngoingNode(nodeId, intersection);
|
||||
crossContext.AddIngoingNode(nodeId, intersection);
|
||||
else if (outStart && !outEnd)
|
||||
{
|
||||
string mwmName;
|
||||
|
@ -140,7 +140,7 @@ void FindCrossNodes(osrm::NodeDataVectorT const & nodeData, gen::OsmID2FeatureID
|
|||
});
|
||||
});
|
||||
if (!mwmName.empty())
|
||||
crossContext.addOutgoingNode(nodeId, mwmName, intersection);
|
||||
crossContext.AddOutgoingNode(nodeId, mwmName, intersection);
|
||||
else
|
||||
LOG(LINFO, ("Unknowing outgoing edge", endSeg.lat2, endSeg.lon2, startSeg.lat1, startSeg.lon1));
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ void CalculateCrossAdjacency(string const & mwmRoutingPath, routing::CrossRoutin
|
|||
FilesMappingContainer routingCont(mwmRoutingPath);
|
||||
facade.Load(routingCont);
|
||||
LOG(LINFO, ("Calculating weight map between outgoing nodes"));
|
||||
crossContext.reserveAdjacencyMatrix();
|
||||
crossContext.ReserveAdjacencyMatrix();
|
||||
auto const & in = crossContext.GetIngoingIterators();
|
||||
auto const & out = crossContext.GetOutgoingIterators();
|
||||
TRoutingNodes sources, targets;
|
||||
|
@ -166,10 +166,10 @@ void CalculateCrossAdjacency(string const & mwmRoutingPath, routing::CrossRoutin
|
|||
// Fill sources and targets with start node task for ingoing (true) and target node task
|
||||
// (false) for outgoing nodes
|
||||
for (auto i = in.first; i != in.second; ++i)
|
||||
sources.emplace_back(i->m_nodeId, true, mwmRoutingPath);
|
||||
sources.emplace_back(i->m_nodeId, true /* isStartNode */, mwmRoutingPath);
|
||||
|
||||
for (auto i = out.first; i != out.second; ++i)
|
||||
targets.emplace_back(i->m_nodeId, false, mwmRoutingPath);
|
||||
targets.emplace_back(i->m_nodeId, false /* isStartNode */, mwmRoutingPath);
|
||||
|
||||
vector<EdgeWeight> costs;
|
||||
FindWeightsMatrix(sources, targets, facade, costs);
|
||||
|
@ -179,7 +179,7 @@ void CalculateCrossAdjacency(string const & mwmRoutingPath, routing::CrossRoutin
|
|||
{
|
||||
EdgeWeight const & edgeWeigth = *(res++);
|
||||
if (edgeWeigth != INVALID_EDGE_WEIGHT && edgeWeigth > 0)
|
||||
crossContext.setAdjacencyCost(i, j, edgeWeigth);
|
||||
crossContext.SetAdjacencyCost(i, j, edgeWeigth);
|
||||
}
|
||||
LOG(LINFO, ("Calculation of weight map between outgoing nodes DONE"));
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
namespace
|
||||
{
|
||||
inline bool IsValidEdgeWeight(EdgeWeight const & w) { return w != INVALID_EDGE_WEIGHT; }
|
||||
double const kMwmCrossingNodeEqualityRadiusMeters = 1000.0;
|
||||
|
||||
double constexpr kMwmCrossingNodeEqualityRadiusMeters = 1000.0;
|
||||
double constexpr kMediumSpeedMPS = 120.0 * 1000.0 / (60 * 60);
|
||||
}
|
||||
|
||||
|
@ -13,21 +14,21 @@ namespace routing
|
|||
{
|
||||
IRouter::ResultCode CrossMwmGraph::SetStartNode(CrossNode const & startNode)
|
||||
{
|
||||
ASSERT(startNode.mwmName.length(), ());
|
||||
// TODO make cancellation
|
||||
ASSERT(!startNode.mwmName.empty(), ());
|
||||
// TODO (ldragunov) make cancellation if necessary
|
||||
TRoutingMappingPtr startMapping = m_indexManager.GetMappingByName(startNode.mwmName);
|
||||
MappingGuard startMappingGuard(startMapping);
|
||||
UNUSED_VALUE(startMappingGuard);
|
||||
startMapping->LoadCrossContext();
|
||||
|
||||
// Load source data
|
||||
// Load source data.
|
||||
auto const mwmOutsIter = startMapping->m_crossContext.GetOutgoingIterators();
|
||||
// Generate routing task from one source to several targets
|
||||
// Generate routing task from one source to several targets.
|
||||
TRoutingNodes sources(1), targets;
|
||||
size_t const outSize = distance(mwmOutsIter.first, mwmOutsIter.second);
|
||||
targets.reserve(outSize);
|
||||
|
||||
// If there is no routes outside source map
|
||||
// If there is no routes outside source map.
|
||||
if (!outSize)
|
||||
return IRouter::RouteNotFound;
|
||||
|
||||
|
@ -62,14 +63,14 @@ IRouter::ResultCode CrossMwmGraph::SetFinalNode(CrossNode const & finalNode)
|
|||
UNUSED_VALUE(finalMappingGuard);
|
||||
finalMapping->LoadCrossContext();
|
||||
|
||||
// Load source data
|
||||
// Load source data.
|
||||
auto const mwmIngoingIter = finalMapping->m_crossContext.GetIngoingIterators();
|
||||
// Generate routing task from one source to several targets
|
||||
// Generate routing task from one source to several targets.
|
||||
TRoutingNodes sources, targets(1);
|
||||
size_t const ingoingSize = distance(mwmIngoingIter.first, mwmIngoingIter.second);
|
||||
sources.reserve(ingoingSize);
|
||||
|
||||
// If there is no routes inside target map
|
||||
// If there is no routes inside target map.
|
||||
if (!ingoingSize)
|
||||
return IRouter::RouteNotFound;
|
||||
|
||||
|
@ -101,10 +102,10 @@ TCrossPair CrossMwmGraph::FindNextMwmNode(OutgoingCrossNode const & startNode,
|
|||
{
|
||||
m2::PointD const & startPoint = startNode.m_point;
|
||||
|
||||
string const & nextMwm = currentMapping->m_crossContext.getOutgoingMwmName(startNode);
|
||||
string const & nextMwm = currentMapping->m_crossContext.GetOutgoingMwmName(startNode);
|
||||
TRoutingMappingPtr nextMapping;
|
||||
nextMapping = m_indexManager.GetMappingByName(nextMwm);
|
||||
// If we haven't this routing file, we skip this path
|
||||
// If we haven't this routing file, we skip this path.
|
||||
if (!nextMapping->IsValid())
|
||||
return TCrossPair();
|
||||
nextMapping->LoadCrossContext();
|
||||
|
@ -126,7 +127,7 @@ TCrossPair CrossMwmGraph::FindNextMwmNode(OutgoingCrossNode const & startNode,
|
|||
void CrossMwmGraph::GetOutgoingEdgesListImpl(TCrossPair const & v,
|
||||
vector<CrossWeightedEdge> & adj) const
|
||||
{
|
||||
// Check for virtual edges
|
||||
// Check for virtual edges.
|
||||
adj.clear();
|
||||
auto const it = m_virtualEdges.find(v.second);
|
||||
if (it != m_virtualEdges.end())
|
||||
|
@ -156,7 +157,7 @@ void CrossMwmGraph::GetOutgoingEdgesListImpl(TCrossPair const & v,
|
|||
// Find outs. Generate adjacency list.
|
||||
for (auto oit = outRange.first; oit != outRange.second; ++oit)
|
||||
{
|
||||
EdgeWeight const outWeight = currentContext.getAdjacencyCost(iit, oit);
|
||||
EdgeWeight const outWeight = currentContext.GetAdjacencyCost(iit, oit);
|
||||
if (outWeight != INVALID_CONTEXT_EDGE_WEIGHT && outWeight != 0)
|
||||
{
|
||||
TCrossPair target = FindNextMwmNode(*oit, currentMapping);
|
||||
|
|
|
@ -75,7 +75,7 @@ private:
|
|||
double weight;
|
||||
};
|
||||
|
||||
/// A graph representation for cross mwm routing
|
||||
/// A graph used for cross mwm routing.
|
||||
class CrossMwmGraph : public Graph<TCrossPair, CrossWeightedEdge, CrossMwmGraph>
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -16,10 +16,12 @@ IRouter::ResultCode CalculateRoute(TCrossPair const & startPos, TCrossPair const
|
|||
|
||||
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, onVisitedVertex);
|
||||
switch (result)
|
||||
|
@ -45,7 +47,7 @@ IRouter::ResultCode CalculateCrossMwmPath(TRoutingNodes const & startGraphNodes,
|
|||
CrossMwmGraph roadGraph(indexManager);
|
||||
FeatureGraphNode startGraphNode, finalGraphNode;
|
||||
CrossNode startNode, finalNode;
|
||||
IRouter::ResultCode code;
|
||||
IRouter::ResultCode code = IRouter::StartPointNotFound;
|
||||
|
||||
// Finding start node.
|
||||
for (FeatureGraphNode const & start : startGraphNodes)
|
||||
|
@ -62,6 +64,7 @@ IRouter::ResultCode CalculateCrossMwmPath(TRoutingNodes const & startGraphNodes,
|
|||
return IRouter::StartPointNotFound;
|
||||
|
||||
// Finding final node.
|
||||
code = IRouter::EndPointNotFound;
|
||||
for (FeatureGraphNode const & final : finalGraphNodes)
|
||||
{
|
||||
finalNode = CrossNode(final.node.reverse_node_id, final.mwmName, final.segmentPoint);
|
||||
|
|
|
@ -33,12 +33,12 @@ using TCheckedPath = vector<RoutePathCross>;
|
|||
* \param route Storage for the result records about crossing maps.
|
||||
* \param indexManager Manager for getting indexes of new countries.
|
||||
* \param RoutingVisualizerFn Debug visualization function.
|
||||
* \return Standart routing result code. NoError if the path exists, error code otherwise.
|
||||
* \return NoError if the path exists, error code otherwise.
|
||||
*/
|
||||
IRouter::ResultCode CalculateCrossMwmPath(TRoutingNodes const & startGraphNodes,
|
||||
TRoutingNodes const & finalGraphNodes,
|
||||
RoutingIndexManager & indexManager,
|
||||
RoutingVisualizerFn const & RoutingVisualizerFn,
|
||||
RoutingVisualizerFn const & routingVisualizer,
|
||||
TCheckedPath & route);
|
||||
|
||||
} // namespace routing
|
||||
|
|
|
@ -91,7 +91,7 @@ void CrossRoutingContextReader::Load(Reader const & r)
|
|||
}
|
||||
}
|
||||
|
||||
const string & CrossRoutingContextReader::getOutgoingMwmName(
|
||||
const string & CrossRoutingContextReader::GetOutgoingMwmName(
|
||||
OutgoingCrossNode const & outgoingNode) const
|
||||
{
|
||||
ASSERT(outgoingNode.m_outgoingIndex < m_neighborMwmList.size(),
|
||||
|
@ -110,7 +110,7 @@ pair<OutgoingEdgeIteratorT, OutgoingEdgeIteratorT> CrossRoutingContextReader::Ge
|
|||
return make_pair(m_outgoingNodes.cbegin(), m_outgoingNodes.cend());
|
||||
}
|
||||
|
||||
WritedEdgeWeightT CrossRoutingContextReader::getAdjacencyCost(IngoingEdgeIteratorT ingoing, OutgoingEdgeIteratorT outgoing) const
|
||||
WritedEdgeWeightT CrossRoutingContextReader::GetAdjacencyCost(IngoingEdgeIteratorT ingoing, OutgoingEdgeIteratorT outgoing) const
|
||||
{
|
||||
if (!mp_reader)
|
||||
return INVALID_CONTEXT_EDGE_WEIGHT;
|
||||
|
@ -154,12 +154,12 @@ void CrossRoutingContextWriter::Save(Writer & w) const
|
|||
}
|
||||
}
|
||||
|
||||
void CrossRoutingContextWriter::addIngoingNode(size_t const nodeId, m2::PointD const & point)
|
||||
void CrossRoutingContextWriter::AddIngoingNode(size_t const nodeId, m2::PointD const & point)
|
||||
{
|
||||
m_ingoingNodes.push_back(IngoingCrossNode(nodeId, point));
|
||||
}
|
||||
|
||||
void CrossRoutingContextWriter::addOutgoingNode(size_t const nodeId, string const & targetMwm, m2::PointD const & point)
|
||||
void CrossRoutingContextWriter::AddOutgoingNode(size_t const nodeId, string const & targetMwm, m2::PointD const & point)
|
||||
{
|
||||
auto it = find(m_neighborMwmList.begin(), m_neighborMwmList.end(), targetMwm);
|
||||
if (it == m_neighborMwmList.end())
|
||||
|
@ -167,12 +167,12 @@ void CrossRoutingContextWriter::addOutgoingNode(size_t const nodeId, string cons
|
|||
m_outgoingNodes.push_back(OutgoingCrossNode(nodeId, distance(m_neighborMwmList.begin(), it), point));
|
||||
}
|
||||
|
||||
void CrossRoutingContextWriter::reserveAdjacencyMatrix()
|
||||
void CrossRoutingContextWriter::ReserveAdjacencyMatrix()
|
||||
{
|
||||
m_adjacencyMatrix.resize(m_ingoingNodes.size() * m_outgoingNodes.size(), INVALID_CONTEXT_EDGE_WEIGHT);
|
||||
}
|
||||
|
||||
void CrossRoutingContextWriter::setAdjacencyCost(IngoingEdgeIteratorT ingoing, OutgoingEdgeIteratorT outgoin, WritedEdgeWeightT value)
|
||||
void CrossRoutingContextWriter::SetAdjacencyCost(IngoingEdgeIteratorT ingoing, OutgoingEdgeIteratorT outgoin, WritedEdgeWeightT value)
|
||||
{
|
||||
m_adjacencyMatrix[GetIndexInAdjMatrix(ingoing, outgoin)] = value;
|
||||
}
|
||||
|
|
|
@ -58,13 +58,13 @@ class CrossRoutingContextReader
|
|||
public:
|
||||
void Load(Reader const & r);
|
||||
|
||||
const string & getOutgoingMwmName(OutgoingCrossNode const & mwmIndex) const;
|
||||
const string & GetOutgoingMwmName(OutgoingCrossNode const & mwmIndex) const;
|
||||
|
||||
pair<IngoingEdgeIteratorT, IngoingEdgeIteratorT> GetIngoingIterators() const;
|
||||
|
||||
pair<OutgoingEdgeIteratorT, OutgoingEdgeIteratorT> GetOutgoingIterators() const;
|
||||
|
||||
WritedEdgeWeightT getAdjacencyCost(IngoingEdgeIteratorT ingoing, OutgoingEdgeIteratorT outgoing) const;
|
||||
WritedEdgeWeightT GetAdjacencyCost(IngoingEdgeIteratorT ingoing, OutgoingEdgeIteratorT outgoing) const;
|
||||
};
|
||||
|
||||
/// Helper class to generate cross context section in mwm.routing file
|
||||
|
@ -80,13 +80,13 @@ class CrossRoutingContextWriter
|
|||
public:
|
||||
void Save(Writer & w) const;
|
||||
|
||||
void addIngoingNode(size_t const nodeId, m2::PointD const & point);
|
||||
void AddIngoingNode(size_t const nodeId, m2::PointD const & point);
|
||||
|
||||
void addOutgoingNode(size_t const nodeId, string const & targetMwm, m2::PointD const & point);
|
||||
void AddOutgoingNode(size_t const nodeId, string const & targetMwm, m2::PointD const & point);
|
||||
|
||||
void reserveAdjacencyMatrix();
|
||||
void ReserveAdjacencyMatrix();
|
||||
|
||||
void setAdjacencyCost(IngoingEdgeIteratorT ingoing, OutgoingEdgeIteratorT outgoin, WritedEdgeWeightT value);
|
||||
void SetAdjacencyCost(IngoingEdgeIteratorT ingoing, OutgoingEdgeIteratorT outgoin, WritedEdgeWeightT value);
|
||||
|
||||
pair<IngoingEdgeIteratorT, IngoingEdgeIteratorT> GetIngoingIterators() const;
|
||||
|
||||
|
|
|
@ -509,7 +509,7 @@ OsrmRouter::ResultCode OsrmRouter::CalculateRoute(m2::PointD const & startPoint,
|
|||
startMapping->LoadCrossContext();
|
||||
auto out_iterators = startMapping->m_crossContext.GetOutgoingIterators();
|
||||
for (auto i = out_iterators.first; i != out_iterators.second; ++i)
|
||||
if (startMapping->m_crossContext.getOutgoingMwmName(*i) == targetMapping->GetName())
|
||||
if (startMapping->m_crossContext.GetOutgoingMwmName(*i) == targetMapping->GetName())
|
||||
{
|
||||
route.AddAbsentCountry(targetMapping->GetName());
|
||||
return targetMapping->GetError();
|
||||
|
|
|
@ -12,11 +12,11 @@ UNIT_TEST(TestContextSerialization)
|
|||
routing::CrossRoutingContextWriter context;
|
||||
routing::CrossRoutingContextReader newContext;
|
||||
|
||||
context.addIngoingNode(1, m2::PointD::Zero());
|
||||
context.addIngoingNode(2, m2::PointD::Zero());
|
||||
context.addOutgoingNode(3, "foo", m2::PointD::Zero());
|
||||
context.addOutgoingNode(4, "bar", m2::PointD::Zero());
|
||||
context.reserveAdjacencyMatrix();
|
||||
context.AddIngoingNode(1, m2::PointD::Zero());
|
||||
context.AddIngoingNode(2, m2::PointD::Zero());
|
||||
context.AddOutgoingNode(3, "foo", m2::PointD::Zero());
|
||||
context.AddOutgoingNode(4, "bar", m2::PointD::Zero());
|
||||
context.ReserveAdjacencyMatrix();
|
||||
|
||||
vector<char> buffer;
|
||||
MemWriter<vector<char> > writer(buffer);
|
||||
|
@ -33,10 +33,10 @@ UNIT_TEST(TestContextSerialization)
|
|||
auto outs = newContext.GetOutgoingIterators();
|
||||
TEST_EQUAL(distance(outs.first,outs.second), 2, ());
|
||||
TEST_EQUAL(outs.first->m_nodeId, 3, ());
|
||||
TEST_EQUAL(newContext.getOutgoingMwmName(*outs.first), string("foo"), ());
|
||||
TEST_EQUAL(newContext.GetOutgoingMwmName(*outs.first), string("foo"), ());
|
||||
++outs.first;
|
||||
TEST_EQUAL(outs.first->m_nodeId, 4, ());
|
||||
TEST_EQUAL(newContext.getOutgoingMwmName(*outs.first), string("bar"), ());
|
||||
TEST_EQUAL(newContext.GetOutgoingMwmName(*outs.first), string("bar"), ());
|
||||
}
|
||||
|
||||
UNIT_TEST(TestAdjacencyMatrix)
|
||||
|
@ -44,16 +44,16 @@ UNIT_TEST(TestAdjacencyMatrix)
|
|||
routing::CrossRoutingContextWriter context;
|
||||
routing::CrossRoutingContextReader newContext;
|
||||
|
||||
context.addIngoingNode(1, m2::PointD::Zero());
|
||||
context.addIngoingNode(2, m2::PointD::Zero());
|
||||
context.addIngoingNode(3, m2::PointD::Zero());
|
||||
context.addOutgoingNode(4, "foo", m2::PointD::Zero());
|
||||
context.reserveAdjacencyMatrix();
|
||||
context.AddIngoingNode(1, m2::PointD::Zero());
|
||||
context.AddIngoingNode(2, m2::PointD::Zero());
|
||||
context.AddIngoingNode(3, m2::PointD::Zero());
|
||||
context.AddOutgoingNode(4, "foo", m2::PointD::Zero());
|
||||
context.ReserveAdjacencyMatrix();
|
||||
{
|
||||
auto ins = context.GetIngoingIterators();
|
||||
auto outs = context.GetOutgoingIterators();
|
||||
context.setAdjacencyCost(ins.first, outs.first, 5);
|
||||
context.setAdjacencyCost(ins.first+1, outs.first, 9);
|
||||
context.SetAdjacencyCost(ins.first, outs.first, 5);
|
||||
context.SetAdjacencyCost(ins.first+1, outs.first, 9);
|
||||
}
|
||||
|
||||
vector<char> buffer;
|
||||
|
@ -65,9 +65,9 @@ UNIT_TEST(TestAdjacencyMatrix)
|
|||
newContext.Load(reader);
|
||||
auto ins = newContext.GetIngoingIterators();
|
||||
auto outs = newContext.GetOutgoingIterators();
|
||||
TEST_EQUAL(newContext.getAdjacencyCost(ins.first, outs.first), 5, ());
|
||||
TEST_EQUAL(newContext.getAdjacencyCost(ins.first + 1, outs.first), 9, ());
|
||||
TEST_EQUAL(newContext.getAdjacencyCost(ins.first + 2, outs.first), routing::INVALID_CONTEXT_EDGE_WEIGHT, ("Default cost"));
|
||||
TEST_EQUAL(newContext.GetAdjacencyCost(ins.first, outs.first), 5, ());
|
||||
TEST_EQUAL(newContext.GetAdjacencyCost(ins.first + 1, outs.first), 9, ());
|
||||
TEST_EQUAL(newContext.GetAdjacencyCost(ins.first + 2, outs.first), routing::INVALID_CONTEXT_EDGE_WEIGHT, ("Default cost"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue