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; }