From 4e57a602a46f2261f7afdb56a810164922c25fe5 Mon Sep 17 00:00:00 2001 From: Andreas Neumann Date: Tue, 30 Jan 2024 15:33:07 +0100 Subject: [PATCH] fixed processing sequence to avoid non-deterministic behavior if there is more than one route option with the same travel time albeit different length, the route found depends on the sequence of link processing. That is, route choice depends on the implementation of the Network/NetworkReader and/or the sequence of links in the network file. --- .../java/org/matsim/core/router/speedy/SpeedyGraph.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/matsim/src/main/java/org/matsim/core/router/speedy/SpeedyGraph.java b/matsim/src/main/java/org/matsim/core/router/speedy/SpeedyGraph.java index fbb2896a408..b1b9edf5f1e 100644 --- a/matsim/src/main/java/org/matsim/core/router/speedy/SpeedyGraph.java +++ b/matsim/src/main/java/org/matsim/core/router/speedy/SpeedyGraph.java @@ -5,7 +5,10 @@ import org.matsim.api.core.v01.network.Network; import org.matsim.api.core.v01.network.Node; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; +import java.util.List; /** * Implements a highly optimized data structure for representing a MATSim network. Optimized to use as little memory as possible, and thus to fit as much memory as possible into CPU caches for high @@ -70,7 +73,11 @@ public SpeedyGraph(Network network) { for (Node node : network.getNodes().values()) { this.nodes[node.getId().index()] = node; } - for (Link link : network.getLinks().values()) { + + List> linkIds = new ArrayList<>(network.getLinks().keySet()); + Collections.sort(linkIds); + for (Id linkId : linkIds) { + Link link = network.getLinks().get(linkId); addLink(link); } }