Fix: Non-deterministic behaviour of SwissRailRaptor #3568
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi @mrieser,
@sebhoerl and I noticed that some of our simulations were not determinstic (i.e, running the same simulation twice did not necessarily generate the same events and plans). After investigating we found out that there are at least 2 places in SwissRailRaptor that are not deterministic.
DefaultRaptorStopFinder.findStops
does not always return the same stops, we tracked this down to the initialization of the stopsQuadTree
inSwissRailRaptorData.create
where stops are retrieved from aHashMap
. We replaced it by aLinkedHashMap
to always have the same order.SwissRailRaptorCore.calcLeastCostRoute
where someHashMap
objects are also built then looped over, which we also replaced byLinkedHashMap
.This PR introduces a
RaptorDeterminismTest
class inch.sbb.matsim
with a unit test to uncover non-deterministic behaviour inSwissRailRaptor
. Moreover, aDeterminismTest
class is introduced inorg.matsim.contrib.discrete_mode_choice
to check that a whole simulation is deterministic.The commits introducing the tests are separated from the ones introducing the fixes, so you can checkout each step and see what is being solved.
As some non-deterministic behaviour only appear in rare cases, we will incorporate some systematic checks on other simulation scenarios in our internal workflows and keep you updated if any other source of variability is identified.
Best,
Tarek Chouaki.