Skip to content

Commit

Permalink
enable scheduled mode choice conditionally
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Apr 1, 2024
1 parent 9d9fdbe commit 346b81e
Showing 1 changed file with 50 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,62 +73,68 @@ public void install() {

ScheduledModeChoiceConfigGroup config = ConfigUtils.addOrGetModule(getConfig(), ScheduledModeChoiceConfigGroup.class);

Collection<ReplanningConfigGroup.StrategySettings> strategies = new ArrayList<>(getConfig().replanning().getStrategySettings());
getConfig().replanning().clearStrategySettings();
boolean enabled = !config.getSubpopulations().isEmpty();

for (String subpopulation : config.getSubpopulations()) {
log.info("Scheduled mode choice is {}.", enabled ? "enabled" : "disabled");

OptionalDouble reroute = strategies.stream().filter(s -> s.getStrategyName().equals(DefaultPlanStrategiesModule.DefaultStrategy.ReRoute) &&
s.getSubpopulation().equals(subpopulation))
.mapToDouble(ReplanningConfigGroup.StrategySettings::getWeight)
.findFirst();
if (enabled) {

OptionalDouble timeMutate = strategies.stream().filter(s ->
(s.getStrategyName().equals(DefaultPlanStrategiesModule.DefaultStrategy.TimeAllocationMutator) ||
s.getStrategyName().equals(DefaultPlanStrategiesModule.DefaultStrategy.TimeAllocationMutator_ReRoute)) &&
Collection<ReplanningConfigGroup.StrategySettings> strategies = new ArrayList<>(getConfig().replanning().getStrategySettings());
getConfig().replanning().clearStrategySettings();

for (String subpopulation : config.getSubpopulations()) {

OptionalDouble reroute = strategies.stream().filter(s -> s.getStrategyName().equals(DefaultPlanStrategiesModule.DefaultStrategy.ReRoute) &&
s.getSubpopulation().equals(subpopulation))
.mapToDouble(ReplanningConfigGroup.StrategySettings::getWeight)
.findFirst();

strategies.removeIf(s -> s.getSubpopulation().equals(subpopulation) && EXCLUDED.contains(s.getStrategyName()));

ReplanningConfigGroup.StrategySettings strategy = new ReplanningConfigGroup.StrategySettings();
strategy.setStrategyName(ALL_BEST_K_PLAN_MODES_STRATEGY);
strategy.setSubpopulation(subpopulation);
strategy.setWeight(1.0);
strategies.add(strategy);

if (reroute.isPresent()) {
ReplanningConfigGroup.StrategySettings s = new ReplanningConfigGroup.StrategySettings();
s.setStrategyName(REROUTE_SELECTED);
s.setSubpopulation(subpopulation);
s.setWeight(reroute.getAsDouble());
strategies.add(s);
.mapToDouble(ReplanningConfigGroup.StrategySettings::getWeight)
.findFirst();

OptionalDouble timeMutate = strategies.stream().filter(s ->
(s.getStrategyName().equals(DefaultPlanStrategiesModule.DefaultStrategy.TimeAllocationMutator) ||
s.getStrategyName().equals(DefaultPlanStrategiesModule.DefaultStrategy.TimeAllocationMutator_ReRoute)) &&
s.getSubpopulation().equals(subpopulation))
.mapToDouble(ReplanningConfigGroup.StrategySettings::getWeight)
.findFirst();

strategies.removeIf(s -> s.getSubpopulation().equals(subpopulation) && EXCLUDED.contains(s.getStrategyName()));

ReplanningConfigGroup.StrategySettings strategy = new ReplanningConfigGroup.StrategySettings();
strategy.setStrategyName(ALL_BEST_K_PLAN_MODES_STRATEGY);
strategy.setSubpopulation(subpopulation);
strategy.setWeight(1.0);
strategies.add(strategy);

if (reroute.isPresent()) {
ReplanningConfigGroup.StrategySettings s = new ReplanningConfigGroup.StrategySettings();
s.setStrategyName(REROUTE_SELECTED);
s.setSubpopulation(subpopulation);
s.setWeight(reroute.getAsDouble());
strategies.add(s);
}

if (timeMutate.isPresent()) {
ReplanningConfigGroup.StrategySettings s = new ReplanningConfigGroup.StrategySettings();
s.setStrategyName(TIME_MUTATE_SELECTED);
s.setSubpopulation(subpopulation);
s.setWeight(timeMutate.getAsDouble());
strategies.add(s);
}
}

if (timeMutate.isPresent()) {
ReplanningConfigGroup.StrategySettings s = new ReplanningConfigGroup.StrategySettings();
s.setStrategyName(TIME_MUTATE_SELECTED);
s.setSubpopulation(subpopulation);
s.setWeight(timeMutate.getAsDouble());
strategies.add(s);
}
}
strategies.forEach(s -> getConfig().replanning().addStrategySettings(s));

strategies.forEach(s -> getConfig().replanning().addStrategySettings(s));
if (config.isAdjustTargetIterations()) {

if (config.isAdjustTargetIterations()) {
int iters = config.getWarumUpIterations() + config.getScheduleIterations() * (1 + config.getBetweenIterations());

int iters = config.getWarumUpIterations() + config.getScheduleIterations() * (1 + config.getBetweenIterations());
int target = (int) Math.ceil(iters / getConfig().replanning().getFractionOfIterationsToDisableInnovation());

int target = (int) Math.ceil(iters / getConfig().replanning().getFractionOfIterationsToDisableInnovation());
log.info("Adjusting number of iterations from {} to {}.", getConfig().controller().getLastIteration(), target);
getConfig().controller().setLastIteration(target);
}

log.info("Adjusting number of iterations from {} to {}.", getConfig().controller().getLastIteration(), target);
getConfig().controller().setLastIteration(target);
bindPlanSelectorForRemoval().to(WorstNotSelctedPlanSelector.class);
}

bindPlanSelectorForRemoval().to(WorstNotSelctedPlanSelector.class);

}

/**
Expand Down

0 comments on commit 346b81e

Please sign in to comment.