diff --git a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/polynomial/LinearBoundaryConsistencySolver.java b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/polynomial/LinearBoundaryConsistencySolver.java index 69cbdb5c1d..11515d3be9 100644 --- a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/polynomial/LinearBoundaryConsistencySolver.java +++ b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/polynomial/LinearBoundaryConsistencySolver.java @@ -27,7 +27,6 @@ import static gov.nasa.jpl.aerie.contrib.streamline.core.Expiring.neverExpiring; import static gov.nasa.jpl.aerie.contrib.streamline.core.Reactions.whenever; import static gov.nasa.jpl.aerie.contrib.streamline.core.monads.ExpiringMonad.bind; -import static gov.nasa.jpl.aerie.contrib.streamline.core.Resources.eraseExpiry; import static gov.nasa.jpl.aerie.contrib.streamline.debugging.Context.contextualized; import static gov.nasa.jpl.aerie.contrib.streamline.debugging.Dependencies.addDependency; import static gov.nasa.jpl.aerie.contrib.streamline.debugging.Naming.getName; @@ -314,7 +313,7 @@ private Stream directionalConstraints(Variable constraine // Expiry for driven terms is captured by re-solving rather than expiring the solution. // If solver has a feedback loop from last iteration (which is common) // feeding that expiry in here can loop the solver forever. - var result = eraseExpiry(drivenTerm); + var result = drivenTerm; for (var drivingVariable : drivingVariables) { var scale = controlledTerm.get(drivingVariable); var domain = domains.get(drivingVariable); diff --git a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/polynomial/PolynomialResources.java b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/polynomial/PolynomialResources.java index fc12ae44e2..40c26b3ecb 100644 --- a/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/polynomial/PolynomialResources.java +++ b/contrib/src/main/java/gov/nasa/jpl/aerie/contrib/streamline/modeling/polynomial/PolynomialResources.java @@ -364,6 +364,7 @@ public static ClampedIntegrateResult clampedIntegrate( Resource integrand, Resource lowerBound, Resource upperBound, double startingValue) { LinearBoundaryConsistencySolver rateSolver = new LinearBoundaryConsistencySolver("clampedIntegrate rate solver"); var integral = resource(polynomial(startingValue)); + var neverExpiringIntegral = eraseExpiry(integral); // Solve for the rate as a function of value var overflowRate = rateSolver.variable("overflowRate", Domain::lowerBound); @@ -377,11 +378,11 @@ public static ClampedIntegrateResult clampedIntegrate( // Set up rate clamping conditions var integrandUB = choose( - greaterThanOrEquals(integral, upperBound), + greaterThanOrEquals(neverExpiringIntegral, upperBound), differentiate(upperBound), constant(Double.POSITIVE_INFINITY)); var integrandLB = choose( - lessThanOrEquals(integral, lowerBound), + lessThanOrEquals(neverExpiringIntegral, lowerBound), differentiate(lowerBound), constant(Double.NEGATIVE_INFINITY)); @@ -390,10 +391,10 @@ public static ClampedIntegrateResult clampedIntegrate( // Use a simple feedback loop on volumes to do the integration and clamping. // Clamping here takes care of discrete under-/overflows and overshooting bounds due to discrete time steps. - var clampedCell = clamp(integral, lowerBound, upperBound); + var clampedCell = clamp(neverExpiringIntegral, lowerBound, upperBound); var correctedCell = map(clampedCell, rate.resource(), (v, r) -> r.integral(v.extract())); // Use the corrected integral values to set volumes, but erase expiry information in the process to avoid loops - forward(eraseExpiry(correctedCell), integral); + forward(correctedCell, integral); name(integral, "Clamped Integral (%s)", integrand); name(overflowRate.resource(), "Overflow of %s", integral);