@@ -337,15 +337,16 @@ void Dijkstras::Compute(google::protobuf::RepeatedPtrField<valhalla::Location>&
337337
338338 // Prepare for a graph traversal
339339 Initialize (bdedgelabels_, adjacencylist_, costing_->UnitSize ());
340- if (expansion_direction == ExpansionType::forward) {
341- SetOriginLocations (graphreader, locations, costing_);
342- } else {
343- SetDestinationLocations (graphreader, locations, costing_);
344- }
345340
346341 // Get the time information for all the origin locations
347342 auto time_infos = SetTime (locations, graphreader);
348343
344+ if (expansion_direction == ExpansionType::forward) {
345+ SetOriginLocations (graphreader, locations, time_infos, costing_);
346+ } else {
347+ SetDestinationLocations (graphreader, locations, time_infos, costing_);
348+ }
349+
349350 // Compute the isotile
350351 auto cb_decision = ExpansionRecommendation::continue_expansion;
351352 while (cb_decision != ExpansionRecommendation::stop_expansion) {
@@ -773,15 +774,16 @@ void Dijkstras::ComputeMultiModal(
773774// Add edge(s) at each origin to the adjacency list
774775void Dijkstras::SetOriginLocations (GraphReader& graphreader,
775776 google::protobuf::RepeatedPtrField<valhalla::Location>& locations,
777+ const std::vector<baldr::TimeInfo>& time_infos,
776778 const cost_ptr_t & costing) {
777779 // Bail if you want to do a multipath expansion with more locations than edge label/status supports
778780 if (multipath_ && locations.size () > baldr::kMaxMultiPathId )
779781 throw std::runtime_error (" Max number of locations exceeded" );
780782
781783 // Add edges for each location to the adjacency list
782- uint8_t path_id = -1 ;
784+ uint8_t loc_idx = -1 ;
783785 for (auto & location : locations) {
784- ++path_id ;
786+ ++loc_idx ;
785787
786788 // Only skip inbound edges if we have other options
787789 bool has_other_edges = false ;
@@ -790,6 +792,8 @@ void Dijkstras::SetOriginLocations(GraphReader& graphreader,
790792 has_other_edges = has_other_edges || !e.end_node ();
791793 });
792794
795+ const auto & time_info = time_infos[loc_idx];
796+
793797 // Iterate through edges and add to adjacency list
794798 for (const auto & edge : (location.correlation ().edges ())) {
795799 // If origin is at a node - skip any inbound edge (dist = 1)
@@ -819,7 +823,7 @@ void Dijkstras::SetOriginLocations(GraphReader& graphreader,
819823
820824 // Get cost
821825 uint8_t flow_sources;
822- Cost cost = costing->EdgeCost (directededge, tile, TimeInfo::invalid () , flow_sources) *
826+ Cost cost = costing->EdgeCost (directededge, tile, time_info , flow_sources) *
823827 (1 .0f - edge.percent_along ());
824828 // Get path distance
825829 auto path_dist = directededge->length () * (1 - edge.percent_along ());
@@ -839,7 +843,7 @@ void Dijkstras::SetOriginLocations(GraphReader& graphreader,
839843 bdedgelabels_.emplace_back (kInvalidLabel , edgeid, opp_edge_id, directededge, cost, mode_,
840844 Cost{}, path_dist, false , !(costing_->IsClosed (directededge, tile)),
841845 static_cast <bool >(flow_sources & kDefaultFlowMask ),
842- InternalTurn::kNoTurn , kInvalidRestriction , multipath_ ? path_id : 0 ,
846+ InternalTurn::kNoTurn , kInvalidRestriction , multipath_ ? loc_idx : 0 ,
843847 directededge->destonly () ||
844848 (costing_->is_hgv () && directededge->destonly_hgv ()),
845849 directededge->forwardaccess () & kTruckAccess ,
@@ -849,7 +853,7 @@ void Dijkstras::SetOriginLocations(GraphReader& graphreader,
849853
850854 // Add EdgeLabel to the adjacency list
851855 adjacencylist_.add (idx);
852- edgestatus_.Set (edgeid, EdgeSet::kTemporary , idx, tile, multipath_ ? path_id : 0 );
856+ edgestatus_.Set (edgeid, EdgeSet::kTemporary , idx, tile, multipath_ ? loc_idx : 0 );
853857 }
854858 }
855859}
@@ -858,15 +862,18 @@ void Dijkstras::SetOriginLocations(GraphReader& graphreader,
858862void Dijkstras::SetDestinationLocations (
859863 GraphReader& graphreader,
860864 google::protobuf::RepeatedPtrField<valhalla::Location>& locations,
865+ const std::vector<baldr::TimeInfo>& time_infos,
861866 const cost_ptr_t & costing) {
862867 // Bail if you want to do a multipath expansion with more locations than edge label/status supports
863868 if (multipath_ && locations.size () > baldr::kMaxMultiPathId )
864869 throw std::runtime_error (" Max number of locations exceeded" );
865870
866871 // Add edges for each location to the adjacency list
867- uint8_t path_id = -1 ;
872+ uint8_t loc_idx = -1 ;
868873 for (auto & location : locations) {
869- ++path_id;
874+ ++loc_idx;
875+
876+ const auto & time_info = time_infos[loc_idx];
870877
871878 // Only skip outbound edges if we have other options
872879 bool has_other_edges = false ;
@@ -906,8 +913,8 @@ void Dijkstras::SetDestinationLocations(
906913
907914 // Get the cost
908915 uint8_t flow_sources;
909- Cost cost = costing-> EdgeCost (directededge, tile, TimeInfo::invalid (), flow_sources) *
910- edge.percent_along ();
916+ Cost cost =
917+ costing-> EdgeCost (directededge, tile, time_info, flow_sources) * edge.percent_along ();
911918 // Get the path distance
912919 auto path_dist = directededge->length () * edge.percent_along ();
913920
@@ -938,13 +945,13 @@ void Dijkstras::SetDestinationLocations(
938945 bdedgelabels_.emplace_back (kInvalidLabel , opp_edge_id, edgeid, opp_dir_edge, cost, mode_,
939946 Cost{}, path_dist, false , !(costing_->IsClosed (directededge, tile)),
940947 static_cast <bool >(flow_sources & kDefaultFlowMask ),
941- InternalTurn::kNoTurn , restriction_idx, multipath_ ? path_id : 0 ,
948+ InternalTurn::kNoTurn , restriction_idx, multipath_ ? loc_idx : 0 ,
942949 directededge->destonly () ||
943950 (costing_->is_hgv () && directededge->destonly_hgv ()),
944951 directededge->forwardaccess () & kTruckAccess ,
945952 destonly_restriction_mask);
946953 adjacencylist_.add (idx);
947- edgestatus_.Set (opp_edge_id, EdgeSet::kTemporary , idx, opp_tile, multipath_ ? path_id : 0 );
954+ edgestatus_.Set (opp_edge_id, EdgeSet::kTemporary , idx, opp_tile, multipath_ ? loc_idx : 0 );
948955 }
949956 }
950957}
0 commit comments