saealib.PymooProblem#

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

ベースクラス: 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.

パラメータ:
  • 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).

例外:

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

メモ

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)[ソース]#

Initialize Problem instance.

パラメータ:
  • 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)

戻り値の型:

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.

パラメータ:
  • 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()).

戻り値:

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

戻り値の型:

np.ndarray

PymooProblem.evaluate_batch(x)[ソース]#

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

パラメータ:

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

戻り値:

(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).

戻り値の型:

tuple[np.ndarray, np.ndarray]

PymooProblem.evaluate_constraints(x)#

Evaluate all constraint functions at x.

パラメータ:

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

戻り値:

  • 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.

戻り値の型:

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].

パラメータ:

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

戻り値:

Repaired array, same shape as x.

戻り値の型:

np.ndarray