saealib.PymooProblem#

class saealib.PymooProblem(pymoo_problem, *, eq_tolerance=1e-06, **problem_kwargs)[source]#

Bases: Problem

Adapter wrapping a pymoo Problem instance as a saealib Problem.

Lets researchers who already have a pymoo Problem definition (test suites, real-world models) reuse it unchanged inside saealib.

Parameters:
  • pymoo_problem (pymoo.core.problem.Problem) – An already-constructed pymoo problem instance with finite xl/xu.

  • eq_tolerance (float, optional) – Feasibility tolerance forwarded to each EqualityConstraint built from the pymoo problem’s H (equality constraint) output. Default: 1e-6.

  • **problem_kwargs – Forwarded to Problem (e.g. comparator, handler, eps_cv, eps_obj).

Raises:

ValidationError – If the pymoo problem has no finite xl/xu bounds.

Notes

Unlike opfunu (scalar, single-objective), pymoo problems are batch-evaluated (_evaluate(X, out)) and may declare inequality (G) and equality (H) constraints. evaluate_batch() exploits this by calling the wrapped pymoo problem’s own vectorized evaluate once for the whole batch; callers going through evaluate() / evaluate_constraints() one row at a time instead fall back to the one-slot _EvalCache, which still collapses the per-row evaluate_constraints() + evaluate() pair into a single pymoo call.

direction is always all -1: pymoo problems are unconditionally minimization. Wrap in maximize() only if the pymoo problem itself already negates what you want to maximize.

G maps to InequalityConstraint (threshold=0.0, no sign flip — both conventions agree on “feasible when <= 0”); H maps to EqualityConstraint without modification.

Methods

__init__

Initialize Problem instance.

evaluate

Evaluate the objective function at given solution x.

evaluate_batch

Evaluate a batch via the wrapped pymoo problem's own vectorized evaluate.

evaluate_constraints

Evaluate all constraint functions at x.

repair

Project x onto valid variable domains.

Method Details

PymooProblem.__init__(pymoo_problem, *, eq_tolerance=1e-06, **problem_kwargs)[source]#

Initialize Problem instance.

Parameters:
  • func (callable -> float) – Objective function to evaluate solutions.

  • dim (int or None) – Dimension of the design variables.

  • n_obj (int) – Number of objectives.

  • direction (np.ndarray) – Optimization direction per objective. shape = (n_obj, ) Each element must be +1 (maximize) or -1 (minimize).

  • lb (list[float], optional) – Lower bounds for design variables. length = dim. Required when variables is not provided.

  • ub (list[float], optional) – Upper bounds for design variables. length = dim. Required when variables is not provided.

  • comparator (Comparator, optional) – Comparator instance to use. If None, auto-selected based on n_obj: n_obj == 1 -> SingleObjectiveComparator, n_obj > 1 -> NSGA2Comparator.

  • constraints (list[InequalityConstraint], optional) – List of inequality constraint definitions. Default: empty list.

  • eps_cv (float, optional) – Epsilon for constraint violation feasibility threshold. Default: 1e-6.

  • eps_obj (float, optional) – Epsilon for objective value equality comparison. Default: 1e-6.

  • handler (ConstraintHandler, optional) – Constraint-handling strategy. If None, a StaticToleranceHandler (sum-of-violations, fixed eps_cv) is used, reproducing the default behavior.

  • variables (list[Variable], optional) – Per-dimension variable definitions. When provided, lb and ub are derived from the variable bounds. len(variables) must equal dim.

  • space (SearchSpace, optional) – Search space to use for non-vector representations. When omitted, a VectorSpace is constructed from variables or bounds.

  • evaluation_adapter (EvaluationAdapter, optional) – Adapter that transforms genome batches into evaluation payloads.

  • pymoo_problem (PymooCoreProblem)

  • eq_tolerance (float)

  • problem_kwargs (Any)

Return type:

None

PymooProblem.evaluate(x, g=None)#

Evaluate the objective function at given solution x.

After computing the raw objective, handler.augment_objective is applied so that penalty-based or augmented-Lagrangian handlers can transform the objective using constraint information. The default StaticToleranceHandler leaves the objective unchanged.

Parameters:
  • x (np.ndarray) – The solution to evaluate.

  • g (np.ndarray, optional) – Pre-computed raw constraint values g(x), shape = (n_constraints, ). When None, constraints are evaluated internally if any are defined. Pass this to avoid re-evaluating constraints when g is already available (e.g. from evaluate_constraints()).

Returns:

The objective value(s) at solution x. shape = (n_obj, )

Return type:

np.ndarray

PymooProblem.evaluate_batch(x)[source]#

Evaluate a batch via the wrapped pymoo problem’s own vectorized evaluate.

Parameters:

x (np.ndarray) – Batch of candidates, shape (n, dim).

Returns:

(f_batch, g_batch) with shapes (n, n_obj) and (n, n_constraints); column order matches self.constraints (inequality columns from G first, then equality columns from H).

Return type:

tuple[np.ndarray, np.ndarray]

PymooProblem.evaluate_constraints(x)#

Evaluate all constraint functions at x.

Parameters:

x (np.ndarray) – The solution to evaluate. shape = (dim, )

Returns:

  • g (np.ndarray) – Raw constraint values. shape = (n_constraints, ) Empty array when no constraints are defined.

  • cv (float) – Aggregate constraint violation as computed by handler.compute_cv. 0.0 when no constraints are defined.

Return type:

tuple[ndarray, float]

PymooProblem.repair(x)#

Project x onto valid variable domains.

Rounds integer dimensions to the nearest integer and clips to bounds. Rounds categorical dimensions to the nearest valid index. Clips continuous dimensions to [lb, ub].

Parameters:

x (np.ndarray) – Design variable array. shape = (dim,) or (n, dim).

Returns:

Repaired array, same shape as x.

Return type:

np.ndarray