saealib.EqualityConstraint#

class saealib.EqualityConstraint(func, tolerance=1e-06)[ソース]#

ベースクラス: InequalityConstraint

A 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 same ConstraintHandler. Only violation_from_value() is overridden; violation() and evaluate_with_violation() inherit the equality behavior automatically.

パラメータ:
  • func (callable) -- Constraint function h(x). Should return a scalar float.

  • tolerance (float, optional) -- Feasibility tolerance for |h(x)| <= tolerance. Default: 1e-6. Set tolerance=0.0 to defer the feasibility threshold to a handler such as EpsilonConstraintHandler, where the threshold is managed externally rather than baked into the constraint.

メモ

Provide an analytical Jacobian by overriding gradient() to return ∇h(x); this enables gradient-based constraint handlers (e.g. repair).

Methods

__init__

evaluate

Return the raw constraint value g(x).

evaluate_with_violation

Return the raw value and violation with a single function evaluation.

gradient

Return the gradient of g(x) with respect to x, if available.

violation

Return constraint violation: max(0, g(x) - threshold).

violation_from_value

Return equality violation: max(0, abs(h(x)) - tolerance).

Method Details

EqualityConstraint.__init__(func, tolerance=1e-06)[ソース]#
パラメータ:
  • func (Callable[[...], Any])

  • tolerance (float)

EqualityConstraint.evaluate(x)#

Return the raw constraint value g(x).

パラメータ:

x (ndarray)

戻り値の型:

float

EqualityConstraint.evaluate_with_violation(x)#

Return the raw value and violation with a single function evaluation.

戻り値:

  • g (float) -- Raw constraint value g(x).

  • cv (float) -- Constraint violation: max(0, g(x) - threshold).

パラメータ:

x (ndarray)

戻り値の型:

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.

パラメータ:

x (np.ndarray) -- The solution at which to evaluate the gradient. shape = (dim, )

戻り値:

Gradient vector with shape = (dim, ), or None when no gradient is available.

戻り値の型:

np.ndarray or None

EqualityConstraint.violation(x)#

Return constraint violation: max(0, g(x) - threshold).

パラメータ:

x (ndarray)

戻り値の型:

float

EqualityConstraint.violation_from_value(g)[ソース]#

Return equality violation: max(0, abs(h(x)) - tolerance).

パラメータ:

g (float)

戻り値の型:

float