pymoo 0.6.1.3__cp39-cp39-macosx_11_0_arm64.whl → 0.6.1.5.dev0__cp39-cp39-macosx_11_0_arm64.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 (57) hide show
  1. pymoo/algorithms/moo/age.py +13 -7
  2. pymoo/algorithms/moo/age2.py +49 -19
  3. pymoo/algorithms/moo/ctaea.py +2 -2
  4. pymoo/algorithms/moo/kgb.py +9 -9
  5. pymoo/algorithms/moo/nsga3.py +2 -2
  6. pymoo/algorithms/moo/pinsga2.py +370 -0
  7. pymoo/algorithms/moo/rnsga3.py +2 -2
  8. pymoo/algorithms/soo/nonconvex/es.py +3 -2
  9. pymoo/config.py +1 -1
  10. pymoo/core/algorithm.py +1 -1
  11. pymoo/core/individual.py +8 -7
  12. pymoo/core/replacement.py +5 -5
  13. pymoo/core/survival.py +1 -1
  14. pymoo/core/variable.py +9 -9
  15. pymoo/cython/calc_perpendicular_distance.cpython-39-darwin.so +0 -0
  16. pymoo/cython/calc_perpendicular_distance.pyx +67 -0
  17. pymoo/cython/decomposition.cpython-39-darwin.so +0 -0
  18. pymoo/cython/decomposition.pyx +165 -0
  19. pymoo/cython/hv.cpython-39-darwin.so +0 -0
  20. pymoo/cython/hv.pyx +18 -0
  21. pymoo/cython/info.cpython-39-darwin.so +0 -0
  22. pymoo/cython/info.pyx +5 -0
  23. pymoo/cython/mnn.cpython-39-darwin.so +0 -0
  24. pymoo/cython/mnn.pyx +273 -0
  25. pymoo/cython/non_dominated_sorting.cpython-39-darwin.so +0 -0
  26. pymoo/cython/non_dominated_sorting.pyx +645 -0
  27. pymoo/cython/pruning_cd.cpython-39-darwin.so +0 -0
  28. pymoo/cython/pruning_cd.pyx +197 -0
  29. pymoo/cython/stochastic_ranking.cpython-39-darwin.so +0 -0
  30. pymoo/cython/stochastic_ranking.pyx +49 -0
  31. pymoo/cython/vendor/hypervolume.cpp +1621 -0
  32. pymoo/docs.py +1 -1
  33. pymoo/operators/crossover/ox.py +1 -1
  34. pymoo/operators/selection/rnd.py +2 -2
  35. pymoo/operators/selection/tournament.py +5 -5
  36. pymoo/optimize.py +2 -2
  37. pymoo/problems/dynamic/df.py +4 -4
  38. pymoo/problems/single/traveling_salesman.py +1 -1
  39. pymoo/util/misc.py +2 -2
  40. pymoo/util/mnn.py +2 -2
  41. pymoo/util/nds/fast_non_dominated_sort.py +5 -3
  42. pymoo/util/nds/non_dominated_sorting.py +2 -2
  43. pymoo/util/normalization.py +5 -8
  44. pymoo/util/ref_dirs/energy.py +4 -2
  45. pymoo/util/ref_dirs/reduction.py +1 -1
  46. pymoo/util/reference_direction.py +3 -2
  47. pymoo/util/value_functions.py +719 -0
  48. pymoo/util/vf_dominator.py +99 -0
  49. pymoo/version.py +1 -1
  50. pymoo/visualization/heatmap.py +3 -3
  51. pymoo/visualization/pcp.py +1 -1
  52. pymoo/visualization/radar.py +1 -1
  53. {pymoo-0.6.1.3.dist-info → pymoo-0.6.1.5.dev0.dist-info}/METADATA +12 -13
  54. {pymoo-0.6.1.3.dist-info → pymoo-0.6.1.5.dev0.dist-info}/RECORD +328 -316
  55. {pymoo-0.6.1.3.dist-info → pymoo-0.6.1.5.dev0.dist-info}/WHEEL +2 -1
  56. {pymoo-0.6.1.3.dist-info → pymoo-0.6.1.5.dev0.dist-info/licenses}/LICENSE +0 -0
  57. {pymoo-0.6.1.3.dist-info → pymoo-0.6.1.5.dev0.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,5 @@
1
1
  import numpy as np
2
+ import math
2
3
 
3
4
  from pymoo.algorithms.base.genetic import GeneticAlgorithm
4
5
  from pymoo.algorithms.soo.nonconvex.ga import FitnessSurvival
@@ -43,9 +44,9 @@ class ES(GeneticAlgorithm):
43
44
  """
44
45
 
45
46
  if pop_size is None and n_offsprings is not None:
46
- pop_size = int(np.math.ceil(n_offsprings * rule))
47
+ pop_size = int(math.ceil(n_offsprings * rule))
47
48
  elif n_offsprings is None and pop_size is not None:
48
- n_offsprings = int(np.math.floor(pop_size / rule))
49
+ n_offsprings = int(math.floor(pop_size / rule))
49
50
 
50
51
  assert pop_size is not None and n_offsprings is not None, "You have to at least provivde pop_size of n_offsprings."
51
52
  assert n_offsprings >= 2 * pop_size, "The number of offsprings should be at least double the population size."
pymoo/config.py CHANGED
@@ -22,7 +22,7 @@ class Config:
22
22
  # whether when import a file the doc should be parsed - only activate when creating doc files
23
23
  parse_custom_docs = False
24
24
 
25
- # a method defining the endpoint to load data remotely - default from github repo
25
+ # a method defining the endpoint to load data remotely - default from GitHub repo
26
26
  @classmethod
27
27
  def data(cls):
28
28
  return f"https://raw.githubusercontent.com/anyoptimization/pymoo-data/main/"
pymoo/core/algorithm.py CHANGED
@@ -261,7 +261,7 @@ class Algorithm:
261
261
  opt = None
262
262
 
263
263
  # if no feasible solution has been found
264
- elif not np.any(opt.get("feasible")):
264
+ elif not np.any(opt.get("FEAS")):
265
265
  if self.return_least_infeasible:
266
266
  opt = filter_optimum(opt, least_infeasible=True)
267
267
  else:
pymoo/core/individual.py CHANGED
@@ -12,6 +12,7 @@ __all__ = [
12
12
  ]
13
13
 
14
14
  import copy
15
+ from typing import Any
15
16
  from typing import Optional
16
17
  from typing import Tuple
17
18
  from typing import Union
@@ -48,7 +49,7 @@ class Individual:
48
49
  def __init__(
49
50
  self,
50
51
  config: Optional[dict] = None,
51
- **kwargs: dict,
52
+ **kwargs: Any,
52
53
  ) -> None:
53
54
  """
54
55
  Constructor for the ``Invididual`` class.
@@ -58,7 +59,7 @@ class Individual:
58
59
  config : dict, None
59
60
  A dictionary of configuration metadata.
60
61
  If ``None``, use a class-dependent default configuration.
61
- kwargs : dict
62
+ kwargs : Any
62
63
  Additional keyword arguments containing data which is to be stored
63
64
  in the ``Individual``.
64
65
  """
@@ -553,14 +554,14 @@ class Individual:
553
554
 
554
555
  def set_by_dict(
555
556
  self,
556
- **kwargs: dict
557
+ **kwargs: Any
557
558
  ) -> None:
558
559
  """
559
560
  Set an individual's data or metadata using values in a dictionary.
560
561
 
561
562
  Parameters
562
563
  ----------
563
- kwargs : dict
564
+ kwargs : Any
564
565
  Keyword arguments defining the data to set.
565
566
  """
566
567
  for k, v in kwargs.items():
@@ -594,15 +595,15 @@ class Individual:
594
595
 
595
596
  def get(
596
597
  self,
597
- *keys: Tuple[str,...],
598
+ *keys: str,
598
599
  ) -> Union[tuple,object]:
599
600
  """
600
601
  Get the values for one or more keys for an individual.
601
602
 
602
603
  Parameters
603
604
  ----------
604
- keys : tuple
605
- A tuple of keys for which to get values.
605
+ keys : str
606
+ Keys for which to get values.
606
607
 
607
608
  Returns
608
609
  -------
pymoo/core/replacement.py CHANGED
@@ -7,12 +7,12 @@ from pymoo.core.survival import Survival
7
7
 
8
8
 
9
9
  def is_better(_new, _old, eps=0.0):
10
- both_infeasible = not _old.feasible[0] and not _new.feasible[0]
11
- both_feasible = _old.feasible[0] and _new.feasible[0]
10
+ both_infeasible = not _old.feas and not _new.feas
11
+ both_feasible = _old.feas and _new.feas
12
12
 
13
13
  if both_infeasible and _old.CV[0] - _new.CV[0] > eps:
14
14
  return True
15
- elif not _old.feasible and _new.feasible:
15
+ elif not _old.FEAS and _new.FEAS:
16
16
  return True
17
17
  elif both_feasible and _old.F[0] - _new.F[0] > eps:
18
18
  return True
@@ -59,8 +59,8 @@ class ImprovementReplacement(ReplacementSurvival):
59
59
 
60
60
  ret = np.full((len(pop), 1), False)
61
61
 
62
- pop_F, pop_CV, pop_feas = pop.get("F", "CV", "feasible")
63
- off_F, off_CV, off_feas = off.get("F", "CV", "feasible")
62
+ pop_F, pop_CV, pop_feas = pop.get("F", "CV", "FEAS")
63
+ off_F, off_CV, off_feas = off.get("F", "CV", "FEAS")
64
64
 
65
65
  if problem.has_constraints() > 0:
66
66
 
pymoo/core/survival.py CHANGED
@@ -86,7 +86,7 @@ class ToReplacement(Survival):
86
86
 
87
87
 
88
88
  def split_by_feasibility(pop, sort_infeas_by_cv=True, sort_feas_by_obj=False, return_pop=False):
89
- F, CV, b = pop.get("F", "CV", "feasible")
89
+ F, CV, b = pop.get("F", "CV", "FEAS")
90
90
 
91
91
  feasible = np.where(b)[0]
92
92
  infeasible = np.where(~b)[0]
pymoo/core/variable.py CHANGED
@@ -13,7 +13,7 @@ __all__ = [
13
13
  "get",
14
14
  ]
15
15
 
16
- from typing import Optional, Tuple
16
+ from typing import Any, Optional, Tuple
17
17
  from typing import Union
18
18
  import numpy as np
19
19
  from numpy.typing import ArrayLike
@@ -111,14 +111,14 @@ class Variable(object):
111
111
 
112
112
  def get(
113
113
  self,
114
- **kwargs: dict
114
+ **kwargs: Any
115
115
  ) -> object:
116
116
  """
117
117
  Get the value of a decision variable.
118
118
 
119
119
  Parameters
120
120
  ----------
121
- kwargs : dict
121
+ kwargs : Any
122
122
  Additional keyword arguments.
123
123
 
124
124
  Returns
@@ -139,7 +139,7 @@ class BoundedVariable(Variable):
139
139
  value: Optional[object] = None,
140
140
  bounds: Tuple[Optional[object],Optional[object]] = (None, None),
141
141
  strict: Optional[Tuple[Optional[object],Optional[object]]] = None,
142
- **kwargs: dict,
142
+ **kwargs: Any,
143
143
  ) -> None:
144
144
  """
145
145
  Constructor for the ``BoundedVariable`` class.
@@ -154,7 +154,7 @@ class BoundedVariable(Variable):
154
154
  strict : tuple, None
155
155
  Strict boundaries for the decision variable.
156
156
  If ``None``, the value of ``bounds`` is copied to ``strict``.
157
- kwargs : dict
157
+ kwargs : Any
158
158
  Additional keyword arguments for ``active`` and ``flag``.
159
159
  """
160
160
  # call the Variable constructor
@@ -302,7 +302,7 @@ class Choice(Variable):
302
302
  value: Optional[object] = None,
303
303
  options: Optional[ArrayLike] = None,
304
304
  all: Optional[ArrayLike] = None,
305
- **kwargs: dict,
305
+ **kwargs: Any,
306
306
  ) -> None:
307
307
  """
308
308
  Constructor for the ``Choice`` class.
@@ -316,7 +316,7 @@ class Choice(Variable):
316
316
  all : ArrayLike, None
317
317
  A strict list of decision variable options from which to choose.
318
318
  If ``None``, the value of ``options`` is copied to ``all``.
319
- kwargs : dict
319
+ kwargs : Any
320
320
  Additional keyword arguments for ``active`` and ``flag``.
321
321
  """
322
322
  # all super constructor
@@ -357,7 +357,7 @@ class Choice(Variable):
357
357
  def get(
358
358
  *args: Tuple[Union[Variable,object],...],
359
359
  size: Optional[Union[tuple,int]] = None,
360
- **kwargs: dict
360
+ **kwargs: Any
361
361
  ) -> Union[tuple,object,None]:
362
362
  """
363
363
  Get decision variable values from a tuple of ``Variable`` objects.
@@ -368,7 +368,7 @@ def get(
368
368
  A tuple of ``Variable`` or ``object``s.
369
369
  size : tuple, int, None
370
370
  Size to reshape decision variables.
371
- kwargs : dict
371
+ kwargs : Any
372
372
  Additional keyword arguments to pass to the ``get`` method of the
373
373
  ``Variable`` class when getting decision variable values.
374
374
 
@@ -0,0 +1,67 @@
1
+ # distutils: language = c++
2
+ # cython: language_level=2, boundscheck=False, wraparound=False, cdivision=True
3
+
4
+
5
+ import numpy as np
6
+ from libcpp.vector cimport vector
7
+
8
+
9
+
10
+ def calc_perpendicular_distance(double[:,:] P, double[:,:] L):
11
+ return np.array(c_calc_perpendicular_distance(P, L))
12
+
13
+
14
+ cdef extern from "math.h":
15
+ double sqrt(double m)
16
+ double pow(double base, double exponent)
17
+
18
+
19
+ cdef double c_norm(double[:] v):
20
+ cdef:
21
+ double val
22
+ int i
23
+ val = 0
24
+ for i in range(v.shape[0]):
25
+ val += pow(v[i], 2)
26
+ val = sqrt(val)
27
+ return val
28
+
29
+
30
+ cdef double[:,:] c_calc_perpendicular_distance(double[:,:] P, double[:,:] L):
31
+ cdef :
32
+ int s_L, s_P, n_dim, i, j, k
33
+ double[:,:] M
34
+ vector[double] N
35
+ double norm, dot, perp_dist, norm_scalar_proj
36
+
37
+ s_L = L.shape[0]
38
+ s_P = P.shape[0]
39
+ n_dim = L.shape[1]
40
+
41
+ M = np.zeros((s_P, s_L), dtype=np.float64)
42
+
43
+ for i in range(s_L):
44
+
45
+ norm = c_norm(L[i, :])
46
+
47
+ N = vector[double](n_dim)
48
+ for k in range(n_dim):
49
+ N[k] = L[i, k] / norm
50
+
51
+ for j in range(s_P):
52
+
53
+ dot = 0
54
+ for k in range(n_dim):
55
+ dot += L[i, k] * P[j, k]
56
+ norm_scalar_proj = dot / norm
57
+
58
+ perp_dist = 0
59
+ for k in range(n_dim):
60
+ perp_dist += pow(norm_scalar_proj * N[k] - P[j, k], 2)
61
+ perp_dist = sqrt(perp_dist)
62
+
63
+ M[j, i] = perp_dist
64
+
65
+ return M
66
+
67
+
@@ -0,0 +1,165 @@
1
+ # distutils: language = c++
2
+ # cython: language_level=2, boundscheck=False, wraparound=False, cdivision=True
3
+
4
+
5
+ import numpy as np
6
+ from libcpp.vector cimport vector
7
+
8
+
9
+ # -----------------------------------------------------------
10
+ # INTERFACE
11
+ # -----------------------------------------------------------
12
+
13
+ def calc_perpendicular_distance(double[:,:] P, double[:,:] L):
14
+ return np.array(c_calc_perpendicular_distance(P, L))
15
+
16
+
17
+ def pbi(double[:,:] F, double[:,:] weights, double[:] ideal_point, double theta, double eps=1e-10):
18
+ return np.array(c_pbi(F, weights, ideal_point, theta, eps), dtype=np.float64)
19
+
20
+
21
+ def calc_distance_to_weights(F, weights, utopian_point=None):
22
+
23
+ if utopian_point is None:
24
+ utopian_point = np.zeros(F.shape[1])
25
+
26
+ norm = np.linalg.norm(weights, axis=1)
27
+
28
+ d1, d2 = np.zeros(F.shape[0]), np.zeros(F.shape[0])
29
+
30
+ F = F - utopian_point
31
+ c_d1(d1, F, weights, norm)
32
+ c_d2(d2, F, weights, d1, norm)
33
+
34
+ return d1, d2
35
+
36
+
37
+ # -----------------------------------------------------------
38
+ # IMPLEMENTATION
39
+ # -----------------------------------------------------------
40
+
41
+ cdef extern from "math.h":
42
+ double sqrt(double m)
43
+ double pow(double base, double exponent)
44
+
45
+
46
+
47
+
48
+ cdef double c_norm(double[:] v):
49
+ cdef:
50
+ double val
51
+ int i
52
+
53
+ val = 0
54
+ for i in range(v.shape[0]):
55
+ val += pow(v[i], 2)
56
+ val = sqrt(val)
57
+ return val
58
+
59
+
60
+ cdef double[:,:] c_calc_perpendicular_distance(double[:,:] P, double[:,:] L):
61
+ cdef :
62
+ int s_L, s_P, n_dim, i, j, k
63
+ double[:,:] M
64
+ vector[double] N
65
+ double norm, dot, perp_dist, norm_scalar_proj
66
+
67
+ s_L = L.shape[0]
68
+ s_P = P.shape[0]
69
+ n_dim = L.shape[1]
70
+
71
+ M = np.zeros((s_P, s_L), dtype=np.float64)
72
+
73
+ for i in range(s_L):
74
+
75
+ norm = c_norm(L[i, :])
76
+
77
+ N = vector[double](n_dim)
78
+ for k in range(n_dim):
79
+ N[k] = L[i, k] / norm
80
+
81
+ for j in range(s_P):
82
+
83
+ dot = 0
84
+ for k in range(n_dim):
85
+ dot += L[i, k] * P[j, k]
86
+ norm_scalar_proj = dot / norm
87
+
88
+ perp_dist = 0
89
+ for k in range(n_dim):
90
+ perp_dist += pow(norm_scalar_proj * N[k] - P[j, k], 2)
91
+ perp_dist = sqrt(perp_dist)
92
+
93
+ M[j, i] = perp_dist
94
+
95
+ return M
96
+
97
+
98
+
99
+ cdef vector[double] c_pbi(double[:,:] F, double[:,:] weights, double[:] ideal_point, double theta, double eps):
100
+ cdef:
101
+ double d1, d2, f_max, norm
102
+ int i, j, n_dim
103
+ vector[double] pbi
104
+
105
+ n_points = F.shape[0]
106
+ n_obj = F.shape[1]
107
+ pbi = vector[double](n_points)
108
+
109
+ for i in range(n_points):
110
+
111
+ norm = c_norm(weights[i,:])
112
+
113
+ d1 = 0
114
+ for j in range(n_obj):
115
+ d1 += (F[i,j] - ideal_point[j] + eps) * weights[i,j]
116
+ d1 = d1 / norm
117
+
118
+ d2 = 0
119
+ for j in range(n_obj):
120
+ d2 += pow(F[i,j] - ideal_point[j] + eps - (d1 * weights[i,j] / norm), 2.0)
121
+ d2 = sqrt(d2)
122
+
123
+ pbi[i] = d1 + theta * d2
124
+
125
+ return pbi
126
+
127
+
128
+
129
+
130
+ cdef void c_d1(double[:] d1, double[:,:] F, double[:,:] weights, double[:] norm):
131
+ cdef:
132
+ double val
133
+ int i, j
134
+
135
+ n_points = F.shape[0]
136
+ n_obj = F.shape[1]
137
+
138
+ for i in range(n_points):
139
+
140
+ val = 0
141
+ for j in range(n_obj):
142
+ val += F[i,j] * weights[i,j]
143
+ d1[i] = val / norm[i]
144
+
145
+
146
+
147
+
148
+ cdef void c_d2(double[:] d2, double[:,:] F, double[:,:] weights, double[:] d1, double[:] norm):
149
+ cdef:
150
+ double val
151
+ int i, j
152
+
153
+ n_points = F.shape[0]
154
+ n_obj = F.shape[1]
155
+
156
+ for i in range(n_points):
157
+
158
+ val = 0
159
+ for j in range(n_obj):
160
+ val += pow(F[i,j] - (d1[i] * weights[i,j] / norm[i]), 2.0)
161
+ d2[i] = sqrt(val)
162
+
163
+
164
+
165
+
Binary file
pymoo/cython/hv.pyx ADDED
@@ -0,0 +1,18 @@
1
+ # distutils: language = c++
2
+ # cython: language_level=2, boundscheck=False, wraparound=False, cdivision=True
3
+
4
+ import numpy as np
5
+
6
+ cdef extern from "vendor/hypervolume.cpp":
7
+ double overmars_yap(double * points, double * referencePoint, unsigned noObjectives, unsigned noPoints);
8
+
9
+
10
+ def hv(ref_point, F):
11
+ F = F[np.argsort(F[:, -1])]
12
+ n, m = F.shape
13
+ return c_hv(F, ref_point, m, n)
14
+
15
+
16
+ def c_hv(double[:,:] F, double[:] ref_point, m, n):
17
+ return overmars_yap(&F[0, 0], &ref_point[0], m, n)
18
+ # return fpli_hv(&F[0,0], m, n, &ref_point[0])
Binary file
pymoo/cython/info.pyx ADDED
@@ -0,0 +1,5 @@
1
+ # distutils: language = c++
2
+ # cython: language_level=2, boundscheck=False, wraparound=False, cdivision=True
3
+
4
+ def info():
5
+ return "yes"
Binary file