Skip to content

Commit

Permalink
fix cases where commuting probability for car and transit is 0 and th…
Browse files Browse the repository at this point in the history
…e ratio becomes N/A, leading to in infinite loop
  • Loading branch information
nkuehnel committed Dec 4, 2019
1 parent c53f2cb commit 1652b72
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 1652b72

Please sign in to comment.