Package de.labathome.trustconstr.records
Class PreparedConstraint
java.lang.Object
de.labathome.trustconstr.records.PreparedConstraint
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 Summary
ConstructorsConstructorDescriptionPreparedConstraint(LinearConstraint lc, Matrix x0, Optional<Boolean> sparseJacobian) Prepare aLinearConstraint.PreparedConstraint(NonlinearConstraint nc, Matrix x0, Optional<Boolean> sparseJacobian, FiniteDifferenceBounds finiteDiffBounds) Prepare aNonlinearConstraint.PreparedConstraint(Bounds bounds, Matrix x0, Optional<Boolean> sparseJacobian) PrepareBounds(folding them into the constraint set as the trivial linear constraintlb ≤ x ≤ ubwithA = I). -
Method Summary
-
Constructor Details
-
PreparedConstraint
- Parameters:
lc- linear constraintx0- starting iterate (n x 1)sparseJacobian- user preference for Jacobian representation;Optional.empty()preserves whateverlc.getA()already is
-
PreparedConstraint
public PreparedConstraint(NonlinearConstraint nc, Matrix x0, Optional<Boolean> sparseJacobian, FiniteDifferenceBounds finiteDiffBounds) - Parameters:
nc- nonlinear constraintx0- starting iterate (n x 1)sparseJacobian- user preference for Jacobian representationfiniteDiffBounds- bounds to clamp finite-difference perturbations within (currently unused -- the FD wrapping is done byNonlinearConstraintitself when the user omits an analytic Jacobian, before this constructor is reached)
-
PreparedConstraint
PrepareBounds(folding them into the constraint set as the trivial linear constraintlb ≤ x ≤ ubwithA = I).f = x0andJ = Iare cached via anIdentityVectorFunction.- Parameters:
bounds- box bounds on the decision variablesx0- starting iterate (n x 1)sparseJacobian- user preference for Jacobian representation
-
-
Method Details
-
violation
Compute the per-row constraint violation atx. Each row's violation ismax(0, lb - f(x)) + max(0, f(x) - ub): the amount by which the constraint is exceeded on either side. Mirrors scipy'sPreparedConstraint.violation.- Parameters:
x- current iterate (n x 1)- Returns:
- per-row violation, length
m()
-
fun
- Returns:
- wrapped
VectorFunctionLikecarrier with cachedf,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
- Returns:
- defensive copy of the iterate
x0the constraint was prepared at
-
source
- Returns:
- original user-supplied source constraint; one of
LinearConstraint,NonlinearConstraint, orBounds, depending on which constructor was used
-
bounds
- Returns:
- bounds repackaged as a
Boundsrecord (lbandubasm x 1column matrices). Mirrors scipy's tuple-shapebounds = (lb, ub).
-