Skip to content

Commit

Permalink
Merge pull request #1159 from NASA-AMMOS/add-padding-coexistence
Browse files Browse the repository at this point in the history
Add justAfter and justBefore operators to scheduling eDSL
  • Loading branch information
adrienmaillard authored Oct 4, 2023
2 parents e72ed05 + e1465c7 commit fca5c57
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ private ActivityDirective schedulingActToActivityDir(SchedulingActivityDirective
}
}
final var serializedActivity = new SerializedActivity(activity.getType().getName(), arguments);
if(activity.anchorId()!= null && !planActDirectiveIdToSimulationActivityDirectiveId.containsKey(activity.anchorId())){
throw new RuntimeException("Activity with id "+ activity.anchorId() + " referenced as an anchor by activity " + activity.toString() + " is not present in the plan");
}
return new ActivityDirective(
activity.startOffset(),
serializedActivity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ public static gov.nasa.jpl.aerie.constraints.model.ActivityInstance convertToCon
{
final var startT = Duration.of(startTime.until(driverActivity.start(), ChronoUnit.MICROS), MICROSECONDS);
final var endT = startT.plus(driverActivity.duration());
final var activityInterval = startT.isEqualTo(endT)
? Interval.between(startT, endT)
: Interval.betweenClosedOpen(startT, endT);
final var activityInterval = Interval.between(startT, endT);
return new gov.nasa.jpl.aerie.constraints.model.ActivityInstance(
id, driverActivity.type(), driverActivity.arguments(),
activityInterval);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,8 @@ public void testCoexistenceWindows() {

assertTrue(TestUtility.activityStartingAtTime(plan.get(), Duration.of(1, Duration.SECONDS), actTypeA));
assertTrue(TestUtility.activityStartingAtTime(plan.get(), Duration.of(14, Duration.SECONDS), actTypeA));
assertEquals(3, problem.getSimulationFacade().countSimulationRestarts());
assertTrue(TestUtility.activityStartingAtTime(plan.get(), Duration.of(12, Duration.SECONDS), actTypeA));
assertEquals(4, problem.getSimulationFacade().countSimulationRestarts());
}

@Test
Expand Down Expand Up @@ -971,12 +972,13 @@ public void testCoexistenceWindowsCutoffMidActivity() {
for(SchedulingActivityDirective a : plan.get().getActivitiesByTime()){
logger.debug(a.startOffset().toString() + ", " + a.duration().toString());
}

assertEquals(10, plan.get().getActivitiesById().size());
assertTrue(TestUtility.activityStartingAtTime(plan.get(), Duration.of(2, Duration.SECONDS), actTypeB));
assertTrue(TestUtility.activityStartingAtTime(plan.get(), Duration.of(10, Duration.SECONDS), actTypeB));
assertTrue(TestUtility.activityStartingAtTime(plan.get(), Duration.of(16, Duration.SECONDS), actTypeB));
assertTrue(TestUtility.activityStartingAtTime(plan.get(), Duration.of(23, Duration.SECONDS), actTypeB));
assertTrue(TestUtility.activityStartingAtTime(plan.get(), Duration.of(25, Duration.SECONDS), actTypeB));
assertEquals(5, problem.getSimulationFacade().countSimulationRestarts());
assertEquals(6, problem.getSimulationFacade().countSimulationRestarts());
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion scheduler-worker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ dependencies {
testImplementation project(':examples:foo-missionmodel')
testImplementation testFixtures(project(':scheduler-server'))
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.10.0'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.0'
testImplementation 'org.assertj:assertj-core:3.24.2'
testImplementation 'junit:junit:4.13.2'
testImplementation 'javax.json.bind:javax.json.bind-api:1.0'
testImplementation 'org.glassfish:javax.json:1.1.4'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,9 @@ export class ActivityExpression<T extends WindowsEDSL.Gen.ActivityType> {
}

export class TimingConstraint {

public static defaultPadding: Temporal.Duration = Temporal.Duration.from({microseconds:1});

/** @internal **/
private constructor() {}
/**
Expand Down Expand Up @@ -633,6 +636,23 @@ export class TimingConstraint {
singleton: false
})
}

/**
* Represents a precise time point at a defined offset (default: 1 microseconds, can be modified) from the start or end of a window.
* Equivalent to TimingConstraint.singleton(windowProperty).plus(TimingConstraint.defaultPadding)
* @param windowProperty either WindowProperty.START or WindowProperty.END
*/
public static justAfter(windowProperty: WindowProperty): SingletonTimingConstraint {
return this.singleton(windowProperty).plus(this.defaultPadding);
}
/**
* Represents a precise time point at a defined offset (default: -1 microseconds, can be modified) from the start or end of a window.
* Equivalent to TimingConstraint.singleton(windowProperty).minus(TimingConstraint.defaultPadding)
* @param windowProperty either WindowProperty.START or WindowProperty.END
*/
public static justBefore(windowProperty: WindowProperty): SingletonTimingConstraint {
return this.singleton(windowProperty).minus(this.defaultPadding);
}
}

/**
Expand Down Expand Up @@ -837,6 +857,7 @@ declare global {
matchingArgs: WindowsEDSL.Gen.ActivityTypeParameterMapWithUndefined[T]): ActivityExpression<T>
}
class TimingConstraint {
public static defaultPadding: Temporal.Duration;
/**
* The singleton timing constraint represents a precise time point
* at some offset from either the start or end of a window.
Expand All @@ -862,6 +883,18 @@ declare global {
* @param upperBound represents the (inclusive) upper bound of the time interval
*/
public static bounds(lowerBound: SingletonTimingConstraint, upperBound: SingletonTimingConstraint): FlexibleRangeTimingConstraint
/**
* Represents a precise time point at a defined offset (default: 1 microseconds, can be modified) from the start or end of a window.
* Equivalent to TimingConstraint.singleton(windowProperty).plus(TimingConstraint.defaultPadding)
* @param windowProperty either WindowProperty.START or WindowProperty.END
*/
public static justAfter(windowProperty: WindowProperty): SingletonTimingConstraint
/**
* Represents a precise time point at a defined offset (default: -1 microseconds, can be modified) from the start or end of a window.
* Equivalent to TimingConstraint.singleton(windowProperty).minus(TimingConstraint.defaultPadding)
* @param windowProperty either WindowProperty.START or WindowProperty.END
*/
public static justBefore(windowProperty: WindowProperty): SingletonTimingConstraint
}
var WindowProperty: typeof AST.WindowProperty
var Operator: typeof AST.TimingConstraintOperator
Expand Down
Loading

0 comments on commit fca5c57

Please sign in to comment.