Package de.labathome.trustconstr
Class NonlinearConstraint
java.lang.Object
de.labathome.trustconstr.NonlinearConstraint
- All Implemented Interfaces:
Constraint,Jacobian
Nonlinear constraint of the form
lb <= fun(x) <= ub
Counterpart to scipy.optimize.NonlinearConstraint
(scipy/optimize/_constraints.py:22).
fun is the constraint function R^n -> R^m, jac
its Jacobian (R^n -> R^{m x n}). The optional hess callable
is the constraint-Hessian-of-Lagrangian:
hess(x, v) -> sum_i v[i] * H_{c_i}(x). When supplied, the
orchestrator uses it to build the full Lagrangian Hessian
H_objective(x) + hess(x, v); without it, the orchestrator falls back
to the objective Hessian alone, which can hurt convergence on problems where
constraint curvature matters at the optimum (e.g. Maratos).
Eq/ineq classification follows the same rule as LinearConstraint,
including the two-sided interval split. Inequality rows are emitted in
scipy's 4-block order (less, greater, interval-upper, interval-lower).
-
Constructor Summary
ConstructorsConstructorDescriptionNonlinearConstraint(Function<Matrix, Matrix> fun, double[] lb, double[] ub) NonlinearConstraint(Function<Matrix, Matrix> fun, double[] lb, double[] ub, boolean[] keepFeasible) NonlinearConstraint(Function<Matrix, Matrix> fun, Function<Matrix, Matrix> jac, double[] lb, double[] ub) Convenience overload with neither constraint Hessian norkeepFeasibleflags.NonlinearConstraint(Function<Matrix, Matrix> fun, Function<Matrix, Matrix> jac, double[] lb, double[] ub, boolean[] keepFeasible) Convenience overload: asNonlinearConstraint(Function, Function, BiFunction, double[], double[], boolean[])with no constraint Hessian.NonlinearConstraint(Function<Matrix, Matrix> fun, Function<Matrix, Matrix> jac, BiFunction<Matrix, Matrix, Matrix> hess, double[] lb, double[] ub, boolean[] keepFeasible) Build a nonlinear constraint with explicit constraint Hessian. -
Method Summary
Modifier and TypeMethodDescriptionbounds()constrIneq(Matrix x) boolean[]Per-canonical-inequality-rowenforceFeasibilityflags derived from the user-suppliedkeep_feasible.boolean[]lagrangianContribution(Matrix x, double[] vEq, double[] vIneq) Constraint Hessian-of-LagrangianSum_i v[i] * H_{c_i}(x), combining equality and inequality multipliers into a single Hessian contribution.double[]lb()intnEq()intnIneq()double[]ub()userFun()userHess()userJac()voidThrowsIllegalArgumentExceptionif any row markedkeepFeasible[i] == trueis violated at the supplied starting point.
-
Constructor Details
-
NonlinearConstraint
public NonlinearConstraint(Function<Matrix, Matrix> fun, Function<Matrix, Matrix> jac, BiFunction<Matrix, Matrix, Matrix> hess, double[] lb, double[] ub, boolean[] keepFeasible) Build a nonlinear constraint with explicit constraint Hessian.- Parameters:
fun- constraint functionR^n -> R^mjac- analytic JacobianR^n -> R^{m x n}hess- constraint Hessian-of-Lagrangian(x, v) -> Sum v[i] H_{c_i}(x); may benulllb- per-row lower bounds, lengthmub- per-row upper bounds, lengthmkeepFeasible- per-row strict-feasibility flag, lengthm;null= all-false
-
NonlinearConstraint
public NonlinearConstraint(Function<Matrix, Matrix> fun, Function<Matrix, Matrix> jac, double[] lb, double[] ub, boolean[] keepFeasible) Convenience overload: asNonlinearConstraint(Function, Function, BiFunction, double[], double[], boolean[])with no constraint Hessian.- Parameters:
fun- constraint functionjac- analytic Jacobianlb- lower boundsub- upper boundskeepFeasible- per-row strict-feasibility flag
-
NonlinearConstraint
public NonlinearConstraint(Function<Matrix, Matrix> fun, Function<Matrix, Matrix> jac, double[] lb, double[] ub) Convenience overload with neither constraint Hessian norkeepFeasibleflags.- Parameters:
fun- constraint functionjac- analytic Jacobianlb- lower boundsub- upper bounds
-
NonlinearConstraint
public NonlinearConstraint(Function<Matrix, Matrix> fun, double[] lb, double[] ub, boolean[] keepFeasible) - Parameters:
fun- constraint functionlb- lower boundsub- upper boundskeepFeasible- per-row strict-feasibility flag
-
NonlinearConstraint
- Parameters:
fun- constraint functionlb- lower boundsub- upper bounds
-
-
Method Details
-
lb
public double[] lb()- Returns:
- defensive copy of the lower bounds
-
ub
public double[] ub()- Returns:
- defensive copy of the upper bounds
-
keepFeasible
public boolean[] keepFeasible()- Returns:
- defensive copy of the per-row keep-feasible flags
-
userFun
- Returns:
- the user-supplied constraint function
R^n -> R^m
-
userJac
- Returns:
- the user-supplied analytic Jacobian
R^n -> R^{m x n}
-
userHess
- Returns:
- the user-supplied constraint Hessian-of-Lagrangian
(x, v) -> Sum v[i] H_{c_i}(x), ornullif none
-
bounds
- Returns:
- the bounds repackaged as a
Boundsrecord
-
nEq
public int nEq()- Returns:
- number of canonical equality rows
-
nIneq
public int nIneq()- Returns:
- number of canonical inequality rows
-
enforceFeasibilityIneq
public boolean[] enforceFeasibilityIneq()Per-canonical-inequality-rowenforceFeasibilityflags derived from the user-suppliedkeep_feasible. Each canonical ineq row inherits the kf flag of the original row it came from. Length matchesnIneq().- Returns:
- per-canonical-row strict-feasibility flags
-
validateKeepFeasibleAtStart
ThrowsIllegalArgumentExceptionif any row markedkeepFeasible[i] == trueis violated at the supplied starting point. Mirrors scipy's strict-feasibility precondition forkeep_feasible=Truerows.- Parameters:
x0- starting iterate (n x 1)
-
lagrangianContribution
Constraint Hessian-of-LagrangianSum_i v[i] * H_{c_i}(x), combining equality and inequality multipliers into a single Hessian contribution. -
constrEq
- Specified by:
constrEqin interfaceConstraint- Parameters:
x- current iterate (n × 1)- Returns:
- equality-constraint residual (
nEq × 1)
-
constrIneq
- Specified by:
constrIneqin interfaceConstraint- Parameters:
x- current iterate (n × 1)- Returns:
- inequality-constraint residual (
nIneq × 1); feasible iff every entry is≤ 0
-
jacEq
-
jacIneq
-