-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1007 from NASA-AMMOS/830-add-shift-operation-for-…
…profiles-to-edsl Shift operation for profiles
- Loading branch information
Showing
20 changed files
with
391 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 17 additions & 35 deletions
52
constraints/src/main/java/gov/nasa/jpl/aerie/constraints/tree/ShiftBy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,41 @@ | ||
package gov.nasa.jpl.aerie.constraints.tree; | ||
|
||
import gov.nasa.jpl.aerie.constraints.model.EvaluationEnvironment; | ||
import gov.nasa.jpl.aerie.constraints.model.Profile; | ||
import gov.nasa.jpl.aerie.constraints.model.SimulationResults; | ||
import gov.nasa.jpl.aerie.constraints.time.Interval; | ||
import gov.nasa.jpl.aerie.constraints.time.Windows; | ||
import gov.nasa.jpl.aerie.merlin.protocol.types.Duration; | ||
|
||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
public final class ShiftBy implements Expression<Windows> { | ||
public final Expression<Windows> windows; | ||
public final Expression<Duration> fromStart; | ||
public final Expression<Duration> fromEnd; | ||
|
||
public ShiftBy(final Expression<Windows> left, final Expression<Duration> fromStart, final Expression<Duration> fromEnd) { | ||
this.windows = left; | ||
this.fromStart = fromStart; | ||
this.fromEnd = fromEnd; | ||
} | ||
public record ShiftBy<P extends Profile<P>>( | ||
Expression<P> expression, | ||
Expression<Duration> duration) implements Expression<P> { | ||
|
||
@Override | ||
public Windows evaluate(final SimulationResults results, final Interval bounds, final EvaluationEnvironment environment) { | ||
final var windows = this.windows.evaluate(results, bounds, environment); | ||
return windows.shiftBy(this.fromStart.evaluate(results, bounds, environment), this.fromEnd.evaluate(results, bounds, environment)); | ||
public P evaluate(final SimulationResults results, final Interval bounds, final EvaluationEnvironment environment) { | ||
// bounds aren't shifted here because duration expressions don't care about them; durations don't exist on the timeline. | ||
final var duration = this.duration.evaluate(results, bounds, environment); | ||
|
||
final var shiftedBounds = bounds.shiftBy(Duration.negate(duration)); | ||
final var originalProfile = this.expression.evaluate(results, shiftedBounds, environment); | ||
|
||
return originalProfile.shiftBy(duration); | ||
} | ||
|
||
@Override | ||
public void extractResources(final Set<String> names) { | ||
this.windows.extractResources(names); | ||
this.expression.extractResources(names); | ||
this.duration.extractResources(names); | ||
} | ||
|
||
@Override | ||
public String prettyPrint(final String prefix) { | ||
return String.format( | ||
"\n%s(shift %s by %s %s)", | ||
"\n%s(shiftBy %s %s)", | ||
prefix, | ||
this.windows.prettyPrint(prefix + " "), | ||
this.fromStart.toString(), | ||
this.fromEnd.toString() | ||
this.expression.prettyPrint(prefix + " "), | ||
this.duration.prettyPrint(prefix + " ") | ||
); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!(obj instanceof ShiftBy)) return false; | ||
final var o = (ShiftBy)obj; | ||
|
||
return Objects.equals(this.windows, o.windows) && | ||
Objects.equals(this.fromStart, o.fromStart) && | ||
Objects.equals(this.fromEnd, o.fromEnd); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(this.windows, this.fromStart, this.fromEnd); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
constraints/src/main/java/gov/nasa/jpl/aerie/constraints/tree/ShiftWindowsEdges.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package gov.nasa.jpl.aerie.constraints.tree; | ||
|
||
import gov.nasa.jpl.aerie.constraints.model.EvaluationEnvironment; | ||
import gov.nasa.jpl.aerie.constraints.model.SimulationResults; | ||
import gov.nasa.jpl.aerie.constraints.time.Interval; | ||
import gov.nasa.jpl.aerie.constraints.time.Windows; | ||
import gov.nasa.jpl.aerie.merlin.protocol.types.Duration; | ||
|
||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
public final class ShiftWindowsEdges implements Expression<Windows> { | ||
public final Expression<Windows> windows; | ||
public final Expression<Duration> fromStart; | ||
public final Expression<Duration> fromEnd; | ||
|
||
public ShiftWindowsEdges(final Expression<Windows> left, final Expression<Duration> fromStart, final Expression<Duration> fromEnd) { | ||
this.windows = left; | ||
this.fromStart = fromStart; | ||
this.fromEnd = fromEnd; | ||
} | ||
|
||
@Override | ||
public Windows evaluate(final SimulationResults results, final Interval bounds, final EvaluationEnvironment environment) { | ||
final var shiftRising = this.fromStart.evaluate(results, bounds, environment); | ||
final var shiftFalling = this.fromEnd.evaluate(results, bounds, environment); | ||
|
||
final var newBounds = Interval.between( | ||
Duration.min(bounds.start.minus(shiftRising), bounds.start.minus(shiftFalling)), | ||
bounds.startInclusivity, | ||
Duration.max(bounds.end.minus(shiftRising), bounds.end.minus(shiftFalling)), | ||
bounds.endInclusivity | ||
); | ||
|
||
final var windows = this.windows.evaluate(results, newBounds, environment); | ||
return windows.shiftEdges(shiftRising, shiftFalling).select(bounds); | ||
} | ||
|
||
@Override | ||
public void extractResources(final Set<String> names) { | ||
this.windows.extractResources(names); | ||
} | ||
|
||
@Override | ||
public String prettyPrint(final String prefix) { | ||
return String.format( | ||
"\n%s(shiftWindowsEdges %s by %s %s)", | ||
prefix, | ||
this.windows.prettyPrint(prefix + " "), | ||
this.fromStart.toString(), | ||
this.fromEnd.toString() | ||
); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!(obj instanceof ShiftWindowsEdges)) return false; | ||
final var o = (ShiftWindowsEdges)obj; | ||
|
||
return Objects.equals(this.windows, o.windows) && | ||
Objects.equals(this.fromStart, o.fromStart) && | ||
Objects.equals(this.fromEnd, o.fromEnd); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(this.windows, this.fromStart, this.fromEnd); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.