pymoo 0.6.1.2__cp39-cp39-macosx_10_9_universal2.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.

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