From d1496bed3b751cf5e255a4e620f864fde9e79b3c Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Thu, 15 Aug 2024 15:07:49 -0400 Subject: [PATCH] refactor(ImpedanceUpdateHandler): Apply impedances to edges with SplitterVertex. --- .../impedance/ImpedanceUpdateHandler.java | 51 ++++++++----------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/opentripplanner/updater/impedance/ImpedanceUpdateHandler.java b/src/main/java/org/opentripplanner/updater/impedance/ImpedanceUpdateHandler.java index 2cd841910ca..5167368c1f2 100644 --- a/src/main/java/org/opentripplanner/updater/impedance/ImpedanceUpdateHandler.java +++ b/src/main/java/org/opentripplanner/updater/impedance/ImpedanceUpdateHandler.java @@ -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; @@ -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; @@ -29,38 +27,31 @@ public void update(Graph graph, Map impedances) { // - walkable edges: ~92k // - First-time impedance load: ~29k entries - // This filter is fast and cuts the size of the searchable set tenfold. - Collection 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 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 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))); } }