Skip to content

Commit

Permalink
Pull synchronization out of getLatestSimResultsUpTo so the latter can…
Browse files Browse the repository at this point in the history
… be used in rootfinding
  • Loading branch information
adrienmaillard committed Oct 11, 2023
1 parent 79fc57a commit 69b0050
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ private InsertActivityResult checkAndInsertActs(Collection<SchedulingActivityDir
return new InsertActivityResult(allGood, finalSetOfActsInserted);
}

/**
* Pulls all the child activities from the simulation + fills in activity durations
* This method should be called only when the state of the plan is considered safe, i.e. not during rootfinding
* @return a map of scheduling activity directives (old -> new) that have been replaced in the plan due to updated durations
*/
private Map<SchedulingActivityDirective, SchedulingActivityDirective> synchronizeSimulationWithSchedulerPlan() {
final Map<SchedulingActivityDirective, SchedulingActivityDirective> replacedInPlan;
try {
Expand Down Expand Up @@ -620,6 +625,7 @@ else if(!analysisOnly && (missing instanceof MissingActivityTemplateConflict mi
assert plan != null;
//REVIEW: maybe should have way to request only certain kinds of conflicts
final var lastSimulationResults = this.getLatestSimResultsUpTo(this.problem.getPlanningHorizon().getEndAerie());
synchronizeSimulationWithSchedulerPlan();
final var evaluationEnvironment = new EvaluationEnvironment(this.problem.getRealExternalProfiles(), this.problem.getDiscreteExternalProfiles());
final var rawConflicts = goal.getConflicts(plan, lastSimulationResults, evaluationEnvironment);
assert rawConflicts != null;
Expand Down Expand Up @@ -771,6 +777,7 @@ private Windows narrowByResourceConstraints(Windows windows,
final var totalDomain = Interval.between(windows.minTrueTimePoint().get().getKey(), windows.maxTrueTimePoint().get().getKey());
//make sure the simulation results cover the domain
final var latestSimulationResults = this.getLatestSimResultsUpTo(totalDomain.end);
synchronizeSimulationWithSchedulerPlan();
//iteratively narrow the windows from each constraint
//REVIEW: could be some optimization in constraint ordering (smallest domain first to fail fast)
final var evaluationEnvironment = new EvaluationEnvironment(this.problem.getRealExternalProfiles(), this.problem.getDiscreteExternalProfiles());
Expand All @@ -793,7 +800,6 @@ private SimulationResults getLatestSimResultsUpTo(Duration time){
if (lastSimResultsFromFacade.isEmpty() || lastSimResultsFromFacade.get().bounds.end.shorterThan(time)) {
try {
this.simulationFacade.computeSimulationResultsUntil(time);
synchronizeSimulationWithSchedulerPlan();
} catch (SimulationFacade.SimulationException e) {
throw new RuntimeException("Exception while running simulation before evaluating conflicts", e);
}
Expand All @@ -814,6 +820,7 @@ private Windows narrowGlobalConstraints(
}
//make sure the simulation results cover the domain
final var latestSimulationResults = this.getLatestSimResultsUpTo(tmp.maxTrueTimePoint().get().getKey());
synchronizeSimulationWithSchedulerPlan();
for (GlobalConstraint gc : constraints) {
if (gc instanceof GlobalConstraintWithIntrospection c) {
tmp = c.findWindows(
Expand Down

0 comments on commit 69b0050

Please sign in to comment.