pydmoo 0.0.11__py3-none-any.whl → 0.0.13__py3-none-any.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.
pydmoo/__init__.py CHANGED
@@ -0,0 +1,5 @@
1
+ from ._version import __version__
2
+
3
+ __all__ = [
4
+ "__version__"
5
+ ]
pydmoo/_version.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "0.0.13"
@@ -0,0 +1,98 @@
1
+ from pydmoo.problems.dynamic.cec2015 import FDA4, FDA5
2
+ from pydmoo.problems.dynamic.df import DF1, DF2, DF3, DF4, DF5, DF6, DF7, DF8, DF9, DF10, DF11, DF12, DF13, DF14
3
+ from pydmoo.problems.dynamic.gts import (
4
+ GTS1,
5
+ GTS1_2,
6
+ GTS1_3,
7
+ GTS2,
8
+ GTS2_2,
9
+ GTS2_3,
10
+ GTS3,
11
+ GTS3_2,
12
+ GTS3_3,
13
+ GTS4,
14
+ GTS4_2,
15
+ GTS4_3,
16
+ GTS5,
17
+ GTS5_2,
18
+ GTS5_3,
19
+ GTS6,
20
+ GTS6_2,
21
+ GTS6_3,
22
+ GTS7,
23
+ GTS7_2,
24
+ GTS7_3,
25
+ GTS8,
26
+ GTS8_2,
27
+ GTS8_3,
28
+ GTS9,
29
+ GTS9_2,
30
+ GTS9_3,
31
+ GTS10,
32
+ GTS10_2,
33
+ GTS10_3,
34
+ GTS11,
35
+ GTS11_2,
36
+ GTS11_3,
37
+ )
38
+
39
+ PROBLEM = {
40
+ 'fda4': FDA4,
41
+ 'fda5': FDA5,
42
+ 'gts1': GTS1,
43
+ 'gts2': GTS2,
44
+ 'gts3': GTS3,
45
+ 'gts4': GTS4,
46
+ 'gts5': GTS5,
47
+ 'gts6': GTS6,
48
+ 'gts7': GTS7,
49
+ 'gts8': GTS8,
50
+ 'gts9': GTS9,
51
+ 'gts10': GTS10,
52
+ 'gts11': GTS11,
53
+ 'gts1_2': GTS1_2,
54
+ 'gts2_2': GTS2_2,
55
+ 'gts3_2': GTS3_2,
56
+ 'gts4_2': GTS4_2,
57
+ 'gts5_2': GTS5_2,
58
+ 'gts6_2': GTS6_2,
59
+ 'gts7_2': GTS7_2,
60
+ 'gts8_2': GTS8_2,
61
+ 'gts9_2': GTS9_2,
62
+ 'gts10_2': GTS10_2,
63
+ 'gts11_2': GTS11_2,
64
+ 'gts1_3': GTS1_3,
65
+ 'gts2_3': GTS2_3,
66
+ 'gts3_3': GTS3_3,
67
+ 'gts4_3': GTS4_3,
68
+ 'gts5_3': GTS5_3,
69
+ 'gts6_3': GTS6_3,
70
+ 'gts7_3': GTS7_3,
71
+ 'gts8_3': GTS8_3,
72
+ 'gts9_3': GTS9_3,
73
+ 'gts10_3': GTS10_3,
74
+ 'gts11_3': GTS11_3,
75
+ 'df1': DF1,
76
+ 'df2': DF2,
77
+ 'df3': DF3,
78
+ 'df4': DF4,
79
+ 'df5': DF5,
80
+ 'df6': DF6,
81
+ 'df7': DF7,
82
+ 'df8': DF8,
83
+ 'df9': DF9,
84
+ 'df10': DF10,
85
+ 'df11': DF11,
86
+ 'df12': DF12,
87
+ 'df13': DF13,
88
+ 'df14': DF14,
89
+ }
90
+
91
+
92
+ def get_problem(name, *args, **kwargs):
93
+ name = name.lower()
94
+
95
+ if name.lower() not in PROBLEM:
96
+ raise Exception("Problem not found.")
97
+
98
+ return PROBLEM[name.lower()](*args, **kwargs)
pydmoo/problems/dyn.py ADDED
@@ -0,0 +1,89 @@
1
+ """
2
+ Includes modified code from pymoo (https://github.com/anyoptimization/pymoo/blob/main/pymoo/problems/dyn.py),
3
+ licensed under Apache License 2.0. Original copyright and license terms are preserved.
4
+ """
5
+
6
+ from abc import ABC
7
+ from math import ceil
8
+
9
+ from mpmath import mp
10
+ from pymoo.core.callback import Callback
11
+ from pymoo.core.problem import Problem
12
+
13
+
14
+ class DynamicProblem(Problem, ABC):
15
+ pass
16
+
17
+
18
+ class DynamicTestProblem(DynamicProblem, ABC):
19
+
20
+ def __init__(self, nt, taut, t0=50, tau=1, time=None, add_time_perturbation=False, **kwargs):
21
+ super().__init__(**kwargs)
22
+ self.tau = tau
23
+ self.nt = nt
24
+ self.taut = taut
25
+ self.t0 = t0 # added by DynOpt
26
+ self._time = time
27
+
28
+ self.add_time_perturbation = add_time_perturbation # added by DynOpt
29
+
30
+ def tic(self, elapsed=1):
31
+
32
+ # increase the time counter by one
33
+ self.tau += elapsed
34
+
35
+ # remove the cache of the problem to recreate ps and pf
36
+ self.__dict__["cache"] = {}
37
+
38
+ @property
39
+ def time(self):
40
+ if self._time is not None:
41
+ return self._time
42
+ else:
43
+ # return 1 / self.nt * (self.tau // self.taut)
44
+
45
+ # added by DynOpt
46
+ delta_time = 1 / self.nt
47
+ count = max((self.tau + self.taut - (self.t0 + 1)), 0) // self.taut
48
+
49
+ if not self.add_time_perturbation:
50
+ ratio = 0
51
+
52
+ else:
53
+ mp.dps = max(ceil(10 + count), 10)
54
+ mp_pi = 0 if count == 0 else int(str(mp.pi).split(".")[-1][count - 1])
55
+ ratio = 0.5 * 1 / 9 * mp_pi
56
+
57
+ return delta_time * count + delta_time * ratio
58
+
59
+ @time.setter
60
+ def time(self, value):
61
+ self._time = value
62
+
63
+ # added by DynOpt
64
+ def update_to_next_time(self):
65
+
66
+ # update to next time
67
+ count = max((self.tau + self.taut - (self.t0 + 1)), 0) // self.taut
68
+
69
+ elapsed = int(count * self.taut + (self.t0 + 1) - self.tau)
70
+
71
+ self.tic(elapsed=elapsed)
72
+
73
+ return elapsed
74
+
75
+
76
+ class TimeSimulation(Callback):
77
+
78
+ def update(self, algorithm):
79
+ problem = algorithm.problem
80
+
81
+ # added by DynOpt
82
+ # Designed to handle time-linkage properties within the GTS test suites.
83
+ if hasattr(problem, "time_linkage") and hasattr(problem, "cal"):
84
+ problem.cal(algorithm.opt.get("F"))
85
+
86
+ if hasattr(problem, "tic"):
87
+ problem.tic()
88
+ else:
89
+ raise Exception("TimeSimulation can only be used for dynamic test problems.")
File without changes
@@ -0,0 +1,147 @@
1
+ """
2
+ Includes modified code from pymoo (https://github.com/anyoptimization/pymoo/blob/main/pymoo/problems/dynamic/cec2015.py),
3
+ licensed under Apache License 2.0. Original copyright and license terms are preserved.
4
+ """
5
+
6
+ from math import cos, fabs, floor, pi, sin, sqrt
7
+
8
+ import numpy as np
9
+
10
+ from pydmoo.problems.dyn import DynamicTestProblem
11
+ from pydmoo.problems.dynamic.df import get_PF
12
+
13
+
14
+ class DynamicCEC2015(DynamicTestProblem):
15
+
16
+ def __init__(self, n_var=10, nt=10, taut=20, n_obj=2, xl=0.0, xu=1.0, vtype=float, **kwargs):
17
+ super().__init__(nt, taut, n_var=n_var, n_obj=n_obj, xl=xl, xu=xu, vtype=vtype, **kwargs)
18
+
19
+
20
+ class FDA2DEB(DynamicCEC2015):
21
+
22
+ def __init__(self, n_var=30, **kwargs):
23
+ super().__init__(n_var=n_var, **kwargs)
24
+
25
+ def _evaluate(self, X, out, *args, **kwargs):
26
+ t = self.time
27
+ from pymoo.vendor.gta import fda2_deb as f
28
+ out["F"] = np.array([f(x, t) for x in X])
29
+
30
+
31
+ class FDA4(DynamicCEC2015):
32
+
33
+ def __init__(self, n_var=30, **kwargs):
34
+ super().__init__(n_var=n_var, n_obj=3, **kwargs)
35
+
36
+ def _evaluate(self, X, out, *args, **kwargs):
37
+ t = self.time
38
+ from pymoo.vendor.gta import FDA4 as f
39
+ out["F"] = np.array([f(x, t) for x in X])
40
+
41
+ # added by DynOpt
42
+ def _calc_pareto_front(self, *args, n_pareto_points=100, **kwargs):
43
+ H = 20
44
+ x1, x2 = np.meshgrid(np.linspace(0, 1, H), np.linspace(0, 1, H), indexing='xy')
45
+
46
+ f1 = np.cos(x1 * pi / 2) * np.cos(x2 * pi / 2)
47
+ f2 = np.cos(x1 * pi / 2) * np.sin(x2 * pi / 2)
48
+ f3 = np.sin(x1 * pi / 2)
49
+
50
+ h = get_PF(np.array([f1, f2, f3]), False)
51
+ return h
52
+
53
+
54
+ class FDA5(DynamicCEC2015):
55
+
56
+ def __init__(self, n_var=30, **kwargs):
57
+ super().__init__(n_var=n_var, n_obj=3, **kwargs)
58
+
59
+ def _evaluate(self, X, out, *args, **kwargs):
60
+ t = self.time
61
+ from pymoo.vendor.gta import FDA5 as f
62
+ out["F"] = np.array([f(x, t) for x in X])
63
+
64
+ # added by DynOpt
65
+ def _calc_pareto_front(self, *args, n_pareto_points=100, **kwargs):
66
+ H = 20
67
+ x1, x2 = np.meshgrid(np.linspace(0, 1, H), np.linspace(0, 1, H), indexing='xy')
68
+
69
+ G = fabs(sin(0.5 * pi * self.time))
70
+ g = G
71
+ F = 1 + 100 * pow(sin(0.5 * pi * self.time), 4)
72
+
73
+ x1 = np.power(x1, F)
74
+ x2 = np.power(x2, F)
75
+
76
+ f1 = (1 + g) * np.cos(x1 * pi / 2) * np.cos(x2 * pi / 2)
77
+ f2 = (1 + g) * np.cos(x1 * pi / 2) * np.sin(x2 * pi / 2)
78
+ f3 = (1 + g) * np.sin(x1 * pi / 2)
79
+
80
+ h = get_PF(np.array([f1, f2, f3]), True)
81
+ return h
82
+
83
+
84
+ class DIMP2(DynamicCEC2015):
85
+
86
+ def __init__(self, n_var=30, **kwargs):
87
+ super().__init__(n_var=n_var, **kwargs)
88
+
89
+ def _evaluate(self, X, out, *args, **kwargs):
90
+ t = self.time
91
+ from pymoo.vendor.gta import DIMP2 as f
92
+ out["F"] = np.array([f(x, t) for x in X])
93
+
94
+
95
+ class dMOP2(DynamicCEC2015):
96
+
97
+ def __init__(self, n_var=30, **kwargs):
98
+ super().__init__(n_var=n_var, **kwargs)
99
+
100
+ def _evaluate(self, X, out, *args, **kwargs):
101
+ t = self.time
102
+ from pymoo.vendor.gta import dMOP2 as f
103
+ out["F"] = np.array([f(x, t) for x in X])
104
+
105
+
106
+ class dMOP3(DynamicCEC2015):
107
+
108
+ def __init__(self, n_var=30, **kwargs):
109
+ super().__init__(n_var=n_var, **kwargs)
110
+
111
+ def _evaluate(self, X, out, *args, **kwargs):
112
+ t = self.time
113
+ from pymoo.vendor.gta import dMOP3 as f
114
+ out["F"] = np.array([f(x, t) for x in X])
115
+
116
+
117
+ class HE2(DynamicCEC2015):
118
+
119
+ def __init__(self, n_var=30, **kwargs):
120
+ super().__init__(n_var=n_var, **kwargs)
121
+
122
+ def _evaluate(self, X, out, *args, **kwargs):
123
+ t = self.time
124
+ from pymoo.vendor.gta import HE2 as f
125
+ out["F"] = np.array([f(x, t) for x in X])
126
+
127
+
128
+ class HE7(DynamicCEC2015):
129
+
130
+ def __init__(self, n_var=10, **kwargs):
131
+ super().__init__(n_var=n_var, **kwargs)
132
+
133
+ def _evaluate(self, X, out, *args, **kwargs):
134
+ t = self.time
135
+ from pymoo.vendor.gta import HE7 as f
136
+ out["F"] = np.array([f(x, t) for x in X])
137
+
138
+
139
+ class HE9(DynamicCEC2015):
140
+
141
+ def __init__(self, n_var=10, **kwargs):
142
+ super().__init__(n_var=n_var, **kwargs)
143
+
144
+ def _evaluate(self, X, out, *args, **kwargs):
145
+ t = self.time
146
+ from pymoo.vendor.gta import HE9 as f
147
+ out["F"] = np.array([f(x, t) for x in X])