Skip to content

Commit

Permalink
refactor(ImpedanceUpdateHandler): Apply impedances to edges with Spli…
Browse files Browse the repository at this point in the history
…tterVertex.
  • Loading branch information
binh-dam-ibigroup committed Aug 15, 2024
1 parent 1c47d27 commit d1496be
Showing 1 changed file with 21 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.opentripplanner.updater.impedance;

import java.util.Collection;
import java.util.Map;
import org.opentripplanner.ext.mobilityprofile.MobilityProfile;
import org.opentripplanner.ext.mobilityprofile.MobilityProfileData;
Expand All @@ -9,7 +8,6 @@
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.street.model.edge.StreetEdge;
import org.opentripplanner.street.model.vertex.OsmVertex;
import org.opentripplanner.street.search.TraverseMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -29,38 +27,31 @@ public void update(Graph graph, Map<String, MobilityProfileData> impedances) {
// - walkable edges: ~92k
// - First-time impedance load: ~29k entries

// This filter is fast and cuts the size of the searchable set tenfold.
Collection<StreetEdge> walkableEdges = graph
.getStreetEdges()
.stream()
.filter(se -> se.getPermission().allows(TraverseMode.WALK))
.toList();
for (StreetEdge se : graph.getStreetEdges()) {
var impedance = impedances.get(se.profileKey);
if (impedance != null) {
String symbol = "★";
Map<MobilityProfile, Float> proRatedCosts = impedance.costs();

for (StreetEdge se : walkableEdges) {
if (
se.getFromVertex() instanceof OsmVertex osmFrom &&
se.getToVertex() instanceof OsmVertex osmTo
) {
var impedance = impedances.get(se.profileKey);
if (impedance != null) {
String symbol = "★";
Map<MobilityProfile, Float> proRatedCosts = impedance.costs();
// Create pro-rated impedances for split edges with intermediate OsmVertex or SplitterVertex.
long fromNodeId = 0;
if (se.getFromVertex() instanceof OsmVertex osmFrom) fromNodeId = osmFrom.nodeId;
long toNodeId = 0;
if (se.getToVertex() instanceof OsmVertex osmTo) toNodeId = osmTo.nodeId;

// Create pro-rated impedance data for split edges.
if (osmFrom.nodeId != impedance.fromNode() || osmTo.nodeId != impedance.toNode()) {
double ratio = se.getDistanceMeters() / impedance.lengthInMeters();
proRatedCosts =
MobilityProfileRouting.getProRatedProfileCosts(impedance.costs(), (float) ratio);
symbol = "☆";
}
if (fromNodeId != impedance.fromNode() || toNodeId != impedance.toNode()) {
double ratio = se.getDistanceMeters() / impedance.lengthInMeters();
proRatedCosts =
MobilityProfileRouting.getProRatedProfileCosts(impedance.costs(), (float) ratio);
symbol = "☆";
}

// Update profile costs for this StreetEdge object if an impedance entry was found.
se.profileCost = proRatedCosts;
count++;
// Update profile costs for this StreetEdge object if an impedance entry was found.
se.profileCost = proRatedCosts;
count++;

// Amend the name with an indication that impedances were applied
se.setName(I18NString.of(String.format("%s%s", se.getName(), symbol)));
}
// Amend the name with an indication that impedances were applied
se.setName(I18NString.of(String.format("%s%s", se.getName(), symbol)));
}
}

Expand Down

0 comments on commit d1496be

Please sign in to comment.