saealib.InequalityConstraint¶
- class saealib.InequalityConstraint(func, threshold=0.0)[source]¶
Bases:
objectA single inequality constraint: g(x) <= threshold.
- Parameters:
func (callable) – Constraint function g(x). Should return a scalar float.
threshold (float, optional) – Right-hand side of the constraint g(x) <= threshold. Default: 0.0.
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 the violation for an already-evaluated raw value g(x). |
Method Details
- InequalityConstraint.__init__(func, threshold=0.0)[source]¶
- Parameters:
func (callable)
threshold (float)
- InequalityConstraint.evaluate(x)[source]¶
Return the raw constraint value g(x).
- Parameters:
x (ndarray)
- Return type:
float
- InequalityConstraint.evaluate_with_violation(x)[source]¶
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]
- InequalityConstraint.gradient(x)[source]¶
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
- InequalityConstraint.violation(x)[source]¶
Return constraint violation: max(0, g(x) - threshold).
- Parameters:
x (ndarray)
- Return type:
float
- InequalityConstraint.violation_from_value(g)[source]¶
Return the violation for an already-evaluated raw value g(x).
This is the single source of truth for the per-constraint violation formula:
violation(),evaluate_with_violation(), andStaticToleranceHandlerall delegate to it. Subclasses (e.g.EqualityConstraint) override this one method to change how a raw value maps to a violation, without re-evaluatingfunc.- Parameters:
g (float) – Raw constraint value g(x).
- Returns:
Constraint violation: max(0, g - threshold).
- Return type:
float