diff --git a/siloCore/src/main/java/de/tum/bgu/msm/models/modeChoice/SimpleCommuteModeChoice.java b/siloCore/src/main/java/de/tum/bgu/msm/models/modeChoice/SimpleCommuteModeChoice.java index 795083e0c..4ad614706 100644 --- a/siloCore/src/main/java/de/tum/bgu/msm/models/modeChoice/SimpleCommuteModeChoice.java +++ b/siloCore/src/main/java/de/tum/bgu/msm/models/modeChoice/SimpleCommuteModeChoice.java @@ -65,8 +65,13 @@ public CommuteModeChoiceMapping assignCommuteModeChoice(Location from, TravelTim utilityByMode.put(TransportMode.car, carUtility); utilityByMode.put(TransportMode.pt, ptUtility); commuteModesByPerson.put(pp.getId(), utilityByMode); - double probabilityAsKey = carUtility / (carUtility + ptUtility); - while (personByProbability.containsKey(probabilityAsKey)){ + double probabilityAsKey; + if(carUtility == 0 && ptUtility == 0) { + probabilityAsKey = 0.5; + } else { + probabilityAsKey = carUtility / (carUtility + ptUtility); + } + while (personByProbability.containsKey(probabilityAsKey)) { //more than one hh member has exactly the same probability, so it would be replaced in the treemap probabilityAsKey += random.nextDouble(); } @@ -125,8 +130,13 @@ public CommuteModeChoiceMapping assignRegionalCommuteModeChoice(Region region, T utilityByMode.put(TransportMode.car, carUtility); utilityByMode.put(TransportMode.pt, ptUtility); commuteModesByPerson.put(pp.getId(), utilityByMode); - double probabilityAsKey = carUtility / (carUtility + ptUtility); - if (personByProbability.containsKey(probabilityAsKey)){ + double probabilityAsKey; + if(carUtility == 0 && ptUtility == 0) { + probabilityAsKey = 0.5; + } else { + probabilityAsKey = carUtility / (carUtility + ptUtility); + } + while (personByProbability.containsKey(probabilityAsKey)) { //more than one hh member has exactly the same probability, so it would be replaced in the treemap probabilityAsKey += random.nextDouble(); }