Class PreparedConstraint

java.lang.Object
de.labathome.trustconstr.records.PreparedConstraint

public class PreparedConstraint extends Object
User-facing constraint prepared for use by the trust-constr orchestrator. Mirrors scipy's PreparedConstraint (scipy/optimize/_constraints.py:352): wraps the constraint in an appropriate VectorFunctionLike carrier (with f and J cached at x0), exposes the bounds and per-row keep-feasible mask, and validates that x0 satisfies any keep-feasible inequality rows.

Three constructors handle the three constraint shapes scipy supports: LinearConstraint (uses LinearVectorFunction), NonlinearConstraint (uses NonlinearVectorFunction), Bounds (uses IdentityVectorFunction).

  • Constructor Details

    • PreparedConstraint

      public PreparedConstraint(LinearConstraint lc, Matrix x0, Optional<Boolean> sparseJacobian)
      Prepare a LinearConstraint. f and J are cached at x0 via a LinearVectorFunction.
      Parameters:
      lc - linear constraint
      x0 - starting iterate (n x 1)
      sparseJacobian - user preference for Jacobian representation; Optional.empty() preserves whatever lc.getA() already is
    • PreparedConstraint

      public PreparedConstraint(NonlinearConstraint nc, Matrix x0, Optional<Boolean> sparseJacobian, FiniteDifferenceBounds finiteDiffBounds)
      Prepare a NonlinearConstraint. f and J are cached at x0 via a NonlinearVectorFunction.
      Parameters:
      nc - nonlinear constraint
      x0 - starting iterate (n x 1)
      sparseJacobian - user preference for Jacobian representation
      finiteDiffBounds - bounds to clamp finite-difference perturbations within (currently unused -- the FD wrapping is done by NonlinearConstraint itself when the user omits an analytic Jacobian, before this constructor is reached)
    • PreparedConstraint

      public PreparedConstraint(Bounds bounds, Matrix x0, Optional<Boolean> sparseJacobian)
      Prepare Bounds (folding them into the constraint set as the trivial linear constraint lb &le; x &le; ub with A = I). f = x0 and J = I are cached via an IdentityVectorFunction.
      Parameters:
      bounds - box bounds on the decision variables
      x0 - starting iterate (n x 1)
      sparseJacobian - user preference for Jacobian representation
  • Method Details

    • violation

      public double[] violation(Matrix x)
      Compute the per-row constraint violation at x. Each row's violation is max(0, lb - f(x)) + max(0, f(x) - ub): the amount by which the constraint is exceeded on either side. Mirrors scipy's PreparedConstraint.violation.
      Parameters:
      x - current iterate (n x 1)
      Returns:
      per-row violation, length m()
    • fun

      public VectorFunctionLike fun()
      Returns:
      wrapped VectorFunctionLike carrier with cached f, J
    • lb

      public double[] lb()
      Returns:
      defensive copy of the lower bounds, length m()
    • ub

      public double[] ub()
      Returns:
      defensive copy of the upper bounds, length m()
    • keepFeasible

      public boolean[] keepFeasible()
      Returns:
      defensive copy of the per-row keep-feasible flags, length m()
    • m

      public long m()
      Returns:
      number of constraint rows (m)
    • n

      public long n()
      Returns:
      number of decision variables (n)
    • x0

      public Matrix x0()
      Returns:
      defensive copy of the iterate x0 the constraint was prepared at
    • source

      public Object source()
      Returns:
      original user-supplied source constraint; one of LinearConstraint, NonlinearConstraint, or Bounds, depending on which constructor was used
    • bounds

      public Bounds bounds()
      Returns:
      bounds repackaged as a Bounds record (lb and ub as m x 1 column matrices). Mirrors scipy's tuple-shape bounds = (lb, ub).