Skip to content

Commit

Permalink
Remove schedulingActivity.isNew()
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelCourtney committed Feb 3, 2025
1 parent 1829f67 commit 81f23aa
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void run(
}
for (final var edit : editablePlan.getTotalDiff()) {
if (edit instanceof Edit.Create c) {
newActivities.add(toSchedulingActivity(c.getDirective(), lookupActivityType::apply, true));
newActivities.add(toSchedulingActivity(c.getDirective(), lookupActivityType::apply));
} else if (!(edit instanceof Edit.Delete)) {
throw new IllegalStateException("Unexpected edit type: " + edit);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
* @param duration the length of time this activity instances lasts for after its start
* @param arguments arguments are stored in a String/SerializedValue hashmap.
* @param topParent the parent activity if any
* @param isNew whether this activity was created in this scheduling run, or already existed in the plan
*/
public record SchedulingActivity(
ActivityDirectiveId id,
Expand All @@ -41,7 +40,6 @@ public record SchedulingActivity(
ActivityDirectiveId topParent,
ActivityDirectiveId anchorId,
boolean anchoredToStart,
boolean isNew,
String name
) {

Expand All @@ -51,8 +49,7 @@ public static SchedulingActivity of(
Duration startOffset,
Duration duration,
ActivityDirectiveId anchorId,
boolean anchoredToStart,
boolean isNew
boolean anchoredToStart
) {
return new SchedulingActivity(
id,
Expand All @@ -63,7 +60,6 @@ public static SchedulingActivity of(
null,
anchorId,
anchoredToStart,
isNew,
null
);
}
Expand All @@ -76,8 +72,7 @@ public static SchedulingActivity of(
Map<String, SerializedValue> parameters,
ActivityDirectiveId topParent,
ActivityDirectiveId anchorId,
boolean anchoredToStart,
boolean isNew
boolean anchoredToStart
) {
return new SchedulingActivity(
id,
Expand All @@ -88,7 +83,6 @@ public static SchedulingActivity of(
topParent,
anchorId,
anchoredToStart,
isNew,
null
);
}
Expand All @@ -103,7 +97,6 @@ public SchedulingActivity withNewDuration(Duration duration){
this.topParent,
this.anchorId,
this.anchoredToStart,
this.isNew(),
this.name
);
}
Expand All @@ -118,7 +111,6 @@ public SchedulingActivity withNewAnchor(ActivityDirectiveId anchorId, boolean an
this.topParent,
anchorId,
anchoredToStart,
this.isNew,
this.name
);
}
Expand All @@ -133,7 +125,6 @@ public SchedulingActivity withNewDirectiveId(ActivityDirectiveId id) {
this.topParent,
this.anchorId,
this.anchoredToStart,
this.isNew,
this.name
);
}
Expand All @@ -148,7 +139,6 @@ public SchedulingActivity withNewTopParent(ActivityDirectiveId topParent) {
topParent,
this.anchorId,
this.anchoredToStart,
this.isNew,
this.name
);
}
Expand All @@ -163,7 +153,6 @@ public static SchedulingActivity fromExistingActivityDirective(ActivityDirective
null,
activity.anchorId(),
activity.anchoredToStart(),
false,
null
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ public static void updatePlanWithChildActivities(
activity.arguments(),
rootParent.get(),
null,
true,
false
true
);
plan.add(activityInstance);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,6 @@ public Duration valueAt(Duration start, final EquationSolvingAlgorithms.History<
null,
null,
true,
true,
null
);
Duration computedDuration = null;
Expand Down Expand Up @@ -1299,7 +1298,6 @@ public Duration valueAt(Duration start, final EquationSolvingAlgorithms.History<
instantiatedArguments,
null,
null,
true,
true
));
} else if (activityExpression.type().getDurationType() instanceof DurationType.Fixed dt) {
Expand All @@ -1323,7 +1321,6 @@ public Duration valueAt(Duration start, final EquationSolvingAlgorithms.History<
activityExpression.type()),
null,
null,
true,
true
));
} else if (activityExpression.type().getDurationType() instanceof DurationType.Parametric dt) {
Expand All @@ -1349,7 +1346,6 @@ public Duration valueAt(final Duration start, final EquationSolvingAlgorithms.Hi
instantiatedArgs,
null,
null,
true,
true
);
history.add(new EquationSolvingAlgorithms.FunctionCoordinate<>(start, start.plus(duration)), new ActivityMetadata(activity));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ data class SchedulerPlanEditAdapter(
}

override fun create(directive: Directive<AnyDirective>) {
plan.add(directive.toSchedulingActivity(lookupActivityType, true))
plan.add(directive.toSchedulingActivity(lookupActivityType))
}

override fun delete(id: ActivityDirectiveId) {
Expand All @@ -53,7 +53,7 @@ data class SchedulerPlanEditAdapter(
}

companion object {
@JvmStatic fun Directive<AnyDirective>.toSchedulingActivity(lookupActivityType: (String) -> ActivityType, isNew: Boolean) = SchedulingActivity(
@JvmStatic fun Directive<AnyDirective>.toSchedulingActivity(lookupActivityType: (String) -> ActivityType) = SchedulingActivity(
id,
lookupActivityType(type),
when (val s = start) {
Expand Down Expand Up @@ -82,7 +82,6 @@ data class SchedulerPlanEditAdapter(
is DirectiveStart.Absolute -> true
is DirectiveStart.Anchor -> s.anchorPoint == DirectiveStart.Anchor.AnchorPoint.Start
},
isNew,
name
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ private static PlanInMemory makePlanA012(Problem problem) {
final var plan = new PlanInMemory();
final var actTypeA = problem.getActivityType("GrowBanana");
final var idGenerator = new DirectiveIdGenerator(0);
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeA, t0, d1min, null, true, false));
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeA, t1year, d1min, null, true, false));
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeA, t2year, d1min, null, true, false));
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeA, t3year, d1min, null, true, false));
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeA, t0, d1min, null, true));
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeA, t1year, d1min, null, true));
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeA, t2year, d1min, null, true));
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeA, t3year, d1min, null, true));
return plan;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,26 @@ private static Problem makeTestMissionAB() {
private static PlanInMemory makePlanA012(Problem problem) {
final var plan = new PlanInMemory();
final var actTypeA = problem.getActivityType("ControllableDurationActivity");
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeA, t0, d1min, null, true, false));
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeA, t1hr, d1min, null, true, false));
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeA, t2hr, d1min, null, true, false));
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeA, t0, d1min, null, true));
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeA, t1hr, d1min, null, true));
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeA, t2hr, d1min, null, true));
return plan;
}

