Skip to content

Commit

Permalink
Adding EDSL syntax for PersistentTimeAnchor
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdelfa authored and dandelany committed Jun 7, 2024
1 parent 52ceee2 commit eeeba43
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public interface Function8<Result, T1, T2, T3, T4, T5, T6, T7, T8> {
Result apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8);
}

public interface Function9<Result, T1, T2, T3, T4, T5, T6, T7, T8, T9> {
Result apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9);
}

public static <Result, T1>
Function<T1, Result>
Expand Down Expand Up @@ -129,6 +132,20 @@ public interface Function8<Result, T1, T2, T3, T4, T5, T6, T7, T8> {
p.getRight());
}

public static <Result, T1, T2, T3, T4, T5, T6, T7, T8, T9>
Function<Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<T1, T2>, T3>, T4>, T5>, T6>, T7>, T8>, T9>, Result>
untuple(Function9<Result, T1, T2, T3, T4, T5, T6, T7, T8, T9> f) {
return p -> f.apply(
p.getLeft().getLeft().getLeft().getLeft().getLeft().getLeft().getLeft().getLeft(),
p.getLeft().getLeft().getLeft().getLeft().getLeft().getLeft().getLeft().getRight(),
p.getLeft().getLeft().getLeft().getLeft().getLeft().getLeft().getRight(),
p.getLeft().getLeft().getLeft().getLeft().getLeft().getRight(),
p.getLeft().getLeft().getLeft().getLeft().getRight(),
p.getLeft().getLeft().getLeft().getRight(),
p.getLeft().getLeft().getRight(),
p.getLeft().getRight(),
p.getRight());
}

