Skip to content

Commit

Permalink
refactor CleanPopulation
Browse files Browse the repository at this point in the history
  • Loading branch information
simei94 committed Sep 26, 2024
1 parent 13dfc89 commit dc2dce2
Showing 1 changed file with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ public Integer call() throws Exception {
for (Person person : population.getPersons().values()) {

if (rmUnselected) {
Plan selected = person.getSelectedPlan();
for (Plan plan : Lists.newArrayList(person.getPlans())) {
if (plan != selected)
person.removePlan(plan);
}
removeUnselectedPlans(person);
}

for (Plan plan : person.getPlans()) {
Expand All @@ -83,16 +79,11 @@ public Integer call() throws Exception {

for (PlanElement el : plan.getPlanElements()) {
if (rmRoutes) {
if (el instanceof Leg) {
((Leg) el).setRoute(null);
}
removeRouteFromLeg(el);
}

if (rmActivityLocations) {
if (el instanceof Activity) {
((Activity) el).setLinkId(null);
((Activity) el).setFacilityId(null);
}
removeActivityLocation(el);
}
}
}
Expand All @@ -102,4 +93,25 @@ public Integer call() throws Exception {

return 0;
}
}

public static void removeActivityLocation(PlanElement el) {
if (el instanceof Activity act) {
act.setLinkId(null);
act.setFacilityId(null);
}
}

public static void removeRouteFromLeg(PlanElement el) {
if (el instanceof Leg leg) {
leg.setRoute(null);
}
}

public static void removeUnselectedPlans(Person person) {
Plan selected = person.getSelectedPlan();
for (Plan plan : Lists.newArrayList(person.getPlans())) {
if (plan != selected)
person.removePlan(plan);
}
}
}

0 comments on commit dc2dce2

Please sign in to comment.