From 4414149ef571df078e51e8c14e8199bda44141c5 Mon Sep 17 00:00:00 2001 From: rakow Date: Tue, 14 May 2024 22:21:31 +0200 Subject: [PATCH] catch errors in sample network --- .../application/prepare/network/SampleNetwork.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/contribs/application/src/main/java/org/matsim/application/prepare/network/SampleNetwork.java b/contribs/application/src/main/java/org/matsim/application/prepare/network/SampleNetwork.java index 82a7a278e32..7150554e61e 100644 --- a/contribs/application/src/main/java/org/matsim/application/prepare/network/SampleNetwork.java +++ b/contribs/application/src/main/java/org/matsim/application/prepare/network/SampleNetwork.java @@ -193,7 +193,7 @@ public Integer call() throws Exception { RandomizedTravelTime tt = new RandomizedTravelTime(rnd); - LeastCostPathCalculator router = createRandomizedRouter(network, tt); + LeastCostPathCalculator router = createRandomizedRouter(cityNetwork, tt); sampleCityRoutes(cityNetwork, router, tt, rnd); @@ -223,9 +223,16 @@ private void sampleCityRoutes(Network network, LeastCostPathCalculator router, R Link to = NetworkUtils.getNearestLink(network, dest); + // Links could be on the very edge so that nodes are outside the network + if (to == null || !network.getNodes().containsKey(link.getFromNode().getId()) || + !network.getNodes().containsKey(to.getToNode().getId())) { + i--; + continue; + } + LeastCostPathCalculator.Path path = router.calcLeastCostPath(link.getFromNode(), to.getToNode(), 0, null, null); - if (path.nodes.size() < 2) { + if (path == null || path.nodes.size() < 2) { i--; continue; }