diff --git a/scheduler-worker/src/main/java/gov/nasa/jpl/aerie/scheduler/worker/services/SynchronousSchedulerAgent.java b/scheduler-worker/src/main/java/gov/nasa/jpl/aerie/scheduler/worker/services/SynchronousSchedulerAgent.java index 6b0c6d49fd..b2ad52cd70 100644 --- a/scheduler-worker/src/main/java/gov/nasa/jpl/aerie/scheduler/worker/services/SynchronousSchedulerAgent.java +++ b/scheduler-worker/src/main/java/gov/nasa/jpl/aerie/scheduler/worker/services/SynchronousSchedulerAgent.java @@ -132,7 +132,7 @@ public void schedule(final ScheduleRequest request, final ResultsProtocol.Writer final var externalProfiles = loadExternalProfiles(planMetadata.planId()); final var initialSimulationResults = loadSimulationResults(planMetadata); //seed the problem with the initial plan contents - final var loadedPlanComponents = loadInitialPlan(planMetadata, problem); + final var loadedPlanComponents = loadInitialPlan(planMetadata, problem, initialSimulationResults); problem.setInitialPlan(loadedPlanComponents.schedulerPlan(), initialSimulationResults); problem.setExternalProfile(externalProfiles.realProfiles(), externalProfiles.discreteProfiles()); //apply constraints/goals to the problem @@ -401,11 +401,15 @@ private Solver createScheduler(final PlanMetadata planMetadata, final Problem pr * * @param planMetadata metadata of plan container to load from * @param problem the problem that the plan adheres to + * @param initialSimulationResults initial simulation results (optional) * @return a plan with all activity instances loaded from the target merlin plan container * @throws ResultsProtocolFailure when the requested plan cannot be loaded, or the target plan revision has * changed, or aerie could not be reached */ - private PlanComponents loadInitialPlan(final PlanMetadata planMetadata, final Problem problem) { + private PlanComponents loadInitialPlan( + final PlanMetadata planMetadata, + final Problem problem, + final Optional initialSimulationResults) { //TODO: maybe paranoid check if plan rev has changed since original metadata? try { final var merlinPlan = merlinService.getPlanActivityDirectives(planMetadata, problem); @@ -431,12 +435,19 @@ private PlanComponents loadInitialPlan(final PlanMetadata planMetadata, final Pr .orElseThrow(() -> new Exception("Controllable Duration parameter was not an Int")), Duration.MICROSECONDS); } - } else if ( - schedulerActType.getDurationType() instanceof DurationType.Uncontrollable - || schedulerActType.getDurationType() instanceof DurationType.Fixed - || schedulerActType.getDurationType() instanceof DurationType.Parametric - ) { - // Do nothing + } else if (schedulerActType.getDurationType() instanceof DurationType.Fixed fixedDurationType) { + actDuration = fixedDurationType.duration(); + } else if(schedulerActType.getDurationType() instanceof DurationType.Parametric parametricDurationType) { + actDuration = parametricDurationType.durationFunction().apply(activity.serializedActivity().getArguments()); + } else if(schedulerActType.getDurationType() instanceof DurationType.Uncontrollable) { + if(initialSimulationResults.isPresent()){ + for(final var simAct: initialSimulationResults.get().simulatedActivities.entrySet()){ + if(simAct.getValue().directiveId().isPresent() && + simAct.getValue().directiveId().get().equals(elem.getKey())){ + actDuration = simAct.getValue().duration(); + } + } + } } else { throw new Error("Unhandled variant of DurationType:" + schedulerActType.getDurationType()); }