-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add post phase to scheduled strategy
- Loading branch information
Showing
10 changed files
with
124 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...ode-choice/src/main/java/org/matsim/modechoice/replanning/scheduled/ScheduleListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.matsim.modechoice.replanning.scheduled; | ||
|
||
import jakarta.inject.Inject; | ||
import org.matsim.api.core.v01.population.Person; | ||
import org.matsim.api.core.v01.population.Plan; | ||
import org.matsim.core.config.Config; | ||
import org.matsim.core.config.ConfigUtils; | ||
import org.matsim.core.controler.events.IterationEndsEvent; | ||
import org.matsim.core.controler.listener.IterationEndsListener; | ||
import org.matsim.core.replanning.StrategyManager; | ||
import org.matsim.core.replanning.selectors.WorstPlanForRemovalSelector; | ||
import org.matsim.modechoice.ScheduledModeChoiceConfigGroup; | ||
|
||
/** | ||
* Helper listener. | ||
*/ | ||
public class ScheduleListener implements IterationEndsListener { | ||
|
||
private final StrategyManager strategyManager; | ||
private final ScheduledModeChoiceConfigGroup config; | ||
|
||
private boolean iterOver = false; | ||
|
||
@Inject | ||
public ScheduleListener(StrategyManager strategyManager, Config config) { | ||
this.strategyManager = strategyManager; | ||
this.config = ConfigUtils.addOrGetModule(config, ScheduledModeChoiceConfigGroup.class); | ||
} | ||
|
||
@Override | ||
public void notifyIterationEnds(IterationEndsEvent event) { | ||
|
||
int applyIdx = ScheduledStrategyChooser.isScheduledIteration(event.getIteration(), config); | ||
|
||
if (applyIdx == ScheduledStrategyChooser.ITER_OVER && !iterOver) { | ||
// restore the default removal selector for final phase | ||
strategyManager.setPlanSelectorForRemoval(new WorstPlanForRemovalSelector()); | ||
|
||
// Reset plan types at the end so plan can be removed freely | ||
for (Person person : event.getServices().getScenario().getPopulation().getPersons().values()) { | ||
for (Plan plan : person.getPlans()) { | ||
plan.setType(null); | ||
} | ||
} | ||
|
||
iterOver = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters