saealib.Problem¶
- class saealib.Problem(func, dim, n_obj, direction, lb, ub, eps=None, comparator=None, constraints=None, *, eps_cv=1e-06, eps_obj=1e-06, handler=None)[source]¶
Bases:
objectDefinition of optimization problem.
- Parameters:
func (callable)
dim (int)
n_obj (int)
direction (np.ndarray)
lb (list[float])
ub (list[float])
eps (float | None)
comparator (Comparator | None)
constraints (list[InequalityConstraint] | None)
eps_cv (float)
eps_obj (float)
handler (ConstraintHandler | 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:
Comparator
- eps_cv¶
Epsilon for constraint violation feasibility threshold.
- 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 all constraint functions at x. |
Method Details
- Problem.__init__(func, dim, n_obj, direction, lb, ub, eps=None, comparator=None, constraints=None, *, eps_cv=1e-06, eps_obj=1e-06, handler=None)[source]¶
Initialize Problem instance.
- Parameters:
func (callable -> float) – Objective function to evaluate solutions.
dim (int) – 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]) – Lower bounds for design variables. length = dim
ub (list[float]) – Upper bounds for design variables. length = dim
eps (float, optional) – Deprecated. Use eps_cv and eps_obj. Will be removed in 0.1.0.
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.
- Problem.evaluate(x, g=None)[source]¶
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.- 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
gis already available (e.g. fromevaluate_constraints()).
- Returns:
The objective value(s) at solution x. shape = (n_obj, )
- Return type:
np.ndarray
- Problem.evaluate_constraints(x)[source]¶
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]