saealib.ConstraintHandler¶
- class saealib.ConstraintHandler[source]¶
Bases:
ABCPluggable constraint-processing strategy.
A
ConstraintHandlerexposes the constraint-handling lifecycle as a set of overridable hooks, decoupling the per-constraint violation formula and the aggregation method from the coreProblem. 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, lb, ub)] -> 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 have sensible defaults so that subclasses implement just what they need.
Methods
Transform objective values using constraint information. |
|
Aggregate raw constraint values into a scalar constraint violation. |
|
Run end-of-generation bookkeeping. |
|
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.0means 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, lb, ub, **kwargs)[source]¶
Repair a design vector before evaluation.
Called by the algorithm after each variation operator (crossover / mutation) and before objective evaluation. The default clips
xto[lb, ub], reproducing the behaviour ofrepair_clipping.Subclasses override this to add domain-constraint repair (e.g. a Newton step toward an equality-constraint manifold) on top of—or instead of—bounds clipping.
- Parameters:
x (np.ndarray) – The design vector to repair. shape = (dim, )
constraints (list[InequalityConstraint]) – The problem’s domain constraints.
lb (np.ndarray) – Lower bounds. shape = (dim, )
ub (np.ndarray) – Upper bounds. shape = (dim, )
**kwargs – Reserved for future use (e.g. parent solution for reflection repair).
- Returns:
The repaired design vector. shape = (dim, )
- Return type:
np.ndarray