diff --git a/contribs/application/src/main/java/org/matsim/application/analysis/traffic/traveltime/TravelTimeComparison.java b/contribs/application/src/main/java/org/matsim/application/analysis/traffic/traveltime/TravelTimeComparison.java index 3c22fc678a3..41abdbcff54 100644 --- a/contribs/application/src/main/java/org/matsim/application/analysis/traffic/traveltime/TravelTimeComparison.java +++ b/contribs/application/src/main/java/org/matsim/application/analysis/traffic/traveltime/TravelTimeComparison.java @@ -1,5 +1,7 @@ package org.matsim.application.analysis.traffic.traveltime; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.TransportMode; import org.matsim.api.core.v01.network.Link; @@ -47,6 +49,8 @@ ) public class TravelTimeComparison implements MATSimAppCommand { + private static final Logger log = LogManager.getLogger(TravelTimeComparison.class); + @CommandLine.Mixin private InputOptions input = InputOptions.ofCommand(TravelTimeComparison.class); @@ -90,6 +94,13 @@ public Integer call() throws Exception { for (Row row : data) { LeastCostPathCalculator.Path congested = computePath(network, congestedRouter, row); + + // Skip if path is not found + if (congested == null) { + row.setDouble("simulated", Double.NaN); + continue; + } + double dist = congested.links.stream().mapToDouble(Link::getLength).sum(); double speed = 3.6 * dist / congested.travelTime; @@ -102,6 +113,8 @@ public Integer call() throws Exception { row.setDouble("free_flow", speed); } + data = data.dropWhere(data.doubleColumn("simulated").isMissing()); + data.addColumns( data.doubleColumn("simulated").subtract(data.doubleColumn("mean")).setName("bias") ); @@ -129,6 +142,16 @@ private LeastCostPathCalculator.Path computePath(Network network, LeastCostPathC Node fromNode = network.getNodes().get(Id.createNodeId(row.getString("from_node"))); Node toNode = network.getNodes().get(Id.createNodeId(row.getString("to_node"))); + if (fromNode == null) { + log.error("Node {} not found in network", row.getString("from_node")); + return null; + } + + if (toNode == null) { + log.error("Node {} not found in network", row.getString("to_node")); + return null; + } + return router.calcLeastCostPath(fromNode, toNode, row.getInt("hour") * 3600, null, null); }