saealib.PymooProblem#
- class saealib.PymooProblem(pymoo_problem, *, eq_tolerance=1e-06, **problem_kwargs)[ソース]#
ベースクラス:
ProblemAdapter wrapping a pymoo Problem instance as a saealib
Problem.Lets researchers who already have a pymoo
Problemdefinition (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
EqualityConstraintbuilt from the pymoo problem'sH(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/xubounds.
メモ
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 vectorizedevaluateonce for the whole batch; callers going throughevaluate()/evaluate_constraints()one row at a time instead fall back to the one-slot_EvalCache, which still collapses the per-rowevaluate_constraints()+evaluate()pair into a single pymoo call.directionis always all-1: pymoo problems are unconditionally minimization. Wrap inmaximize()only if the pymoo problem itself already negates what you want to maximize.Gmaps toInequalityConstraint(threshold=0.0, no sign flip — both conventions agree on "feasible when <= 0");Hmaps toEqualityConstraintwithout modification.
Methods
Initialize Problem instance. |
|
Evaluate the objective function at given solution x. |
|
Evaluate a batch via the wrapped pymoo problem's own vectorized |
|
Evaluate all constraint functions at x. |
|
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
VectorSpaceis constructed fromvariablesor 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_objectiveis applied so that penalty-based or augmented-Lagrangian handlers can transform the objective using constraint information. The defaultStaticToleranceHandlerleaves 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
gis already available (e.g. fromevaluate_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 matchesself.constraints(inequality columns fromGfirst, then equality columns fromH).- 戻り値の型:
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