Skip to content

Commit

Permalink
Merge pull request #1485 from NASA-AMMOS/1378-coexistence-goal-bug
Browse files Browse the repository at this point in the history
Bug fix for coexistence goal valueAt usage
  • Loading branch information
adrienmaillard authored Jul 18, 2024
2 parents 533a2ee + 6ae6953 commit 4f8a893
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public DiscreteProfile evaluate(
final Interval bounds,
final EvaluationEnvironment environment)
{
final var res = this.profile.evaluate(results, bounds, environment);
final var time = timepoint.evaluate(results, bounds, environment);
final var time = timepoint.evaluate(results, Interval.FOREVER, environment);
final var timepoint = time.iterator().next().interval().start;
final var res = this.profile.evaluate(results, Interval.at(timepoint), environment);
//REVIEW: SHOULD ASSERT A BUNCH OF THINGS HERE SO IT IS NOT WRONGLY USED
final var value = res.valueAt(timepoint);
if(value.isEmpty()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,12 @@ void testSingleActivityPlanSimpleCoexistenceGoalWithValueAtParams() {
BANANANATION,
List.of(new ActivityDirective(
Duration.ZERO,
"GrowBanana",
Map.of(
"quantity", SerializedValue.of(3),
"growingDuration", SerializedValue.of(growBananaDuration.in(Duration.MICROSECONDS))),
null,
true)),
"GrowBanana",
Map.of(
"quantity", SerializedValue.of(3),
"growingDuration", SerializedValue.of(growBananaDuration.in(Duration.MICROSECONDS))),
null,
true)),
List.of(new SchedulingGoal(new GoalId(0L, 0L), """
export default () => Goal.CoexistenceGoal({
forEach: ActivityExpression.ofType(ActivityTypes.GrowBanana),
Expand Down Expand Up @@ -440,6 +440,54 @@ export default () => Goal.CoexistenceGoal({
}
}

/**
* Here the anchor window is [01:00:00, plan end]. The coexisting activity starts at 00:55:00 and the `valueAt` interval for
* the parametric parameter is then outside of the anchor window causing the intervals not to intersect as the valueAt
* was evaluated only in the start ([00:55:00, 00:55:00]) interval. Now, it is evaluated in Interval.FOREVER. Determining
* the right bounds for simulation is the scheduler's responsability (upstream of the goal conflict evaluation).
*/
@Test
void testBugValueAt() {
final var growBananaDuration = Duration.of(1, Duration.HOUR);
final var results = runScheduler(
BANANANATION,
List.of(new ActivityDirective(
Duration.HOUR,
"GrowBanana",
Map.of(
"quantity", SerializedValue.of(3),
"growingDuration", SerializedValue.of(growBananaDuration.in(Duration.MICROSECONDS))),
null,
true),
new ActivityDirective(
Duration.MINUTE.times(50),
"ChangeProducer",
Map.of(
"producer", SerializedValue.of("Company")),
null,
true)),
List.of(new SchedulingGoal(new GoalId(0L, 0L), """
export default () => Goal.CoexistenceGoal({
forEach: Real.Resource("/fruit").greaterThan(4.0),
activityTemplate: interval => ActivityTemplates.ChangeProducer({producer: Discrete.Resource("/producer").valueAt(Spans.FromInterval(interval).starts())}),
startsAt: TimingConstraint.singleton(WindowProperty.START).minus(Temporal.Duration.from({ minutes : 5}))
})
""", true)),
PLANNING_HORIZON);

assertEquals(1, results.scheduleResults.goalResults().size());
final var goalResult = results.scheduleResults.goalResults().get(new GoalId(0L, 0L));

assertTrue(goalResult.satisfied());
assertEquals(1, goalResult.createdActivities().size());
assertEquals(1, goalResult.satisfyingActivities().size());
final var activityCreated = results.updatedPlan
.stream()
.filter(a -> a.startOffset().isEqualTo(Duration.MINUTES.times(55)))
.collect(Collectors.toSet());
assertEquals(1, activityCreated.size());
assertEquals(new SerializedValue.StringValue("Company"), activityCreated.iterator().next().serializedActivity().getArguments().get("producer"));
}

@Test
void testCoexistenceGoalWithAnchors() {
Expand Down

0 comments on commit 4f8a893

Please sign in to comment.