| 459 | |
| 460 | template <typename CrossMwmId> |
| 461 | void FillWeights(string const & path, string const & mwmFile, string const & country, |
| 462 | CountryParentNameGetterFn const & countryParentNameGetterFn, |
| 463 | CrossMwmConnectorBuilderEx<CrossMwmId> & builder) |
| 464 | { |
| 465 | base::Timer timer; |
| 466 | |
| 467 | // We use leaps for cars only. To use leaps for other vehicle types add weights generation |
| 468 | // here and change WorldGraph mode selection rule in IndexRouter::CalculateSubroute. |
| 469 | VehicleType const vhType = VehicleType::Car; |
| 470 | std::shared_ptr<VehicleModelInterface> vehicleModel = |
| 471 | CarModelFactory(countryParentNameGetterFn).GetVehicleModelForCountry(country); |
| 472 | |
| 473 | MwmValue mwmValue(LocalCountryFile(path, platform::CountryFile(country), 0 /* version */)); |
| 474 | uint32_t mwmNumRoads = DeserializeIndexGraphNumRoads(mwmValue, vhType); |
| 475 | IndexGraph graph(std::make_shared<Geometry>(GeometryLoader::CreateFromFile(mwmFile, vehicleModel), mwmNumRoads), |
| 476 | EdgeEstimator::Create(vhType, *vehicleModel, nullptr /* trafficStash */, nullptr /* dataSource */, |
| 477 | nullptr /* numMvmIds */)); |
| 478 | graph.SetCurrentTimeGetter([time = GetCurrentTimestamp()] { return time; }); |
| 479 | DeserializeIndexGraph(mwmValue, vhType, graph); |
| 480 | |
| 481 | std::map<Segment, std::map<Segment, RouteWeight>> weights; |
| 482 | |
| 483 | auto const & connector = builder.PrepareConnector(vhType); |
| 484 | uint32_t const numEnters = connector.GetNumEnters(); |
| 485 | uint32_t i = 0; |
| 486 | connector.ForEachEnter([&](uint32_t, Segment const & enter) |
| 487 | { |
| 488 | if (i % 10 == 0) |
| 489 | LOG(LINFO, ("Building leaps:", i, "/", numEnters, "waves passed")); |
| 490 | ++i; |
| 491 | |
| 492 | using Algorithm = AStarAlgorithm<JointSegment, JointEdge, RouteWeight>; |
| 493 | |
| 494 | Algorithm astar; |
| 495 | IndexGraphWrapper indexGraphWrapper(graph, enter); |
| 496 | DijkstraWrapperJoints wrapper(indexGraphWrapper, enter); |
| 497 | Algorithm::Context context(wrapper); |
| 498 | |
| 499 | ankerl::unordered_dense::map<uint32_t, vector<JointSegment>> visitedVertexes; |
| 500 | astar.PropagateWave(wrapper, wrapper.GetStartJoint(), [&](JointSegment const & vertex) |
| 501 | { |
| 502 | if (vertex.IsFake()) |
| 503 | { |
| 504 | auto const & start = wrapper.GetSegmentOfFakeJoint(vertex, true /* start */); |
| 505 | auto const & end = wrapper.GetSegmentOfFakeJoint(vertex, false /* start */); |
| 506 | if (start.IsForward() != end.IsForward()) |
| 507 | return true; |
| 508 | |
| 509 | visitedVertexes[end.GetFeatureId()].emplace_back(start, end); |
| 510 | } |
| 511 | else |
| 512 | { |
| 513 | visitedVertexes[vertex.GetFeatureId()].emplace_back(vertex); |
| 514 | } |
| 515 | |
| 516 | return true; |
| 517 | }, context); |
| 518 |
no test coverage detected