saealib.Problem#
- class saealib.Problem(func, dim, n_obj, direction, lb=None, ub=None, comparator=None, constraints=None, *, eps_cv=1e-06, eps_obj=1e-06, handler=None, variables=None, space=None, evaluation_adapter=None)[ソース]#
ベースクラス:
objectDefinition of optimization problem.
- パラメータ:
func (Callable[..., Any])
dim (int | None)
n_obj (int)
direction (np.ndarray)
lb (list[float] | None)
ub (list[float] | None)
comparator (Comparator | None)
constraints (list[InequalityConstraint] | None)
eps_cv (float)
eps_obj (float)
handler (ConstraintHandler | None)
variables (list[Variable] | None)
space (SearchSpace | None)
evaluation_adapter (EvaluationAdapter | None)
- dim#
Dimension of the design variables.
- Type:
int
- n_obj#
Number of objectives.
- Type:
int
- direction#
Optimization direction per objective. shape = (n_obj, ) Each element must be +1 (maximize) or -1 (minimize).
- Type:
np.ndarray
- lb#
Lower bounds for design variables. shape = (dim, )
- Type:
np.ndarray
- ub#
Upper bounds for design variables. shape = (dim, )
- Type:
np.ndarray
- comparator#
Comparator instance to compare solutions.
- Type:
- eps_cv#
Epsilon for constraint violation feasibility threshold. Only used to seed the default
handler/comparatorat construction time; mutating this attribute afterwards has no runtime effect. The actual running threshold ishandler.feasibility_threshold, which theRunnersyncs intocomparator/pareto_archiveevery generation. Explicit handlers may therefore use a running threshold intentionally different from this value. This value remains the feasibility basis forResultand summarybest_f; an explicit handler with a different running threshold can therefore make reported solutions disagree with the comparator's criterion.- Type:
float
- eps_obj#
Epsilon for objective value equality comparison.
- Type:
float
- func#
Objective function to evaluate solutions.
- Type:
callable -> float
- constraints#
List of inequality constraint definitions.
- Type:
list[InequalityConstraint]
- handler#
Constraint-handling strategy used to aggregate violations and augment objectives.
- Type:
Methods
Initialize Problem instance. |
|
Evaluate the objective function at given solution x. |
|
Evaluate the objective and constraint functions for a batch of solutions. |
|
Evaluate all constraint functions at x. |
|
Project x onto valid variable domains. |
Method Details
- Problem.__init__(func, dim, n_obj, direction, lb=None, ub=None, comparator=None, constraints=None, *, eps_cv=1e-06, eps_obj=1e-06, handler=None, variables=None, space=None, evaluation_adapter=None)[ソース]#
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.
- Problem.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
- Problem.evaluate_batch(x)[ソース]#
Evaluate the objective and constraint functions for a batch of solutions.
The default implementation returns
None, meaning batch evaluation is not supported by thisProblem-- callers should fall back to the row-by-row path (evaluate()/evaluate_constraints()applied one row at a time). Subclasses (orProbleminstances constructed around a batch-capablefunc, e.g. a vectorized function, a GPU kernel, or an external library such as pymoo that can score many designs in one call) may override this method to evaluate all rows of x in a single call.The returned values are raw: unlike
evaluate(), the objective batch is not passed throughhandler.augment_objective, and unlikeevaluate_constraints(), the constraint batch is not reduced viahandler.compute_cv. Callers are expected to apply those transformations themselves afterward, per row.- パラメータ:
x (np.ndarray) -- Batch of solutions to evaluate. shape = (n, dim)
- 戻り値:
(f_batch, g_batch)if batch evaluation is supported, elseNone.f_batch: raw objective values. shape = (n, n_obj)g_batch: raw constraint values, in the same column order asself.constraints. shape = (n, n_constraints); (n, 0) when the problem has no constraints. Row order matches the order of rows in x.- 戻り値の型:
tuple[np.ndarray, np.ndarray] or None
- Problem.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]
- Problem.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