saealib.ConstraintHandler

class saealib.ConstraintHandler[source]

Bases: ABC

Pluggable constraint-processing strategy.

A ConstraintHandler exposes the constraint-handling lifecycle as a set of overridable hooks, decoupling the per-constraint violation formula and the aggregation method from the core Problem. This lets research code swap in alternative strategies (e.g. ε-constraint, penalty functions, gradient-based repair, augmented Lagrangian) without forking core classes.

Lifecycle:

Ask            -> [repair(x, constraints)]
               -> evaluate f, g
               -> [compute_cv(constraints, x, g)]        -> cv
               -> [augment_objective(f, constraints, x, g)] -> f'
Tell           -> Comparator(f', cv) with eps_cv = feasibility_threshold
Generation end -> [on_generation_end(gen, population)]

Only compute_cv() is abstract; the remaining hooks default to no-ops so that subclasses implement just what they need.

Methods

__init__

augment_objective

Transform objective values using constraint information.

compute_cv

Aggregate raw constraint values into a scalar constraint violation.

on_generation_end

Run end-of-generation bookkeeping.

repair

Repair a design vector before evaluation.

Method Details

ConstraintHandler.__init__()
ConstraintHandler.augment_objective(f, constraints, x, g)[source]

Transform objective values using constraint information.

Used by penalty-based or augmented-Lagrangian strategies. The default is the identity (objectives are returned unchanged).

Parameters:
  • f (np.ndarray) – Raw objective values. shape = (n_obj, )

  • constraints (list[InequalityConstraint]) – The problem’s inequality constraints, aligned with g.

  • x (np.ndarray) – The evaluated design vector. shape = (dim, )

  • g (np.ndarray) – Raw constraint values g(x). shape = (n_constraints, )

Returns:

The (possibly) augmented objective values. shape = (n_obj, )

Return type:

np.ndarray

abstract ConstraintHandler.compute_cv(constraints, x, g)[source]

Aggregate raw constraint values into a scalar constraint violation.

Parameters:
  • constraints (list[InequalityConstraint]) – The problem’s inequality constraints, aligned with g.

  • x (np.ndarray) – The evaluated design vector. shape = (dim, )

  • g (np.ndarray) – Raw constraint values g(x). shape = (n_constraints, )

Returns:

Aggregate constraint violation (cv); 0.0 means feasible.

Return type:

float

ConstraintHandler.on_generation_end(gen, population)[source]

Run end-of-generation bookkeeping.

Used by adaptive strategies (e.g. ε-level control) that update their internal state between generations. The default is a no-op.

Parameters:
  • gen (int) – The generation index that just finished.

  • population (Population) – The current population.

Return type:

None

ConstraintHandler.repair(x, constraints)[source]

Repair a design vector before evaluation.

Parameters:
  • x (np.ndarray) – The design vector to repair. shape = (dim, )

  • constraints (list[InequalityConstraint]) – The problem’s inequality constraints.

Returns:

The (possibly) repaired design vector. The default returns x unchanged.

Return type:

np.ndarray