public static <T1>
T1
Expand Down Expand Up @@ -177,4 +194,10 @@ public interface Function8<Result, T1, T2, T3, T4, T5, T6, T7, T8> {
tuple(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) {
return tuple(tuple(tuple(tuple(tuple(tuple(tuple(t1, t2), t3), t4), t5), t6), t7), t8);
}

public static <T1, T2, T3, T4, T5, T6, T7, T8, T9>
Pair<Pair<Pair<Pair<Pair<Pair<Pair<Pair<T1, T2>, T3>, T4>, T5>, T6>, T7>, T8>, T9>
tuple(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) {
return tuple(tuple(tuple(tuple(tuple(tuple(tuple(tuple(t1, t2), t3), t4), t5), t6), t7), t8), t9);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import gov.nasa.jpl.aerie.merlin.protocol.types.Duration;
import gov.nasa.jpl.aerie.scheduler.TimeUtility;
import gov.nasa.jpl.aerie.scheduler.constraints.timeexpressions.TimeAnchor;
import gov.nasa.jpl.aerie.scheduler.model.PersistentTimeAnchor;
import gov.nasa.jpl.aerie.scheduler.server.http.ActivityTemplateJsonParser;
import gov.nasa.jpl.aerie.scheduler.server.services.MerlinService;
import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -117,6 +118,7 @@ private static JsonObjectParser<GoalSpecifier.CoexistenceGoalDefinition> coexist
return
productP
.field("activityTemplate", new ActivityTemplateJsonParser(activityTypes))
.optionalField("persistentAnchor",enumP(PersistentTimeAnchor.class, Enum::name))
.optionalField("activityFinder", activityExpressionP)
.field("alias", stringP)
.field("forEach", constraintExpressionP)
Expand All @@ -131,12 +133,11 @@ private static JsonObjectParser<GoalSpecifier.CoexistenceGoalDefinition> coexist
*/
@SuppressWarnings("unchecked")
private static <T1 extends TimingConstraint, T2 extends TimingConstraint>
Convert<
Pair<Pair<Pair<Pair<Pair<Pair<ActivityTemplate, Optional<ConstraintExpression.ActivityExpression>>, String>, ConstraintExpression>, Optional<T1>>, Optional<T2>>, Boolean>,
GoalSpecifier.CoexistenceGoalDefinition>
Convert<Pair<Pair<Pair<Pair<Pair<Pair<Pair<ActivityTemplate, Optional<PersistentTimeAnchor>>, Optional<ConstraintExpression.ActivityExpression>>, String>, ConstraintExpression>, Optional<T1>>, Optional<T2>>, Boolean>, GoalSpecifier.CoexistenceGoalDefinition>
coexistenceGoalTransform() {
return Convert.between(untuple(GoalSpecifier.CoexistenceGoalDefinition::new), (GoalSpecifier.CoexistenceGoalDefinition $) -> tuple(
$.activityTemplate(),
$.persistentAnchor(),
$.activityFinder(),
$.alias,
$.forEach,
Expand Down Expand Up @@ -268,6 +269,7 @@ record RecurrenceGoalDefinition(
) implements GoalSpecifier {}
record CoexistenceGoalDefinition(
ActivityTemplate activityTemplate,
Optional<PersistentTimeAnchor> persistentAnchor,
Optional<ConstraintExpression.ActivityExpression> activityFinder,
String alias,
ConstraintExpression forEach,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

import * as AST from "./scheduler-ast.js";
import * as WindowsEDSL from "./constraints-edsl-fluent-api.js";
import {PersistentTimeAnchor} from "./scheduler-ast.js";
import * as WindowsEDSL from "./constraints-edsl-fluent-api.js";
import {ActivityInstance} from "./constraints-edsl-fluent-api.js";
import * as ConstraintsAST from "./constraints-ast.js";
import {makeArgumentsDiscreteProfiles} from "./scheduler-mission-model-generated-code";
Expand Down Expand Up @@ -387,6 +388,7 @@ export class Goal {
activityFinder?: ActivityExpression<B>
} | {
activityTemplate: (( span: ActivityInstance<T> ) => ActivityTemplate<S>) | ActivityTemplate<S>,
persistentAnchor?: PersistentTimeAnchor,
forEach: ActivityExpression<T>,
activityFinder?: ActivityExpression<B>
}) & CoexistenceGoalTimingConstraints): Goal {
Expand Down Expand Up @@ -424,10 +426,19 @@ export class Goal {
activityTemplate = opts.activityTemplate;
}

let PersistentAnchortmp: PersistentTimeAnchor;

if ((opts as {persistentAnchor: PersistentTimeAnchor}).persistentAnchor !== undefined)
PersistentAnchortmp = (opts as {persistentAnchor: PersistentTimeAnchor}).persistentAnchor;
else
PersistentAnchortmp = PersistentTimeAnchor.DISABLED;


return Goal.new({
kind: AST.NodeKind.ActivityCoexistenceGoal,
alias: alias,
activityTemplate: activityTemplate,
persistentAnchor: PersistentAnchortmp,
activityFinder: opts.activityFinder?.__astNode,
forEach: localForEach.__astNode,
startConstraint: (("startsAt" in opts) ? opts.startsAt.__astNode : ("startsWithin" in opts) ? opts.startsWithin.__astNode : undefined),
Expand Down Expand Up @@ -817,15 +828,16 @@ declare global {
* The CoexistenceGoal places one activity (defined by activityTemplate) per window (defined by forEach).
* The activity is placed such that it starts at (startsAt) or ends at (endsAt) a certain offset from the window
*/
public static CoexistenceGoal <
public static CoexistenceGoal<
T extends WindowsEDSL.Gen.ActivityType,
S extends WindowsEDSL.Gen.ActivityType,
B extends WindowsEDSL.Gen.ActivityType>(opts: ({
activityTemplate: (( interval: WindowsEDSL.Interval ) => ActivityTemplate<S>) | ActivityTemplate<S>,
forEach: WindowsEDSL.Windows,
forEach: WindowsEDSL.Windows | WindowsEDSL.Interval | Temporal.Instant,
activityFinder?: ActivityExpression<B>
} | {
activityTemplate: (( span: ActivityInstance<T> ) => ActivityTemplate<S>) | ActivityTemplate<S>,
persistentAnchor?: PersistentTimeAnchor,
forEach: ActivityExpression<T>,
activityFinder?: ActivityExpression<B>
}) & CoexistenceGoalTimingConstraints): Goal
Expand Down Expand Up @@ -899,6 +911,7 @@ declare global {
var WindowProperty: typeof AST.WindowProperty
var Operator: typeof AST.TimingConstraintOperator
var ActivityTypes: typeof WindowsEDSL.Gen.ActivityType
var PersistentTimeAnchor: typeof AST.PersistentTimeAnchor

type Double = number;
type Integer = number;
Expand All @@ -923,6 +936,7 @@ Object.assign(globalThis,
GlobalSchedulingCondition,
Goal,
ActivityExpression,
PersistentTimeAnchor: AST.PersistentTimeAnchor,
TimingConstraint: TimingConstraint,
WindowProperty: AST.WindowProperty,
Operator: AST.TimingConstraintOperator,
Expand Down

0 comments on commit eeeba43

Please sign in to comment.