pymoo 0.6.1.5.dev0__cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pymoo might be problematic. Click here for more details.
- pymoo/__init__.py +3 -0
- pymoo/algorithms/__init__.py +0 -0
- pymoo/algorithms/base/__init__.py +0 -0
- pymoo/algorithms/base/bracket.py +38 -0
- pymoo/algorithms/base/genetic.py +109 -0
- pymoo/algorithms/base/line.py +62 -0
- pymoo/algorithms/base/local.py +39 -0
- pymoo/algorithms/base/meta.py +79 -0
- pymoo/algorithms/hyperparameters.py +89 -0
- pymoo/algorithms/moo/__init__.py +0 -0
- pymoo/algorithms/moo/age.py +310 -0
- pymoo/algorithms/moo/age2.py +194 -0
- pymoo/algorithms/moo/ctaea.py +298 -0
- pymoo/algorithms/moo/dnsga2.py +76 -0
- pymoo/algorithms/moo/kgb.py +446 -0
- pymoo/algorithms/moo/moead.py +183 -0
- pymoo/algorithms/moo/nsga2.py +113 -0
- pymoo/algorithms/moo/nsga3.py +358 -0
- pymoo/algorithms/moo/pinsga2.py +370 -0
- pymoo/algorithms/moo/rnsga2.py +188 -0
- pymoo/algorithms/moo/rnsga3.py +246 -0
- pymoo/algorithms/moo/rvea.py +214 -0
- pymoo/algorithms/moo/sms.py +195 -0
- pymoo/algorithms/moo/spea2.py +190 -0
- pymoo/algorithms/moo/unsga3.py +47 -0
- pymoo/algorithms/soo/__init__.py +0 -0
- pymoo/algorithms/soo/convex/__init__.py +0 -0
- pymoo/algorithms/soo/nonconvex/__init__.py +0 -0
- pymoo/algorithms/soo/nonconvex/brkga.py +161 -0
- pymoo/algorithms/soo/nonconvex/cmaes.py +554 -0
- pymoo/algorithms/soo/nonconvex/de.py +279 -0
- pymoo/algorithms/soo/nonconvex/direct.py +149 -0
- pymoo/algorithms/soo/nonconvex/es.py +203 -0
- pymoo/algorithms/soo/nonconvex/g3pcx.py +94 -0
- pymoo/algorithms/soo/nonconvex/ga.py +93 -0
- pymoo/algorithms/soo/nonconvex/ga_niching.py +223 -0
- pymoo/algorithms/soo/nonconvex/isres.py +74 -0
- pymoo/algorithms/soo/nonconvex/nelder.py +251 -0
- pymoo/algorithms/soo/nonconvex/optuna.py +80 -0
- pymoo/algorithms/soo/nonconvex/pattern.py +183 -0
- pymoo/algorithms/soo/nonconvex/pso.py +399 -0
- pymoo/algorithms/soo/nonconvex/pso_ep.py +297 -0
- pymoo/algorithms/soo/nonconvex/random_search.py +25 -0
- pymoo/algorithms/soo/nonconvex/sres.py +56 -0
- pymoo/algorithms/soo/univariate/__init__.py +0 -0
- pymoo/algorithms/soo/univariate/backtracking.py +59 -0
- pymoo/algorithms/soo/univariate/exp.py +46 -0
- pymoo/algorithms/soo/univariate/golden.py +65 -0
- pymoo/algorithms/soo/univariate/quadr_interp.py +81 -0
- pymoo/algorithms/soo/univariate/wolfe.py +163 -0
- pymoo/config.py +33 -0
- pymoo/constraints/__init__.py +3 -0
- pymoo/constraints/adaptive.py +62 -0
- pymoo/constraints/as_obj.py +56 -0
- pymoo/constraints/as_penalty.py +41 -0
- pymoo/constraints/eps.py +26 -0
- pymoo/constraints/from_bounds.py +36 -0
- pymoo/core/__init__.py +0 -0
- pymoo/core/algorithm.py +394 -0
- pymoo/core/callback.py +38 -0
- pymoo/core/crossover.py +77 -0
- pymoo/core/decision_making.py +102 -0
- pymoo/core/decomposition.py +76 -0
- pymoo/core/duplicate.py +163 -0
- pymoo/core/evaluator.py +116 -0
- pymoo/core/indicator.py +34 -0
- pymoo/core/individual.py +784 -0
- pymoo/core/infill.py +64 -0
- pymoo/core/initialization.py +42 -0
- pymoo/core/mating.py +39 -0
- pymoo/core/meta.py +21 -0
- pymoo/core/mixed.py +165 -0
- pymoo/core/mutation.py +44 -0
- pymoo/core/operator.py +40 -0
- pymoo/core/parameters.py +134 -0
- pymoo/core/plot.py +210 -0
- pymoo/core/population.py +180 -0
- pymoo/core/problem.py +460 -0
- pymoo/core/recorder.py +99 -0
- pymoo/core/repair.py +23 -0
- pymoo/core/replacement.py +96 -0
- pymoo/core/result.py +52 -0
- pymoo/core/sampling.py +43 -0
- pymoo/core/selection.py +61 -0
- pymoo/core/solution.py +10 -0
- pymoo/core/survival.py +103 -0
- pymoo/core/termination.py +70 -0
- pymoo/core/variable.py +399 -0
- pymoo/cython/__init__.py +0 -0
- pymoo/cython/calc_perpendicular_distance.cpython-312-x86_64-linux-gnu.so +0 -0
- pymoo/cython/calc_perpendicular_distance.pyx +67 -0
- pymoo/cython/decomposition.cpython-312-x86_64-linux-gnu.so +0 -0
- pymoo/cython/decomposition.pyx +165 -0
- pymoo/cython/hv.cpython-312-x86_64-linux-gnu.so +0 -0
- pymoo/cython/hv.pyx +18 -0
- pymoo/cython/info.cpython-312-x86_64-linux-gnu.so +0 -0
- pymoo/cython/info.pyx +5 -0
- pymoo/cython/mnn.cpython-312-x86_64-linux-gnu.so +0 -0
- pymoo/cython/mnn.pyx +273 -0
- pymoo/cython/non_dominated_sorting.cpython-312-x86_64-linux-gnu.so +0 -0
- pymoo/cython/non_dominated_sorting.pyx +645 -0
- pymoo/cython/pruning_cd.cpython-312-x86_64-linux-gnu.so +0 -0
- pymoo/cython/pruning_cd.pyx +197 -0
- pymoo/cython/stochastic_ranking.cpython-312-x86_64-linux-gnu.so +0 -0
- pymoo/cython/stochastic_ranking.pyx +49 -0
- pymoo/cython/utils.pxd +129 -0
- pymoo/cython/vendor/__init__.py +0 -0
- pymoo/cython/vendor/hypervolume.cpp +1621 -0
- pymoo/cython/vendor/hypervolume.h +63 -0
- pymoo/decomposition/__init__.py +0 -0
- pymoo/decomposition/aasf.py +24 -0
- pymoo/decomposition/asf.py +10 -0
- pymoo/decomposition/pbi.py +13 -0
- pymoo/decomposition/perp_dist.py +13 -0
- pymoo/decomposition/tchebicheff.py +11 -0
- pymoo/decomposition/util.py +13 -0
- pymoo/decomposition/weighted_sum.py +8 -0
- pymoo/docs.py +187 -0
- pymoo/experimental/__init__.py +0 -0
- pymoo/experimental/algorithms/__init__.py +0 -0
- pymoo/experimental/algorithms/gde3.py +57 -0
- pymoo/gradient/__init__.py +21 -0
- pymoo/gradient/automatic.py +57 -0
- pymoo/gradient/grad_autograd.py +105 -0
- pymoo/gradient/grad_complex.py +35 -0
- pymoo/gradient/grad_jax.py +51 -0
- pymoo/gradient/toolbox/__init__.py +6 -0
- pymoo/indicators/__init__.py +0 -0
- pymoo/indicators/distance_indicator.py +55 -0
- pymoo/indicators/gd.py +7 -0
- pymoo/indicators/gd_plus.py +7 -0
- pymoo/indicators/hv/__init__.py +63 -0
- pymoo/indicators/hv/exact.py +71 -0
- pymoo/indicators/hv/exact_2d.py +102 -0
- pymoo/indicators/hv/monte_carlo.py +74 -0
- pymoo/indicators/igd.py +7 -0
- pymoo/indicators/igd_plus.py +7 -0
- pymoo/indicators/kktpm.py +151 -0
- pymoo/indicators/migd.py +55 -0
- pymoo/indicators/rmetric.py +203 -0
- pymoo/indicators/spacing.py +52 -0
- pymoo/mcdm/__init__.py +0 -0
- pymoo/mcdm/compromise_programming.py +19 -0
- pymoo/mcdm/high_tradeoff.py +40 -0
- pymoo/mcdm/pseudo_weights.py +32 -0
- pymoo/operators/__init__.py +0 -0
- pymoo/operators/control.py +187 -0
- pymoo/operators/crossover/__init__.py +0 -0
- pymoo/operators/crossover/binx.py +45 -0
- pymoo/operators/crossover/dex.py +122 -0
- pymoo/operators/crossover/erx.py +162 -0
- pymoo/operators/crossover/expx.py +51 -0
- pymoo/operators/crossover/hux.py +37 -0
- pymoo/operators/crossover/nox.py +13 -0
- pymoo/operators/crossover/ox.py +84 -0
- pymoo/operators/crossover/pcx.py +82 -0
- pymoo/operators/crossover/pntx.py +49 -0
- pymoo/operators/crossover/sbx.py +125 -0
- pymoo/operators/crossover/spx.py +5 -0
- pymoo/operators/crossover/ux.py +20 -0
- pymoo/operators/mutation/__init__.py +0 -0
- pymoo/operators/mutation/bitflip.py +17 -0
- pymoo/operators/mutation/gauss.py +58 -0
- pymoo/operators/mutation/inversion.py +42 -0
- pymoo/operators/mutation/nom.py +7 -0
- pymoo/operators/mutation/pm.py +94 -0
- pymoo/operators/mutation/rm.py +23 -0
- pymoo/operators/repair/__init__.py +0 -0
- pymoo/operators/repair/bounce_back.py +32 -0
- pymoo/operators/repair/bounds_repair.py +95 -0
- pymoo/operators/repair/inverse_penalty.py +89 -0
- pymoo/operators/repair/rounding.py +18 -0
- pymoo/operators/repair/to_bound.py +31 -0
- pymoo/operators/repair/vtype.py +11 -0
- pymoo/operators/sampling/__init__.py +0 -0
- pymoo/operators/sampling/lhs.py +73 -0
- pymoo/operators/sampling/rnd.py +50 -0
- pymoo/operators/selection/__init__.py +0 -0
- pymoo/operators/selection/rnd.py +72 -0
- pymoo/operators/selection/tournament.py +76 -0
- pymoo/operators/survival/__init__.py +0 -0
- pymoo/operators/survival/rank_and_crowding/__init__.py +1 -0
- pymoo/operators/survival/rank_and_crowding/classes.py +209 -0
- pymoo/operators/survival/rank_and_crowding/metrics.py +208 -0
- pymoo/optimize.py +72 -0
- pymoo/problems/__init__.py +157 -0
- pymoo/problems/dyn.py +47 -0
- pymoo/problems/dynamic/__init__.py +0 -0
- pymoo/problems/dynamic/cec2015.py +108 -0
- pymoo/problems/dynamic/df.py +452 -0
- pymoo/problems/dynamic/misc.py +167 -0
- pymoo/problems/functional.py +48 -0
- pymoo/problems/many/__init__.py +5 -0
- pymoo/problems/many/cdtlz.py +159 -0
- pymoo/problems/many/dcdtlz.py +88 -0
- pymoo/problems/many/dtlz.py +264 -0
- pymoo/problems/many/wfg.py +550 -0
- pymoo/problems/multi/__init__.py +14 -0
- pymoo/problems/multi/bnh.py +34 -0
- pymoo/problems/multi/carside.py +48 -0
- pymoo/problems/multi/clutch.py +104 -0
- pymoo/problems/multi/csi.py +55 -0
- pymoo/problems/multi/ctp.py +198 -0
- pymoo/problems/multi/dascmop.py +213 -0
- pymoo/problems/multi/kursawe.py +25 -0
- pymoo/problems/multi/modact.py +68 -0
- pymoo/problems/multi/mw.py +400 -0
- pymoo/problems/multi/omnitest.py +48 -0
- pymoo/problems/multi/osy.py +32 -0
- pymoo/problems/multi/srn.py +28 -0
- pymoo/problems/multi/sympart.py +94 -0
- pymoo/problems/multi/tnk.py +24 -0
- pymoo/problems/multi/truss2d.py +83 -0
- pymoo/problems/multi/welded_beam.py +41 -0
- pymoo/problems/multi/wrm.py +36 -0
- pymoo/problems/multi/zdt.py +151 -0
- pymoo/problems/multi_to_single.py +22 -0
- pymoo/problems/single/__init__.py +12 -0
- pymoo/problems/single/ackley.py +24 -0
- pymoo/problems/single/cantilevered_beam.py +34 -0
- pymoo/problems/single/flowshop_scheduling.py +112 -0
- pymoo/problems/single/g.py +874 -0
- pymoo/problems/single/griewank.py +18 -0
- pymoo/problems/single/himmelblau.py +15 -0
- pymoo/problems/single/knapsack.py +48 -0
- pymoo/problems/single/mopta08.py +26 -0
- pymoo/problems/single/multimodal.py +20 -0
- pymoo/problems/single/pressure_vessel.py +30 -0
- pymoo/problems/single/rastrigin.py +20 -0
- pymoo/problems/single/rosenbrock.py +22 -0
- pymoo/problems/single/schwefel.py +18 -0
- pymoo/problems/single/simple.py +13 -0
- pymoo/problems/single/sphere.py +19 -0
- pymoo/problems/single/traveling_salesman.py +79 -0
- pymoo/problems/single/zakharov.py +19 -0
- pymoo/problems/static.py +14 -0
- pymoo/problems/util.py +42 -0
- pymoo/problems/zero_to_one.py +27 -0
- pymoo/termination/__init__.py +23 -0
- pymoo/termination/collection.py +12 -0
- pymoo/termination/cv.py +48 -0
- pymoo/termination/default.py +45 -0
- pymoo/termination/delta.py +64 -0
- pymoo/termination/fmin.py +16 -0
- pymoo/termination/ftol.py +144 -0
- pymoo/termination/indicator.py +49 -0
- pymoo/termination/max_eval.py +14 -0
- pymoo/termination/max_gen.py +15 -0
- pymoo/termination/max_time.py +20 -0
- pymoo/termination/robust.py +34 -0
- pymoo/termination/xtol.py +33 -0
- pymoo/util/__init__.py +0 -0
- pymoo/util/archive.py +150 -0
- pymoo/util/cache.py +29 -0
- pymoo/util/clearing.py +82 -0
- pymoo/util/display/__init__.py +0 -0
- pymoo/util/display/column.py +52 -0
- pymoo/util/display/display.py +34 -0
- pymoo/util/display/multi.py +96 -0
- pymoo/util/display/output.py +53 -0
- pymoo/util/display/progress.py +54 -0
- pymoo/util/display/single.py +67 -0
- pymoo/util/dominator.py +67 -0
- pymoo/util/function_loader.py +129 -0
- pymoo/util/hv.py +23 -0
- pymoo/util/matlab_engine.py +39 -0
- pymoo/util/misc.py +460 -0
- pymoo/util/mnn.py +70 -0
- pymoo/util/nds/__init__.py +0 -0
- pymoo/util/nds/dominance_degree_non_dominated_sort.py +159 -0
- pymoo/util/nds/efficient_non_dominated_sort.py +152 -0
- pymoo/util/nds/fast_non_dominated_sort.py +70 -0
- pymoo/util/nds/naive_non_dominated_sort.py +36 -0
- pymoo/util/nds/non_dominated_sorting.py +67 -0
- pymoo/util/nds/tree_based_non_dominated_sort.py +133 -0
- pymoo/util/normalization.py +312 -0
- pymoo/util/optimum.py +42 -0
- pymoo/util/plotting.py +177 -0
- pymoo/util/pruning_cd.py +89 -0
- pymoo/util/randomized_argsort.py +60 -0
- pymoo/util/ref_dirs/__init__.py +24 -0
- pymoo/util/ref_dirs/construction.py +88 -0
- pymoo/util/ref_dirs/das_dennis.py +52 -0
- pymoo/util/ref_dirs/energy.py +319 -0
- pymoo/util/ref_dirs/energy_layer.py +119 -0
- pymoo/util/ref_dirs/genetic_algorithm.py +63 -0
- pymoo/util/ref_dirs/incremental.py +68 -0
- pymoo/util/ref_dirs/misc.py +128 -0
- pymoo/util/ref_dirs/optimizer.py +59 -0
- pymoo/util/ref_dirs/performance.py +162 -0
- pymoo/util/ref_dirs/reduction.py +85 -0
- pymoo/util/ref_dirs/sample_and_map.py +24 -0
- pymoo/util/reference_direction.py +260 -0
- pymoo/util/remote.py +55 -0
- pymoo/util/roulette.py +27 -0
- pymoo/util/running_metric.py +128 -0
- pymoo/util/sliding_window.py +25 -0
- pymoo/util/stochastic_ranking.py +32 -0
- pymoo/util/value_functions.py +719 -0
- pymoo/util/vectors.py +40 -0
- pymoo/util/vf_dominator.py +99 -0
- pymoo/vendor/__init__.py +0 -0
- pymoo/vendor/cec2018.py +398 -0
- pymoo/vendor/gta.py +617 -0
- pymoo/vendor/hv.py +267 -0
- pymoo/vendor/vendor_cmaes.py +412 -0
- pymoo/vendor/vendor_coco.py +81 -0
- pymoo/vendor/vendor_scipy.py +232 -0
- pymoo/version.py +1 -0
- pymoo/visualization/__init__.py +8 -0
- pymoo/visualization/fitness_landscape.py +127 -0
- pymoo/visualization/heatmap.py +123 -0
- pymoo/visualization/pcp.py +120 -0
- pymoo/visualization/petal.py +91 -0
- pymoo/visualization/radar.py +108 -0
- pymoo/visualization/radviz.py +68 -0
- pymoo/visualization/scatter.py +150 -0
- pymoo/visualization/star_coordinate.py +75 -0
- pymoo/visualization/util.py +123 -0
- pymoo/visualization/video/__init__.py +0 -0
- pymoo/visualization/video/callback_video.py +82 -0
- pymoo/visualization/video/one_var_one_obj.py +57 -0
- pymoo/visualization/video/two_var_one_obj.py +62 -0
- pymoo-0.6.1.5.dev0.dist-info/METADATA +187 -0
- pymoo-0.6.1.5.dev0.dist-info/RECORD +328 -0
- pymoo-0.6.1.5.dev0.dist-info/WHEEL +6 -0
- pymoo-0.6.1.5.dev0.dist-info/licenses/LICENSE +191 -0
- pymoo-0.6.1.5.dev0.dist-info/top_level.txt +1 -0
pymoo/core/individual.py
ADDED
|
@@ -0,0 +1,784 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Module containing infrastructure for representing individuals in
|
|
3
|
+
population-based optimization algorithms.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
# public API for when using ``from pymoo.core.individual import *``
|
|
7
|
+
__all__ = [
|
|
8
|
+
"default_config",
|
|
9
|
+
"Individual",
|
|
10
|
+
"calc_cv",
|
|
11
|
+
"constr_to_cv",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
import copy
|
|
15
|
+
from typing import Any
|
|
16
|
+
from typing import Optional
|
|
17
|
+
from typing import Tuple
|
|
18
|
+
from typing import Union
|
|
19
|
+
from warnings import warn
|
|
20
|
+
import numpy as np
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def default_config() -> dict:
|
|
24
|
+
"""
|
|
25
|
+
Get default constraint violation configuration settings.
|
|
26
|
+
|
|
27
|
+
Returns
|
|
28
|
+
-------
|
|
29
|
+
out : dict
|
|
30
|
+
A dictionary of default constraint violation settings.
|
|
31
|
+
"""
|
|
32
|
+
return dict(
|
|
33
|
+
cache = True,
|
|
34
|
+
cv_eps = 0.0,
|
|
35
|
+
cv_ieq = dict(scale=None, eps=0.0, pow=None, func=np.sum),
|
|
36
|
+
cv_eq = dict(scale=None, eps=1e-4, pow=None, func=np.sum),
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Individual:
|
|
41
|
+
"""
|
|
42
|
+
Base class for representing an individual in a population-based
|
|
43
|
+
optimization algorithm.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
# function: function to generate default configuration settings
|
|
47
|
+
default_config = default_config
|
|
48
|
+
|
|
49
|
+
def __init__(
|
|
50
|
+
self,
|
|
51
|
+
config: Optional[dict] = None,
|
|
52
|
+
**kwargs: Any,
|
|
53
|
+
) -> None:
|
|
54
|
+
"""
|
|
55
|
+
Constructor for the ``Invididual`` class.
|
|
56
|
+
|
|
57
|
+
Parameters
|
|
58
|
+
----------
|
|
59
|
+
config : dict, None
|
|
60
|
+
A dictionary of configuration metadata.
|
|
61
|
+
If ``None``, use a class-dependent default configuration.
|
|
62
|
+
kwargs : Any
|
|
63
|
+
Additional keyword arguments containing data which is to be stored
|
|
64
|
+
in the ``Individual``.
|
|
65
|
+
"""
|
|
66
|
+
# set decision variable vector to None
|
|
67
|
+
self._X = None
|
|
68
|
+
|
|
69
|
+
# set values objective(s), inequality constraint(s), equality
|
|
70
|
+
# contstraint(s) to None
|
|
71
|
+
self._F = None
|
|
72
|
+
self._G = None
|
|
73
|
+
self._H = None
|
|
74
|
+
|
|
75
|
+
# set first derivatives of objective(s), inequality constraint(s),
|
|
76
|
+
# equality contstraint(s) to None
|
|
77
|
+
self._dF = None
|
|
78
|
+
self._dG = None
|
|
79
|
+
self._dH = None
|
|
80
|
+
|
|
81
|
+
# set second derivatives of objective(s), inequality constraint(s),
|
|
82
|
+
# equality contstraint(s) to None
|
|
83
|
+
self._ddF = None
|
|
84
|
+
self._ddG = None
|
|
85
|
+
self._ddH = None
|
|
86
|
+
|
|
87
|
+
# set constraint violation value to None
|
|
88
|
+
self._CV = None
|
|
89
|
+
|
|
90
|
+
self.evaluated = None
|
|
91
|
+
|
|
92
|
+
# initialize all the local variables
|
|
93
|
+
self.reset()
|
|
94
|
+
|
|
95
|
+
# a local storage for data
|
|
96
|
+
self.data = {}
|
|
97
|
+
|
|
98
|
+
# the config for this individual
|
|
99
|
+
if config is None:
|
|
100
|
+
config = Individual.default_config()
|
|
101
|
+
self.config = config
|
|
102
|
+
|
|
103
|
+
for k, v in kwargs.items():
|
|
104
|
+
if k in self.__dict__:
|
|
105
|
+
self.__dict__[k] = v
|
|
106
|
+
elif "_" + k in self.__dict__:
|
|
107
|
+
self.__dict__["_" + k] = v
|
|
108
|
+
else:
|
|
109
|
+
self.data[k] = v
|
|
110
|
+
|
|
111
|
+
def reset(
|
|
112
|
+
self,
|
|
113
|
+
data: bool = True,
|
|
114
|
+
) -> None:
|
|
115
|
+
"""
|
|
116
|
+
Reset the value of objective(s), inequality constraint(s), equality
|
|
117
|
+
constraint(s), their first and second derivatives, the constraint
|
|
118
|
+
violation, and the metadata to empty values.
|
|
119
|
+
|
|
120
|
+
Parameters
|
|
121
|
+
----------
|
|
122
|
+
data : bool
|
|
123
|
+
Whether to reset metadata associated with the ``Individiual``.
|
|
124
|
+
"""
|
|
125
|
+
# create an empty array to share
|
|
126
|
+
empty = np.array([])
|
|
127
|
+
|
|
128
|
+
# design variables
|
|
129
|
+
self._X = empty
|
|
130
|
+
|
|
131
|
+
# objectives and constraint values
|
|
132
|
+
self._F = empty
|
|
133
|
+
self._G = empty
|
|
134
|
+
self._H = empty
|
|
135
|
+
|
|
136
|
+
# first order derivation
|
|
137
|
+
self._dF = empty
|
|
138
|
+
self._dG = empty
|
|
139
|
+
self._dH = empty
|
|
140
|
+
|
|
141
|
+
# second order derivation
|
|
142
|
+
self._ddF = empty
|
|
143
|
+
self._ddG = empty
|
|
144
|
+
self._ddH = empty
|
|
145
|
+
|
|
146
|
+
# if the constraint violation value to be used
|
|
147
|
+
self._CV = None
|
|
148
|
+
|
|
149
|
+
if data:
|
|
150
|
+
self.data = {}
|
|
151
|
+
|
|
152
|
+
# a set storing what has been evaluated
|
|
153
|
+
self.evaluated = set()
|
|
154
|
+
|
|
155
|
+
def has(
|
|
156
|
+
self,
|
|
157
|
+
key: str,
|
|
158
|
+
) -> bool:
|
|
159
|
+
"""
|
|
160
|
+
Determine whether an individual has a provided key or not.
|
|
161
|
+
|
|
162
|
+
Parameters
|
|
163
|
+
----------
|
|
164
|
+
key : str
|
|
165
|
+
The key for which to test.
|
|
166
|
+
|
|
167
|
+
Returns
|
|
168
|
+
-------
|
|
169
|
+
out : bool
|
|
170
|
+
Whether the ``Individual`` has the provided key.
|
|
171
|
+
"""
|
|
172
|
+
return hasattr(self.__class__, key) or key in self.data
|
|
173
|
+
|
|
174
|
+
# -------------------------------------------------------
|
|
175
|
+
# Values
|
|
176
|
+
# -------------------------------------------------------
|
|
177
|
+
|
|
178
|
+
@property
|
|
179
|
+
def X(self) -> np.ndarray:
|
|
180
|
+
"""
|
|
181
|
+
Get the decision vector for an individual.
|
|
182
|
+
|
|
183
|
+
Returns
|
|
184
|
+
-------
|
|
185
|
+
out : np.ndarray
|
|
186
|
+
The decision variable for the individual.
|
|
187
|
+
"""
|
|
188
|
+
return self._X
|
|
189
|
+
|
|
190
|
+
@X.setter
|
|
191
|
+
def X(self, value: np.ndarray) -> None:
|
|
192
|
+
"""
|
|
193
|
+
Set the decision vector for an individual.
|
|
194
|
+
|
|
195
|
+
Parameters
|
|
196
|
+
----------
|
|
197
|
+
value : np.ndarray
|
|
198
|
+
The decision variable for the individual.
|
|
199
|
+
"""
|
|
200
|
+
self._X = value
|
|
201
|
+
|
|
202
|
+
@property
|
|
203
|
+
def F(self) -> np.ndarray:
|
|
204
|
+
"""
|
|
205
|
+
Get the objective function vector for an individual.
|
|
206
|
+
|
|
207
|
+
Returns
|
|
208
|
+
-------
|
|
209
|
+
out : np.ndarray
|
|
210
|
+
The objective function vector for the individual.
|
|
211
|
+
"""
|
|
212
|
+
return self._F
|
|
213
|
+
|
|
214
|
+
@F.setter
|
|
215
|
+
def F(self, value: np.ndarray) -> None:
|
|
216
|
+
"""
|
|
217
|
+
Set the objective function vector for an individual.
|
|
218
|
+
|
|
219
|
+
Parameters
|
|
220
|
+
----------
|
|
221
|
+
value : np.ndarray
|
|
222
|
+
The objective function vector for the individual.
|
|
223
|
+
"""
|
|
224
|
+
self._F = value
|
|
225
|
+
|
|
226
|
+
@property
|
|
227
|
+
def G(self) -> np.ndarray:
|
|
228
|
+
"""
|
|
229
|
+
Get the inequality constraint vector for an individual.
|
|
230
|
+
|
|
231
|
+
Returns
|
|
232
|
+
-------
|
|
233
|
+
out : np.ndarray
|
|
234
|
+
The inequality constraint vector for the individual.
|
|
235
|
+
"""
|
|
236
|
+
return self._G
|
|
237
|
+
|
|
238
|
+
@G.setter
|
|
239
|
+
def G(self, value: np.ndarray) -> None:
|
|
240
|
+
"""
|
|
241
|
+
Set the inequality constraint vector for an individual.
|
|
242
|
+
|
|
243
|
+
Parameters
|
|
244
|
+
----------
|
|
245
|
+
value : np.ndarray
|
|
246
|
+
The inequality constraint vector for the individual.
|
|
247
|
+
"""
|
|
248
|
+
self._G = value
|
|
249
|
+
|
|
250
|
+
@property
|
|
251
|
+
def H(self) -> np.ndarray:
|
|
252
|
+
"""
|
|
253
|
+
Get the equality constraint vector for an individual.
|
|
254
|
+
|
|
255
|
+
Returns
|
|
256
|
+
-------
|
|
257
|
+
out : np.ndarray
|
|
258
|
+
The equality constraint vector for the individual.
|
|
259
|
+
"""
|
|
260
|
+
return self._H
|
|
261
|
+
|
|
262
|
+
@H.setter
|
|
263
|
+
def H(self, value: np.ndarray) -> None:
|
|
264
|
+
"""
|
|
265
|
+
Get the equality constraint vector for an individual.
|
|
266
|
+
|
|
267
|
+
Parameters
|
|
268
|
+
----------
|
|
269
|
+
value : np.ndarray
|
|
270
|
+
The equality constraint vector for the individual.
|
|
271
|
+
"""
|
|
272
|
+
self._H = value
|
|
273
|
+
|
|
274
|
+
@property
|
|
275
|
+
def CV(self) -> np.ndarray:
|
|
276
|
+
"""
|
|
277
|
+
Get the constraint violation vector for an individual by either reading
|
|
278
|
+
it from the cache or calculating it.
|
|
279
|
+
|
|
280
|
+
Returns
|
|
281
|
+
-------
|
|
282
|
+
out : np.ndarray
|
|
283
|
+
The constraint violation vector for an individual.
|
|
284
|
+
"""
|
|
285
|
+
config = self.config
|
|
286
|
+
cache = config["cache"]
|
|
287
|
+
|
|
288
|
+
if cache and self._CV is not None:
|
|
289
|
+
return self._CV
|
|
290
|
+
else:
|
|
291
|
+
self._CV = np.array([calc_cv(G=self.G, H=self.H, config=config)])
|
|
292
|
+
return self._CV
|
|
293
|
+
|
|
294
|
+
@CV.setter
|
|
295
|
+
def CV(self, value: np.ndarray) -> None:
|
|
296
|
+
"""
|
|
297
|
+
Set the constraint violation vector for an individual.
|
|
298
|
+
|
|
299
|
+
Parameters
|
|
300
|
+
----------
|
|
301
|
+
value : np.ndarray
|
|
302
|
+
The constraint violation vector for the individual.
|
|
303
|
+
"""
|
|
304
|
+
self._CV = value
|
|
305
|
+
|
|
306
|
+
@property
|
|
307
|
+
def FEAS(self) -> np.ndarray:
|
|
308
|
+
"""
|
|
309
|
+
Get whether an individual is feasible for each constraint.
|
|
310
|
+
|
|
311
|
+
Returns
|
|
312
|
+
-------
|
|
313
|
+
out : np.ndarray
|
|
314
|
+
An array containing whether each constraint is feasible for an
|
|
315
|
+
individual.
|
|
316
|
+
"""
|
|
317
|
+
eps = self.config.get("cv_eps", 0.0)
|
|
318
|
+
return self.CV <= eps
|
|
319
|
+
|
|
320
|
+
# -------------------------------------------------------
|
|
321
|
+
# Gradients
|
|
322
|
+
# -------------------------------------------------------
|
|
323
|
+
|
|
324
|
+
@property
|
|
325
|
+
def dF(self) -> np.ndarray:
|
|
326
|
+
"""
|
|
327
|
+
Get the objective function vector first derivatives for an individual.
|
|
328
|
+
|
|
329
|
+
Returns
|
|
330
|
+
-------
|
|
331
|
+
out : np.ndarray
|
|
332
|
+
The objective function vector first derivatives for the individual.
|
|
333
|
+
"""
|
|
334
|
+
return self._dF
|
|
335
|
+
|
|
336
|
+
@dF.setter
|
|
337
|
+
def dF(self, value: np.ndarray) -> None:
|
|
338
|
+
"""
|
|
339
|
+
Set the objective function vector first derivatives for an individual.
|
|
340
|
+
|
|
341
|
+
Parameters
|
|
342
|
+
----------
|
|
343
|
+
value : np.ndarray
|
|
344
|
+
The objective function vector first derivatives for the individual.
|
|
345
|
+
"""
|
|
346
|
+
self._dF = value
|
|
347
|
+
|
|
348
|
+
@property
|
|
349
|
+
def dG(self) -> np.ndarray:
|
|
350
|
+
"""
|
|
351
|
+
Get the inequality constraint(s) first derivatives for an individual.
|
|
352
|
+
|
|
353
|
+
Returns
|
|
354
|
+
-------
|
|
355
|
+
out : np.ndarray
|
|
356
|
+
The inequality constraint(s) first derivatives for the individual.
|
|
357
|
+
"""
|
|
358
|
+
return self._dG
|
|
359
|
+
|
|
360
|
+
@dG.setter
|
|
361
|
+
def dG(self, value: np.ndarray) -> None:
|
|
362
|
+
"""
|
|
363
|
+
Set the inequality constraint(s) first derivatives for an individual.
|
|
364
|
+
|
|
365
|
+
Parameters
|
|
366
|
+
----------
|
|
367
|
+
value : np.ndarray
|
|
368
|
+
The inequality constraint(s) first derivatives for the individual.
|
|
369
|
+
"""
|
|
370
|
+
self._dG = value
|
|
371
|
+
|
|
372
|
+
@property
|
|
373
|
+
def dH(self) -> np.ndarray:
|
|
374
|
+
"""
|
|
375
|
+
Get the equality constraint(s) first derivatives for an individual.
|
|
376
|
+
|
|
377
|
+
Returns
|
|
378
|
+
-------
|
|
379
|
+
out : np.ndarray
|
|
380
|
+
The equality constraint(s) first derivatives for the individual.
|
|
381
|
+
"""
|
|
382
|
+
return self._dH
|
|
383
|
+
|
|
384
|
+
@dH.setter
|
|
385
|
+
def dH(self, value: np.ndarray) -> None:
|
|
386
|
+
"""
|
|
387
|
+
Set the equality constraint(s) first derivatives for an individual.
|
|
388
|
+
|
|
389
|
+
Parameters
|
|
390
|
+
----------
|
|
391
|
+
value : np.ndarray
|
|
392
|
+
The equality constraint(s) first derivatives for the individual.
|
|
393
|
+
"""
|
|
394
|
+
self._dH = value
|
|
395
|
+
|
|
396
|
+
# -------------------------------------------------------
|
|
397
|
+
# Hessians
|
|
398
|
+
# -------------------------------------------------------
|
|
399
|
+
|
|
400
|
+
@property
|
|
401
|
+
def ddF(self) -> np.ndarray:
|
|
402
|
+
"""
|
|
403
|
+
Get the objective function vector second derivatives for an individual.
|
|
404
|
+
|
|
405
|
+
Returns
|
|
406
|
+
-------
|
|
407
|
+
out : np.ndarray
|
|
408
|
+
The objective function vector second derivatives for the individual.
|
|
409
|
+
"""
|
|
410
|
+
return self._ddF
|
|
411
|
+
|
|
412
|
+
@ddF.setter
|
|
413
|
+
def ddF(self, value: np.ndarray) -> None:
|
|
414
|
+
"""
|
|
415
|
+
Set the objective function vector second derivatives for an individual.
|
|
416
|
+
|
|
417
|
+
Parameters
|
|
418
|
+
----------
|
|
419
|
+
value : np.ndarray
|
|
420
|
+
The objective function vector second derivatives for the individual.
|
|
421
|
+
"""
|
|
422
|
+
self._ddF = value
|
|
423
|
+
|
|
424
|
+
@property
|
|
425
|
+
def ddG(self) -> np.ndarray:
|
|
426
|
+
"""
|
|
427
|
+
Get the inequality constraint(s) second derivatives for an individual.
|
|
428
|
+
|
|
429
|
+
Returns
|
|
430
|
+
-------
|
|
431
|
+
out : np.ndarray
|
|
432
|
+
The inequality constraint(s) second derivatives for the individual.
|
|
433
|
+
"""
|
|
434
|
+
return self._ddG
|
|
435
|
+
|
|
436
|
+
@ddG.setter
|
|
437
|
+
def ddG(self, value: np.ndarray) -> None:
|
|
438
|
+
"""
|
|
439
|
+
Set the inequality constraint(s) second derivatives for an individual.
|
|
440
|
+
|
|
441
|
+
Parameters
|
|
442
|
+
----------
|
|
443
|
+
value : np.ndarray
|
|
444
|
+
The inequality constraint(s) second derivatives for the individual.
|
|
445
|
+
"""
|
|
446
|
+
self._ddG = value
|
|
447
|
+
|
|
448
|
+
@property
|
|
449
|
+
def ddH(self) -> np.ndarray:
|
|
450
|
+
"""
|
|
451
|
+
Get the equality constraint(s) second derivatives for an individual.
|
|
452
|
+
|
|
453
|
+
Returns
|
|
454
|
+
-------
|
|
455
|
+
out : np.ndarray
|
|
456
|
+
The equality constraint(s) second derivatives for the individual.
|
|
457
|
+
"""
|
|
458
|
+
return self._ddH
|
|
459
|
+
|
|
460
|
+
@ddH.setter
|
|
461
|
+
def ddH(self, value: np.ndarray) -> None:
|
|
462
|
+
"""
|
|
463
|
+
Set the equality constraint(s) second derivatives for an individual.
|
|
464
|
+
|
|
465
|
+
Parameters
|
|
466
|
+
----------
|
|
467
|
+
value : np.ndarray
|
|
468
|
+
The equality constraint(s) second derivatives for the individual.
|
|
469
|
+
"""
|
|
470
|
+
self._ddH = value
|
|
471
|
+
|
|
472
|
+
# -------------------------------------------------------
|
|
473
|
+
# Convenience (value instead of array)
|
|
474
|
+
# -------------------------------------------------------
|
|
475
|
+
|
|
476
|
+
@property
|
|
477
|
+
def x(self) -> np.ndarray:
|
|
478
|
+
"""
|
|
479
|
+
Convenience property. Get the decision vector for an individual.
|
|
480
|
+
|
|
481
|
+
Returns
|
|
482
|
+
-------
|
|
483
|
+
out : np.ndarray
|
|
484
|
+
The decision variable for the individual.
|
|
485
|
+
"""
|
|
486
|
+
return self.X
|
|
487
|
+
|
|
488
|
+
@property
|
|
489
|
+
def f(self) -> float:
|
|
490
|
+
"""
|
|
491
|
+
Convenience property. Get the first objective function value for an individual.
|
|
492
|
+
|
|
493
|
+
Returns
|
|
494
|
+
-------
|
|
495
|
+
out : float
|
|
496
|
+
The first objective function value for the individual.
|
|
497
|
+
"""
|
|
498
|
+
return self.F[0]
|
|
499
|
+
|
|
500
|
+
@property
|
|
501
|
+
def cv(self) -> Union[float,None]:
|
|
502
|
+
"""
|
|
503
|
+
Convenience property. Get the first constraint violation value for an
|
|
504
|
+
individual by either reading it from the cache or calculating it.
|
|
505
|
+
|
|
506
|
+
Returns
|
|
507
|
+
-------
|
|
508
|
+
out : float, None
|
|
509
|
+
The constraint violation vector for an individual.
|
|
510
|
+
"""
|
|
511
|
+
if self.CV is None:
|
|
512
|
+
return None
|
|
513
|
+
else:
|
|
514
|
+
return self.CV[0]
|
|
515
|
+
|
|
516
|
+
@property
|
|
517
|
+
def feas(self) -> bool:
|
|
518
|
+
"""
|
|
519
|
+
Convenience property. Get whether an individual is feasible for the
|
|
520
|
+
first constraint.
|
|
521
|
+
|
|
522
|
+
Returns
|
|
523
|
+
-------
|
|
524
|
+
out : bool
|
|
525
|
+
Whether an individual is feasible for the first constraint.
|
|
526
|
+
"""
|
|
527
|
+
return self.FEAS[0]
|
|
528
|
+
|
|
529
|
+
# -------------------------------------------------------
|
|
530
|
+
# Deprecated
|
|
531
|
+
# -------------------------------------------------------
|
|
532
|
+
|
|
533
|
+
@property
|
|
534
|
+
def feasible(self) -> np.ndarray:
|
|
535
|
+
"""
|
|
536
|
+
Deprecated. Get whether an individual is feasible for each constraint.
|
|
537
|
+
|
|
538
|
+
Returns
|
|
539
|
+
-------
|
|
540
|
+
out : np.ndarray
|
|
541
|
+
An array containing whether each constraint is feasible for an
|
|
542
|
+
individual.
|
|
543
|
+
"""
|
|
544
|
+
warn(
|
|
545
|
+
"The ``feasible`` property for ``pymoo.core.individual.Individual`` is deprecated",
|
|
546
|
+
DeprecationWarning,
|
|
547
|
+
stacklevel = 2,
|
|
548
|
+
)
|
|
549
|
+
return self.FEAS
|
|
550
|
+
|
|
551
|
+
# -------------------------------------------------------
|
|
552
|
+
# Other Functions
|
|
553
|
+
# -------------------------------------------------------
|
|
554
|
+
|
|
555
|
+
def set_by_dict(
|
|
556
|
+
self,
|
|
557
|
+
**kwargs: Any
|
|
558
|
+
) -> None:
|
|
559
|
+
"""
|
|
560
|
+
Set an individual's data or metadata using values in a dictionary.
|
|
561
|
+
|
|
562
|
+
Parameters
|
|
563
|
+
----------
|
|
564
|
+
kwargs : Any
|
|
565
|
+
Keyword arguments defining the data to set.
|
|
566
|
+
"""
|
|
567
|
+
for k, v in kwargs.items():
|
|
568
|
+
self.set(k, v)
|
|
569
|
+
|
|
570
|
+
def set(
|
|
571
|
+
self,
|
|
572
|
+
key: str,
|
|
573
|
+
value: object,
|
|
574
|
+
) -> 'Individual':
|
|
575
|
+
"""
|
|
576
|
+
Set an individual's data or metadata based on a key and value.
|
|
577
|
+
|
|
578
|
+
Parameters
|
|
579
|
+
----------
|
|
580
|
+
key : str
|
|
581
|
+
Key of the data for which to set.
|
|
582
|
+
value : object
|
|
583
|
+
Value of the data for which to set.
|
|
584
|
+
|
|
585
|
+
Returns
|
|
586
|
+
-------
|
|
587
|
+
out : Individual
|
|
588
|
+
A reference to the ``Individual`` for which values were set.
|
|
589
|
+
"""
|
|
590
|
+
if hasattr(self, key):
|
|
591
|
+
setattr(self, key, value)
|
|
592
|
+
else:
|
|
593
|
+
self.data[key] = value
|
|
594
|
+
return self
|
|
595
|
+
|
|
596
|
+
def get(
|
|
597
|
+
self,
|
|
598
|
+
*keys: str,
|
|
599
|
+
) -> Union[tuple,object]:
|
|
600
|
+
"""
|
|
601
|
+
Get the values for one or more keys for an individual.
|
|
602
|
+
|
|
603
|
+
Parameters
|
|
604
|
+
----------
|
|
605
|
+
keys : str
|
|
606
|
+
Keys for which to get values.
|
|
607
|
+
|
|
608
|
+
Returns
|
|
609
|
+
-------
|
|
610
|
+
out : tuple, object
|
|
611
|
+
If more than one key provided, return a ``tuple`` of retrieved values.
|
|
612
|
+
If a single key provided, return the retrieved value.
|
|
613
|
+
"""
|
|
614
|
+
ret = []
|
|
615
|
+
|
|
616
|
+
for key in keys:
|
|
617
|
+
if hasattr(self, key):
|
|
618
|
+
v = getattr(self, key)
|
|
619
|
+
elif key in self.data:
|
|
620
|
+
v = self.data[key]
|
|
621
|
+
else:
|
|
622
|
+
v = None
|
|
623
|
+
|
|
624
|
+
ret.append(v)
|
|
625
|
+
|
|
626
|
+
if len(ret) == 1:
|
|
627
|
+
return ret[0]
|
|
628
|
+
else:
|
|
629
|
+
return tuple(ret)
|
|
630
|
+
|
|
631
|
+
def duplicate(
|
|
632
|
+
self,
|
|
633
|
+
key: str,
|
|
634
|
+
new_key: str,
|
|
635
|
+
) -> None:
|
|
636
|
+
"""
|
|
637
|
+
Duplicate a key to a new key.
|
|
638
|
+
|
|
639
|
+
Parameters
|
|
640
|
+
----------
|
|
641
|
+
key : str
|
|
642
|
+
Name of the key to duplicated.
|
|
643
|
+
new_key : str
|
|
644
|
+
Name of the key to which to duplicate the original key.
|
|
645
|
+
"""
|
|
646
|
+
self.set(new_key, self.get(key))
|
|
647
|
+
|
|
648
|
+
def new(self) -> 'Individual':
|
|
649
|
+
"""
|
|
650
|
+
Create a new instance of this class.
|
|
651
|
+
|
|
652
|
+
Returns
|
|
653
|
+
-------
|
|
654
|
+
out : Individual
|
|
655
|
+
A new instance of an ``Individual``.
|
|
656
|
+
"""
|
|
657
|
+
return self.__class__()
|
|
658
|
+
|
|
659
|
+
def copy(
|
|
660
|
+
self,
|
|
661
|
+
other: Optional['Individual'] = None,
|
|
662
|
+
deep: bool = True,
|
|
663
|
+
) -> 'Individual':
|
|
664
|
+
"""
|
|
665
|
+
Copy an individual.
|
|
666
|
+
|
|
667
|
+
Parameters
|
|
668
|
+
----------
|
|
669
|
+
other : Individual, None
|
|
670
|
+
The individual to copy. If ``None``, assumed to be self.
|
|
671
|
+
deep : bool
|
|
672
|
+
Whether to deep copy the individual.
|
|
673
|
+
|
|
674
|
+
Returns
|
|
675
|
+
-------
|
|
676
|
+
out : Individual
|
|
677
|
+
A copy of the individual.
|
|
678
|
+
"""
|
|
679
|
+
obj = self.new()
|
|
680
|
+
|
|
681
|
+
# if not provided just copy yourself
|
|
682
|
+
if other is None:
|
|
683
|
+
other = self
|
|
684
|
+
|
|
685
|
+
# the data the new object needs to have
|
|
686
|
+
D = other.__dict__
|
|
687
|
+
|
|
688
|
+
# if it should be a deep copy do it
|
|
689
|
+
if deep:
|
|
690
|
+
D = copy.deepcopy(D)
|
|
691
|
+
|
|
692
|
+
for k, v in D.items():
|
|
693
|
+
obj.__dict__[k] = v
|
|
694
|
+
|
|
695
|
+
return obj
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
def calc_cv(
|
|
699
|
+
G: Optional[np.ndarray] = None,
|
|
700
|
+
H: Optional[np.ndarray] = None,
|
|
701
|
+
config: Optional[dict] = None,
|
|
702
|
+
) -> np.ndarray:
|
|
703
|
+
"""
|
|
704
|
+
Calculate the constraint violation(s) for a set of inequality constraint(s),
|
|
705
|
+
equality constraint(s), and a scoring configuration.
|
|
706
|
+
|
|
707
|
+
Parameters
|
|
708
|
+
----------
|
|
709
|
+
G : np.ndarray, None
|
|
710
|
+
A vector of inequality constraint(s).
|
|
711
|
+
H : np.ndarray, None
|
|
712
|
+
A vector of equality constraint(s).
|
|
713
|
+
config : dict, None
|
|
714
|
+
A dictionary of constraint violation scoring configuration settings.
|
|
715
|
+
|
|
716
|
+
Returns
|
|
717
|
+
-------
|
|
718
|
+
out : np.ndarray
|
|
719
|
+
An array of constraint violations for each objective.
|
|
720
|
+
"""
|
|
721
|
+
if G is None:
|
|
722
|
+
G = np.array([])
|
|
723
|
+
|
|
724
|
+
if H is None:
|
|
725
|
+
H = np.array([])
|
|
726
|
+
|
|
727
|
+
if config is None:
|
|
728
|
+
config = Individual.default_config()
|
|
729
|
+
|
|
730
|
+
if G is None:
|
|
731
|
+
ieq_cv = [0.0]
|
|
732
|
+
elif G.ndim == 1:
|
|
733
|
+
ieq_cv = constr_to_cv(G, **config["cv_ieq"])
|
|
734
|
+
else:
|
|
735
|
+
ieq_cv = [constr_to_cv(g, **config["cv_ieq"]) for g in G]
|
|
736
|
+
|
|
737
|
+
if H is None:
|
|
738
|
+
eq_cv = [0.0]
|
|
739
|
+
elif H.ndim == 1:
|
|
740
|
+
eq_cv = constr_to_cv(np.abs(H), **config["cv_eq"])
|
|
741
|
+
else:
|
|
742
|
+
eq_cv = [constr_to_cv(np.abs(h), **config["cv_eq"]) for h in H]
|
|
743
|
+
|
|
744
|
+
return np.array(ieq_cv) + np.array(eq_cv)
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
def constr_to_cv(
|
|
748
|
+
c: Union[np.ndarray,None],
|
|
749
|
+
eps: float = 0.0,
|
|
750
|
+
scale: Optional[float] = None,
|
|
751
|
+
pow: Optional[float] = None,
|
|
752
|
+
func: object = np.mean,
|
|
753
|
+
) -> float:
|
|
754
|
+
"""
|
|
755
|
+
Convert a constraint to a constraint violation.
|
|
756
|
+
|
|
757
|
+
c : np.ndarray
|
|
758
|
+
An array of constraint violations.
|
|
759
|
+
eps : float
|
|
760
|
+
Error tolerance bounds.
|
|
761
|
+
scale : float, None
|
|
762
|
+
The scale to apply to a constraint violation.
|
|
763
|
+
If ``None``, no scale alteration is applied.
|
|
764
|
+
pow : float, None
|
|
765
|
+
A power to apply to a constraint violation.
|
|
766
|
+
If ``None``, no power alteration is applied.
|
|
767
|
+
func : function
|
|
768
|
+
A function to convert multiple constraint violations into a single score.
|
|
769
|
+
"""
|
|
770
|
+
if c is None or len(c) == 0:
|
|
771
|
+
return 0.0
|
|
772
|
+
|
|
773
|
+
# subtract eps to allow some violation and then zero out all values less than zero
|
|
774
|
+
c = np.maximum(0.0, c - eps)
|
|
775
|
+
|
|
776
|
+
# apply init_simplex_scale if necessary
|
|
777
|
+
if scale is not None:
|
|
778
|
+
c = c / scale
|
|
779
|
+
|
|
780
|
+
# if a pow factor has been provided
|
|
781
|
+
if pow is not None:
|
|
782
|
+
c = c ** pow
|
|
783
|
+
|
|
784
|
+
return func(c)
|