saealib.EqualityConstraint#
- class saealib.EqualityConstraint(func, tolerance=1e-06)[source]#
Bases:
InequalityConstraintA single equality constraint: h(x) = 0, satisfied within a tolerance.
The violation is
max(0, |h(x)| - tolerance), reusing the inequality violation path so that mixed inequality/equality problems aggregate through the sameConstraintHandler. Onlyviolation_from_value()is overridden;violation()andevaluate_with_violation()inherit the equality behavior automatically.- Parameters:
func (callable) – Constraint function h(x). Should return a scalar float.
tolerance (float, optional) – Feasibility tolerance for
|h(x)| <= tolerance. Default: 1e-6. Settolerance=0.0to defer the feasibility threshold to a handler such asEpsilonConstraintHandler, where the threshold is managed externally rather than baked into the constraint.
Notes
Provide an analytical Jacobian by overriding
gradient()to return∇h(x); this enables gradient-based constraint handlers (e.g. repair).
Methods
Return the raw constraint value g(x). |
|
Return the raw value and violation with a single function evaluation. |
|
Return the gradient of g(x) with respect to x, if available. |
|
Return constraint violation: max(0, g(x) - threshold). |
|
Return equality violation: max(0, abs(h(x)) - tolerance). |
Method Details
- EqualityConstraint.__init__(func, tolerance=1e-06)[source]#
- Parameters:
func (Callable[[...], Any])
tolerance (float)
- EqualityConstraint.evaluate(x)#
Return the raw constraint value g(x).
- Parameters:
x (ndarray)
- Return type:
float
- EqualityConstraint.evaluate_with_violation(x)#
Return the raw value and violation with a single function evaluation.
- Returns:
g (float) – Raw constraint value g(x).
cv (float) – Constraint violation: max(0, g(x) - threshold).
- Parameters:
x (ndarray)
- Return type:
tuple[float, float]
- EqualityConstraint.gradient(x)#
Return the gradient of g(x) with respect to x, if available.
Override this in a subclass to enable gradient-based constraint handlers (e.g. gradient-based repair). The default returns
None, signalling that no analytical Jacobian is provided.- Parameters:
x (np.ndarray) – The solution at which to evaluate the gradient. shape = (dim, )
- Returns:
Gradient vector with shape = (dim, ), or
Nonewhen no gradient is available.- Return type:
np.ndarray or None
- EqualityConstraint.violation(x)#
Return constraint violation: max(0, g(x) - threshold).
- Parameters:
x (ndarray)
- Return type:
float