MCPcopy Create free account
hub / github.com/comaps/comaps / Calc

Method Calc

libs/routing/index_router.cpp:1376–1426  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1374}
1375
1376IndexRouter::RoutingResultT const * IndexRouter::RoutesCalculator::Calc(Segment const & beg, Segment const & end,
1377 ProgressPtrT const & progress,
1378 double progressCoef)
1379{
1380 auto itCache = m_cache.insert({{beg, end}, {}});
1381 auto * res = &itCache.first->second;
1382
1383 // Actually, we can (should?) append/push-drop progress even if the route is already in cache,
1384 // but I'd like to avoid this unnecessary actions here.
1385 if (itCache.second)
1386 {
1387 LOG(LDEBUG, ("Calculating sub-route:", beg, end));
1388 progress->AppendSubProgress({m_starter.GetPoint(beg, true), m_starter.GetPoint(end, true), progressCoef});
1389
1390 using JointsStarter = IndexGraphStarterJoints<IndexGraphStarter>;
1391 JointsStarter jointStarter(m_starter);
1392 jointStarter.Init(beg, end);
1393
1394 using Vertex = JointsStarter::Vertex;
1395 using Edge = JointsStarter::Edge;
1396 using Weight = JointsStarter::Weight;
1397
1398 using Visitor = JunctionVisitor<JointsStarter>;
1399 AStarAlgorithm<Vertex, Edge, Weight>::Params<Visitor, AStarLengthChecker> params(
1400 jointStarter, jointStarter.GetStartJoint(), jointStarter.GetFinishJoint(), m_delegate.GetCancellable(),
1401 Visitor(jointStarter, m_delegate, kVisitPeriod, progress), AStarLengthChecker(m_starter));
1402
1403 RoutingResult<JointSegment, RouteWeight> route;
1404 using AlgoT = AStarAlgorithm<Vertex, Edge, Weight>;
1405
1406 if (AlgoT().FindPathBidirectional(params, route) == AlgoT::Result::OK)
1407 {
1408 LOG(LDEBUG, ("Sub-route weight:", route.m_distance));
1409
1410 res->m_path = ProcessJoints(route.m_path, jointStarter);
1411 res->m_distance = route.m_distance;
1412
1413 progress->PushAndDropLastSubProgress();
1414 }
1415 else
1416 {
1417 progress->DropLastSubProgress();
1418
1419 m_cache.erase(itCache.first);
1420 return nullptr;
1421 }
1422 }
1423
1424 CHECK(!res->Empty(), ());
1425 return res;
1426}
1427
1428IndexRouter::RoutingResultT const * IndexRouter::RoutesCalculator::Calc2Times(Segment const & beg, Segment const & end,
1429 ProgressPtrT const & progress,

Callers 1

ProcessLeapsJointsMethod · 0.80

Calls 12

AStarLengthCheckerClass · 0.85
ProcessJointsFunction · 0.85
AppendSubProgressMethod · 0.80
FindPathBidirectionalMethod · 0.80
DropLastSubProgressMethod · 0.80
VisitorClass · 0.50
insertMethod · 0.45
GetPointMethod · 0.45
InitMethod · 0.45
eraseMethod · 0.45
EmptyMethod · 0.45

Tested by

no test coverage detected