Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Procedural Scheduling activity deletion #1610

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Prev Previous commit
Next Next commit
Add doc comments
JoelCourtney committed Dec 11, 2024
commit d2fea830044ecc71ef12d9164c36e2ec8258604c
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
package gov.nasa.ammos.aerie.procedural.scheduling.plan

/**
* How to handle directives anchored to a deleted activity.
*
* If you intend to delete an activity that you believe has nothing anchored to it,
* using [Error] is recommended. This is the default.
*/
enum class DeletedAnchorStrategy {
Error,
Cascade,
/** Throw an error. */ Error,
/** Recursively delete everything in the anchor chain. */ Cascade,

/**
* Attempt to delete the activity in-place without changing the start times
* of any activities anchored to it.
*
* Consider the anchor chain `A <- B <- C`, where `A` starts at an absolute time and
* `B` and `C` are anchored.
* - If `A` is deleted with [ReAnchor], `B` will be set to start at the absolute time `A.startTime + B.offset`.
* `C` will be unchanged.
* - If `B` is deleted with [ReAnchor], `C` will be anchored to `A` with a new offset equal to `B.offset + C.offset`.
*
* If an activity is anchored to the end of the deleted activity, the delete activity's duration is assumed to be 0,
* which may change the ultimate start time of the anchored activity.
*/
ReAnchor,
}
Original file line number Diff line number Diff line change
@@ -7,9 +7,14 @@ import gov.nasa.jpl.aerie.types.ActivityDirectiveId
/**
* Edits that can be made to the plan.
*
* Currently only creating new activities is supported.
* All edits are invertible.
*/
sealed interface Edit {
/**
* Returns the reverse operation.
*
* If both `E` and `E.inverse()` are applied, the plan is unchanged.
*/
fun inverse(): Edit

/** Create a new activity from a given directive. */
Original file line number Diff line number Diff line change
@@ -126,8 +126,13 @@ abstract class EasyEditablePlanDriver(
)

private var committedChanges = Commit(setOf(), mutableSetOf())
var uncommittedChanges = mutableListOf<Edit>()
private var uncommittedChanges = mutableListOf<Edit>()

/** Whether there are uncommitted changes. */
val isDirty
get() = uncommittedChanges.isNotEmpty()

/** The total reduced set of changes made to the plan. */
val totalDiff: Set<Edit>
get() = committedChanges.diff

Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package gov.nasa.ammos.aerie.procedural.scheduling.utils

import gov.nasa.ammos.aerie.procedural.timeline.plan.SimulationResults

/** Simulation results whose staleness can be changed after creation. */
interface PerishableSimulationResults: SimulationResults {
fun setStale(stale: Boolean)
/***/ fun setStale(stale: Boolean)
}
Original file line number Diff line number Diff line change
@@ -37,6 +37,8 @@ interface SimulationResults {
/** Queries all activity instances, deserializing them as [AnyInstance]. **/
fun instances() = instances(null, AnyInstance.deserializer())

/** The input directives that were used for this simulation. */
fun <A: Any> inputDirectives(deserializer: (SerializedValue) -> A): Directives<A>
/** The input directives that were used for this simulation, deserialized as [AnyDirective]. */
fun inputDirectives() = inputDirectives(AnyDirective.deserializer())
}
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ public void run(

procedureMapper.deserialize(SerializedValue.of(this.args)).run(editablePlan);

if (!editablePlan.getUncommittedChanges().isEmpty()) {
if (editablePlan.isDirty()) {
throw new IllegalStateException("procedural goal %s had changes that were not committed or rolled back".formatted(jarPath.getFileName()));
}
for (final var edit : editablePlan.getTotalDiff()) {