From 33ad9e9926371bd13efc85a49525b40dc832e10d Mon Sep 17 00:00:00 2001 From: maillard Date: Fri, 21 Jun 2024 11:44:44 +0200 Subject: [PATCH] Ensure initialization x is in bounds for x1, we provide an optimistic value based on the computation of x0. It is possible that this x1 is out of bounds but nextValueAt was not checking this property. --- .../nasa/jpl/aerie/scheduler/EquationSolvingAlgorithms.java | 2 +- .../java/gov/nasa/jpl/aerie/scheduler/RootfindingTest.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scheduler-driver/src/main/java/gov/nasa/jpl/aerie/scheduler/EquationSolvingAlgorithms.java b/scheduler-driver/src/main/java/gov/nasa/jpl/aerie/scheduler/EquationSolvingAlgorithms.java index 12022c52b8..a951fb9ef5 100644 --- a/scheduler-driver/src/main/java/gov/nasa/jpl/aerie/scheduler/EquationSolvingAlgorithms.java +++ b/scheduler-driver/src/main/java/gov/nasa/jpl/aerie/scheduler/EquationSolvingAlgorithms.java @@ -131,7 +131,7 @@ private IteratingResult nextValueAt( int i = 0; do { //we should not come back to previously visited values - if (!history.alreadyVisited(cur)) { + if (!history.alreadyVisited(cur) && cur.between(min, max)) { i++; try { final var value = function.valueAt(cur, history); diff --git a/scheduler-driver/src/test/java/gov/nasa/jpl/aerie/scheduler/RootfindingTest.java b/scheduler-driver/src/test/java/gov/nasa/jpl/aerie/scheduler/RootfindingTest.java index fc817e9ffe..4f21808ab6 100644 --- a/scheduler-driver/src/test/java/gov/nasa/jpl/aerie/scheduler/RootfindingTest.java +++ b/scheduler-driver/src/test/java/gov/nasa/jpl/aerie/scheduler/RootfindingTest.java @@ -127,7 +127,7 @@ public Duration valueAt( Duration.of(-2, Duration.SECONDS), twoSecond, 100); - assertEquals(29, solution.history().getHistory().size()); + assertEquals(30, solution.history().getHistory().size()); assertEquals(new EquationSolvingAlgorithms.FunctionCoordinate<>(Duration.of(0, Duration.MICROSECONDS), Duration.of(0, Duration.MICROSECONDS)), solution.functionCoordinate()); } @@ -164,7 +164,7 @@ public Duration valueAt( Duration.of(-2, Duration.SECONDS), twoSecond, 100); - assertEquals(2, solution.history().getHistory().size()); - assertEquals(new EquationSolvingAlgorithms.FunctionCoordinate<>(Duration.of(0, Duration.MICROSECONDS), Duration.of(0, Duration.MICROSECONDS)), solution.functionCoordinate()); + assertEquals(1, solution.history().getHistory().size()); + assertEquals(new EquationSolvingAlgorithms.FunctionCoordinate<>(Duration.of(-860925, Duration.MICROSECONDS), Duration.of(0, Duration.MICROSECONDS)), solution.functionCoordinate()); } }