Skip to content

Commit

Permalink
Merge pull request #6 from matsim-scenarios/make_adjust_freight_more_…
Browse files Browse the repository at this point in the history
…robust

Make adjust freight code more robust
  • Loading branch information
Janekdererste authored Oct 5, 2022
2 parents a92a637 + 14c390b commit be92056
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ public static void adjustScenarioForFreight(Scenario scenario, List<String> mode
config.planCalcScore().addModeParams(new PlanCalcScoreConfigGroup.ModeParams(mode).setMonetaryDistanceRate(-0.0004));
}

log.info("will delete routes from commercial legs and set coords of commercial activities to coord of their link!! This requires that the input plans were routed at least once, beforehand!");
log.info("will delete routes from commercial legs and set coords of commercial activities to coord of their link!! If activities have no link id, nothing happens. The simulation will assign this coord later.");
scenario.getPopulation().getPersons().values().stream()
.filter(person -> PopulationUtils.getSubpopulation(person).equals(COMMERCIAL))
.filter(person -> COMMERCIAL.equals(PopulationUtils.getSubpopulation(person)))
.flatMap(person -> person.getSelectedPlan().getPlanElements().stream())
.forEach(planElement -> {
if(planElement instanceof Activity){
Id<Link> linkId = ((Activity) planElement).getLinkId();
((Activity) planElement).setCoord(network.getLinks().get(linkId).getCoord());
if (linkId != null) {
((Activity) planElement).setCoord(network.getLinks().get(linkId).getCoord());
}
} else {
((Leg) planElement).setRoute(null);
}
Expand Down Expand Up @@ -94,4 +96,4 @@ public void install() {
});
}
}
}
}

0 comments on commit be92056

Please sign in to comment.