private static PlanInMemory makePlanA12(Problem problem) {
final var plan = new PlanInMemory();
final var actTypeA = problem.getActivityType("ControllableDurationActivity");
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeA, t1hr, d1min, null, true, false));
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeA, t2hr, d1min, null, true, false));
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeA, t1hr, d1min, null, true));
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeA, t2hr, d1min, null, true));
return plan;
}

private static PlanInMemory makePlanAB012(Problem problem) {
final var plan = makePlanA012(problem);
final var actTypeB = problem.getActivityType("OtherControllableDurationActivity");
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeB, t0, d1min, null, true, false));
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeB, t1hr, d1min, null, true, false));
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeB, t2hr, d1min, null, true, false));
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeB, t0, d1min, null, true));
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeB, t1hr, d1min, null, true));
plan.add(SchedulingActivity.of(idGenerator.next(), actTypeB, t2hr, d1min, null, true));
return plan;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public void testChainAnchors(){
final var id1 = new ActivityDirectiveId(1);
final var id2 = new ActivityDirectiveId(2);
final var id3 = new ActivityDirectiveId(3);
final var act1 = SchedulingActivity.of(id1, at, t0, d1min, null, true, false);
final var act2 = SchedulingActivity.of(id2, at, t1hr, d1min, act1.id(), false, false);
final var act3 = SchedulingActivity.of(id3, at, t2hr, d1min, act2.id(), false, false);
final var act1 = SchedulingActivity.of(id1, at, t0, d1min, null, true);
final var act2 = SchedulingActivity.of(id2, at, t1hr, d1min, act1.id(), false);
final var act3 = SchedulingActivity.of(id3, at, t2hr, d1min, act2.id(), false);
final var acts = List.of(act1, act3, act2);
final var result = SchedulePlanGrounder.groundSchedule(acts, h.getEndAerie());
//act 1 should start at 0 min into the plan
Expand All @@ -51,7 +51,7 @@ public void testChainAnchors(){
public void testEmptyDueToEmptyDuration(){
final var at = new ActivityType("at");
final var id1 = new ActivityDirectiveId(1);
final var act1 = SchedulingActivity.of(id1, at, t0, null, null, true, false);
final var act1 = SchedulingActivity.of(id1, at, t0, null, null, true);
final var result = SchedulePlanGrounder.groundSchedule(List.of(act1), h.getEndAerie());
assertTrue(result.isEmpty());
}
Expand All @@ -60,7 +60,7 @@ public void testEmptyDueToEmptyDuration(){
public void testAnchoredToPlanEnd(){
final var at = new ActivityType("at");
final var id1 = new ActivityDirectiveId(1);
final var act1 = SchedulingActivity.of(id1, at, Duration.negate(d1hr), d1min, null, false, false);
final var act1 = SchedulingActivity.of(id1, at, Duration.negate(d1hr), d1min, null, false);
final var result = SchedulePlanGrounder.groundSchedule(List.of(act1), h.getEndAerie());
final var act1expt = new ActivityInstance(id1.id(), at.getName(), Map.of(), Interval.between(h.getEndAerie().minus(d1hr), h.getEndAerie().minus(d1hr).plus(d1min)), Optional.of(id1));
assertEquals(act1expt, result.get().get(0));
Expand All @@ -72,8 +72,8 @@ public void noAnchor(){
final var at = new ActivityType("at");
final var id1 = new ActivityDirectiveId(1);
final var id2 = new ActivityDirectiveId(2);
final var act1 = SchedulingActivity.of(id1, at, t0, d1min, null, true, false);
final var act2 = SchedulingActivity.of(id2, at, t1hr, d1min, null, true, false);
final var act1 = SchedulingActivity.of(id1, at, t0, d1min, null, true);
final var act2 = SchedulingActivity.of(id2, at, t1hr, d1min, null, true);
final var result = SchedulePlanGrounder.groundSchedule(List.of(act1, act2), h.getEndAerie());
final var act1expt = new ActivityInstance(id1.id(), at.getName(), Map.of(), Interval.between(t0, t0.plus(d1min)), Optional.of(id1));
final var act2expt = new ActivityInstance(id2.id(), at.getName(), Map.of(), Interval.between(t1hr, t1hr.plus(d1min)), Optional.of(id2));
Expand All @@ -86,8 +86,8 @@ public void startTimeAnchor(){
final var at = new ActivityType("at");
final var id1 = new ActivityDirectiveId(1);
final var id2 = new ActivityDirectiveId(2);
final var act1 = SchedulingActivity.of(id1, at, t1hr, d1min, null, true, false);
final var act2 = SchedulingActivity.of(id2, at, t1hr, d1min, act1.id(), true, false);
final var act1 = SchedulingActivity.of(id1, at, t1hr, d1min, null, true);
final var act2 = SchedulingActivity.of(id2, at, t1hr, d1min, act1.id(), true);
final var result = SchedulePlanGrounder.groundSchedule(List.of(act1, act2), h.getEndAerie());
final var act1expt = new ActivityInstance(id1.id(), at.getName(), Map.of(), Interval.between(t1hr, t1hr.plus(d1min)), Optional.of(id1));
final var act2expt = new ActivityInstance(id2.id(), at.getName(), Map.of(), Interval.between(t2hr, t2hr.plus(d1min)), Optional.of(id2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ private PlanInMemory makeTestPlanP0B1() {
final var actTypeBite = problem.getActivityType("BiteBanana");
final var actTypePeel = problem.getActivityType("PeelBanana");

var act1 = SchedulingActivity.of(idGenerator.next(), actTypePeel, t1, null, Map.of("peelDirection", SerializedValue.of("fromStem")), null, null, true, false);
var act1 = SchedulingActivity.of(idGenerator.next(), actTypePeel, t1, null, Map.of("peelDirection", SerializedValue.of("fromStem")), null, null, true);
plan.add(act1);

var act2 = SchedulingActivity.of(idGenerator.next(), actTypeBite, t2, null, Map.of("biteSize", SerializedValue.of(0.1)), null, null, true, false);
var act2 = SchedulingActivity.of(idGenerator.next(), actTypeBite, t2, null, Map.of("biteSize", SerializedValue.of(0.1)), null, null, true);
plan.add(act2);

return plan;
Expand All @@ -131,7 +131,7 @@ public void associationToExistingSatisfyingActivity() throws SchedulingInterrupt
final var actTypePeel = problem.getActivityType("PeelBanana");
final var actTypeBite = problem.getActivityType("BiteBanana");

var act1 = SchedulingActivity.of(idGenerator.next(), actTypePeel, t1, t2, Map.of("peelDirection", SerializedValue.of("fromStem")), null, null, true, false);
var act1 = SchedulingActivity.of(idGenerator.next(), actTypePeel, t1, t2, Map.of("peelDirection", SerializedValue.of("fromStem")), null, null, true);
plan.add(act1);

final var goal = new CoexistenceGoal.Builder()
Expand Down Expand Up @@ -284,10 +284,10 @@ public void testProceduralGoalWithResourceConstraint() throws SchedulingInterrup
final var actTypePeel = problem.getActivityType("PeelBanana");

SchedulingActivity act1 = SchedulingActivity.of(idGenerator.next(), actTypePeel,
t0, Duration.ZERO, Map.of(), null, null, true, false);
t0, Duration.ZERO, Map.of(), null, null, true);

SchedulingActivity act2 = SchedulingActivity.of(idGenerator.next(), actTypePeel,
t2, Duration.ZERO, Map.of(), null, null, true, false);
t2, Duration.ZERO, Map.of(), null, null, true);

//create an "external tool" that insists on a few fixed activities
final var externalActs = java.util.List.of(
Expand Down Expand Up @@ -326,10 +326,10 @@ public void testActivityTypeWithResourceConstraint() throws SchedulingInterrupte
actTypePeel.setResourceConstraint(constraint);

SchedulingActivity act1 = SchedulingActivity.of(idGenerator.next(), actTypePeel,
t0, Duration.ZERO, Map.of(), null, null, true, false);
t0, Duration.ZERO, Map.of(), null, null, true);

SchedulingActivity act2 = SchedulingActivity.of(idGenerator.next(), actTypePeel,
t2, Duration.ZERO, Map.of(), null, null, true, false);
t2, Duration.ZERO, Map.of(), null, null, true);

//create an "external tool" that insists on a few fixed activities
final var externalActs = java.util.List.of(
Expand Down
Loading

0 comments on commit 81f23aa

Please sign in to comment.