pydmoo 0.0.11__py3-none-any.whl → 0.0.12__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.
@@ -0,0 +1,456 @@
1
+ """
2
+ Includes modified code from pymoo (https://github.com/anyoptimization/pymoo/blob/main/pymoo/problems/dynamic/df.py),
3
+ licensed under Apache License 2.0. Original copyright and license terms are preserved.
4
+ """
5
+
6
+ import numpy as np
7
+ from pymoo.util.nds.non_dominated_sorting import NonDominatedSorting
8
+ from pymoo.util.remote import Remote
9
+
10
+ from pydmoo.problems.dyn import DynamicTestProblem
11
+
12
+
13
+ class DF(DynamicTestProblem):
14
+
15
+ def __init__(self, n_var=10, nt=10, taut=20, **kwargs):
16
+ super().__init__(nt,
17
+ taut,
18
+ n_var=n_var,
19
+ n_obj=2,
20
+ xl=0,
21
+ xu=1,
22
+ **kwargs)
23
+
24
+ def _calc_pareto_front(self, *args, **kwargs):
25
+ return Remote.get_instance().load("pymoo", "pf", "DF", f"{str(self.__class__.__name__)}.pf")
26
+
27
+
28
+ class DF1(DF):
29
+
30
+ def _evaluate(self, x, out, *args, **kwargs):
31
+ v = np.sin(0.5 * np.pi * self.time)
32
+
33
+ G = np.abs(v)
34
+ H = 0.75 * v + 1.25
35
+ g = 1 + np.sum((x[:, 1:] - G) ** 2, axis=1)
36
+
37
+ f1 = x[:, 0]
38
+ f2 = g * (1 - ((f1 / g) ** H))
39
+
40
+ out["F"] = np.column_stack([f1, f2])
41
+
42
+ def _calc_pareto_front(self, *args, n_pareto_points=100, **kwargs):
43
+ v = np.sin(0.5 * np.pi * self.time)
44
+ H = 0.75 * v + 1.25
45
+
46
+ f1 = np.linspace(0, 1, n_pareto_points)
47
+ return np.array([f1, 1 - f1 ** H]).T
48
+
49
+
50
+ class DF2(DF):
51
+ def _evaluate(self, x, out, *args, **kwargs):
52
+ v = np.sin(0.5 * np.pi * self.time)
53
+ G = np.abs(v)
54
+
55
+ n = self.n_var
56
+ r = int((n - 1) * G)
57
+ not_r = [k for k in range(n) if k != r]
58
+
59
+ g = 1 + np.sum((x[:, not_r] - G) ** 2, axis=1)
60
+
61
+ f1 = x[:, r]
62
+ f2 = g * (1 - np.power(f1 / g, 0.5))
63
+
64
+ out["F"] = np.column_stack([f1, f2])
65
+
66
+ def _calc_pareto_front(self, *args, n_pareto_points=100, **kwargs):
67
+ f1 = np.linspace(0, 1, n_pareto_points)
68
+ return np.array([f1, 1 - np.sqrt(f1)]).T
69
+
70
+
71
+ class DF3(DF):
72
+ def __init__(self, **kwargs):
73
+ super().__init__(**kwargs)
74
+ self.xl[1:] = -1.0
75
+ self.xu[1:] = 2.0
76
+
77
+ def _evaluate(self, x, out, *args, **kwargs):
78
+ G = np.sin(0.5 * np.pi * self.time)
79
+ H = G + 1.5
80
+
81
+ g = 1 + np.sum((x[:, 1:] - G - x[:, [0]] ** H) ** 2, axis=1)
82
+ f1 = x[:, 0]
83
+ f2 = g * (1 - (x[:, 0] / g) ** H)
84
+
85
+ out["F"] = np.column_stack([f1, f2])
86
+
87
+ def _calc_pareto_front(self, *args, n_pareto_points=100, **kwargs):
88
+ x = np.linspace(0, 1, n_pareto_points)
89
+ g = 1
90
+
91
+ G = np.sin(np.dot(np.dot(0.5, np.pi), self.time))
92
+ H = G + 1.5
93
+ f1 = np.copy(x)
94
+ f2 = np.dot(g, (1 - (x / g) ** H))
95
+
96
+ return np.column_stack([f1, f2])
97
+
98
+
99
+ class DF4(DF):
100
+
101
+ def __init__(self, **kwargs):
102
+ super().__init__(**kwargs)
103
+ self.xl[:] = -2.0
104
+ self.xu[:] = +2.0
105
+
106
+ def _evaluate(self, x, out, *args, **kwargs):
107
+ n = self.n_var
108
+ a = np.sin(0.5 * np.pi * self.time)
109
+ b = 1 + np.abs(np.cos(0.5 * np.pi * self.time))
110
+ H = 1.5 + a
111
+ c = np.maximum(np.abs(a), a + b)
112
+
113
+ g = 1.0
114
+ for i in range(1, n):
115
+ g += (x[:, i] - (a * (x[:, 0] / c) ** 2 / (i + 1))) ** 2
116
+
117
+ f1 = g * np.abs(x[:, 0] - a) ** H
118
+ f2 = g * np.abs(x[:, 0] - a - b) ** H
119
+
120
+ out["F"] = np.column_stack([f1, f2])
121
+
122
+ def _calc_pareto_front(self, *args, n_pareto_points=100, **kwargs):
123
+ a = np.sin(0.5 * np.pi * self.time)
124
+ b = 1 + np.abs(np.cos(0.5 * np.pi * self.time))
125
+ H = 1.5 + a
126
+ x = np.linspace(a, a + b, n_pareto_points)
127
+
128
+ f1 = np.abs(x - a) ** H
129
+ f2 = np.abs(x - a - b) ** H
130
+
131
+ return np.array([f1, f2]).T
132
+
133
+
134
+ class DF5(DF):
135
+ def __init__(self, **kwargs):
136
+ super().__init__(**kwargs)
137
+ self.xl[1:] = -1.0
138
+ self.xu[1:] = +1.0
139
+
140
+ def _evaluate(self, x, out, *args, **kwargs):
141
+ G = np.sin(0.5 * np.pi * self.time)
142
+ w = np.floor(10 * G)
143
+ g = 1 + np.sum((x[:, 1:] - G) ** 2, axis=1)
144
+ f1 = g * (x[:, 0] + 0.02 * np.sin(w * np.pi * x[:, 0]))
145
+ f2 = g * (1 - x[:, 0] + 0.02 * np.sin(w * np.pi * x[:, 0]))
146
+
147
+ out["F"] = np.column_stack([f1, f2])
148
+
149
+ def _calc_pareto_front(self, *args, n_pareto_points=100, **kwargs):
150
+ x = np.linspace(0, 1, n_pareto_points)
151
+ G = np.sin(0.5 * np.pi * self.time)
152
+ w = np.floor(10 * G)
153
+ f1 = x + 0.02 * np.sin(w * np.pi * x)
154
+ f2 = 1 - x + 0.02 * np.sin(w * np.pi * x)
155
+ return np.array([f1, f2]).T
156
+
157
+
158
+ class DF6(DF):
159
+ def __init__(self, **kwargs):
160
+ super().__init__(**kwargs)
161
+ self.xl[1:] = -1.0
162
+ self.xu[1:] = +1.0
163
+
164
+ def _evaluate(self, x, out, *args, **kwargs):
165
+ G = np.sin(0.5 * np.pi * self.time)
166
+ a = 0.2 + 2.8 * np.abs(G)
167
+ y = x[:, 1:] - G
168
+ g = 1 + np.sum((np.abs(G) * y ** 2 - 10 * np.cos(2 * np.pi * y) + 10), axis=1)
169
+
170
+ f1 = g * np.power(x[:, 0] + 0.1 * np.sin(3 * np.pi * x[:, 0]), a)
171
+ f2 = g * np.power(1 - x[:, 0] + 0.1 * np.sin(3 * np.pi * x[:, 0]), a)
172
+
173
+ out["F"] = np.column_stack([f1, f2])
174
+
175
+ def _calc_pareto_front(self, *args, n_pareto_points=100, **kwargs):
176
+ x = np.linspace(0, 1, n_pareto_points)
177
+ G = np.sin(0.5 * np.pi * self.time)
178
+ a = 0.2 + 2.8 * np.abs(G)
179
+ f1 = (x + 0.1 * np.sin(3 * np.pi * x)) ** a
180
+ f2 = (1 - x + 0.1 * np.sin(3 * np.pi * x)) ** a
181
+
182
+ return np.array([f1, f2]).T
183
+
184
+
185
+ class DF7(DF):
186
+
187
+ def __init__(self, **kwargs):
188
+ super().__init__(**kwargs)
189
+ self.xl[0] = 1.0
190
+ self.xu[0] = 4.0
191
+
192
+ def _evaluate(self, x, out, *args, **kwargs):
193
+ a = 5 * np.cos(0.5 * np.pi * self.time)
194
+ g = 1 + np.sum((x[:, 1:] - 1 / (1 + np.exp(a * (x[:, [0]] - 2.5)))) ** 2, axis=1)
195
+
196
+ f1 = g * (1 + self.time) / x[:, 0]
197
+ f2 = g * x[:, 0] / (1 + self.time)
198
+
199
+ out["F"] = np.column_stack([f1, f2])
200
+
201
+ def _calc_pareto_front(self, *args, n_pareto_points=100, **kwargs):
202
+ x = np.linspace(1, 4, n_pareto_points)
203
+ f1 = (1 + self.time) / x
204
+ f2 = x / (1 + self.time)
205
+ pf = np.array([f1, f2]).T
206
+ pf = pf[np.argsort(pf[:, 0])]
207
+ return pf
208
+
209
+
210
+ class DF8(DF):
211
+
212
+ def __init__(self, **kwargs):
213
+ super().__init__(**kwargs)
214
+ self.xl[1:] = -1.0
215
+ self.xu[1:] = +1.0
216
+
217
+ def _evaluate(self, x, out, *args, **kwargs):
218
+ G = np.sin(0.5 * np.pi * self.time)
219
+ a = 2.25 + 2 * np.cos(2 * np.pi * self.time)
220
+ b = 1
221
+ tmp = G * np.sin(4 * np.pi * np.power(x[:, 0].reshape(len(x), 1), b)) / (1 + np.abs(G))
222
+ g = 1 + np.sum((x[:, 1:] - tmp) ** 2, axis=1)
223
+ f1 = g * (x[:, 0] + 0.1 * np.sin(3 * np.pi * x[:, 0]))
224
+ f2 = g * np.power(1 - x[:, 0] + 0.1 * np.sin(3 * np.pi * x[:, 0]), a)
225
+
226
+ out["F"] = np.column_stack([f1, f2])
227
+
228
+ def _calc_pareto_front(self, *args, n_pareto_points=100, **kwargs):
229
+ x = np.linspace(0, 1, n_pareto_points)
230
+ a = 2.25 + 2 * np.cos(2 * np.pi * self.time)
231
+
232
+ f1 = x + 0.1 * np.sin(3 * np.pi * x)
233
+ f2 = (1 - x + 0.1 * np.sin(3 * np.pi * x)) ** a
234
+
235
+ return np.array([f1, f2]).T
236
+
237
+
238
+ class DF9(DF):
239
+
240
+ def __init__(self, **kwargs):
241
+ super().__init__(**kwargs)
242
+ self.xl[1:] = -1.0
243
+ self.xu[1:] = +1.0
244
+
245
+ def _evaluate(self, x, out, *args, **kwargs):
246
+ _, n = x.shape
247
+ N = 1 + np.floor(10 * np.abs(np.sin(0.5 * np.pi * self.time)))
248
+ g = 1
249
+ for i in range(1, n):
250
+ tmp = x[:, i] - np.cos(4 * self.time + x[:, 0] + x[:, i - 1])
251
+ g = g + tmp ** 2
252
+ f1 = g * (x[:, 0] + np.maximum(0, (0.1 + 0.5 / N) * np.sin(2 * N * np.pi * x[:, 0])))
253
+ f2 = g * (1 - x[:, 0] + np.maximum(0, (0.1 + 0.5 / N) * np.sin(2 * N * np.pi * x[:, 0])))
254
+
255
+ out["F"] = np.column_stack([f1, f2])
256
+
257
+ def _calc_pareto_front(self, *args, n_pareto_points=100, **kwargs):
258
+ x = np.linspace(0, 1, n_pareto_points)
259
+ N = 1 + np.floor(10 * np.abs(np.sin(0.5 * np.pi * self.time)))
260
+
261
+ f1 = x + np.maximum(0, (0.1 + 0.5 / N) * np.sin(2 * N * np.pi * x))
262
+ f2 = 1 - x + np.maximum(0, (0.1 + 0.5 / N) * np.sin(2 * N * np.pi * x))
263
+
264
+ h = get_PF(np.array([f1, f2]), True)
265
+ return h
266
+
267
+
268
+ class DF10(DF):
269
+
270
+ def __init__(self, **kwargs):
271
+ super().__init__(**kwargs)
272
+ self.xl[2:] = -1.0
273
+ self.xu[2:] = +1.0
274
+ self.n_obj = 3
275
+
276
+ def _evaluate(self, x, out, *args, **kwargs):
277
+ G = np.sin(0.5 * np.pi * self.time)
278
+ H = 2.25 + 2 * np.cos(0.5 * np.pi * self.time)
279
+ x0 = x[:, 0].reshape(len(x), 1)
280
+ x1 = x[:, 1].reshape(len(x), 1)
281
+ tmp = np.sin(4 * np.pi * (x0 + x1)) / (1 + np.abs(G)) # in the document is 2*
282
+ g = 1 + np.sum((x[:, 2:] - tmp) ** 2, axis=1)
283
+ g = g.reshape(len(g), 1)
284
+ f1 = (g * np.power(np.sin(0.5 * np.pi * x0), H)).reshape(len(g), )
285
+ f2 = (g * np.power(np.sin(0.5 * np.pi * x1) * np.cos(0.5 * np.pi * x0), H)).reshape(len(g), )
286
+ f3 = (g * np.power(np.cos(0.5 * np.pi * x1) * np.cos(0.5 * np.pi * x0), H)).reshape(len(g), )
287
+
288
+ out["F"] = np.column_stack([f1, f2, f3])
289
+
290
+ def _calc_pareto_front(self, *args, n_pareto_points=100, **kwargs):
291
+ H = 20
292
+ x1, x2 = np.meshgrid(np.linspace(0, 1, H), np.linspace(0, 1, H), indexing='xy')
293
+ H = 2.25 + 2 * np.cos(0.5 * np.pi * self.time)
294
+ g = 1
295
+ f1 = g * np.sin(0.5 * np.pi * x1) ** H
296
+ f2 = np.multiply(g * np.sin(0.5 * np.pi * x2) ** H, np.cos(0.5 * np.pi * x1) ** H)
297
+ f3 = np.multiply(g * np.cos(0.5 * np.pi * x2) ** H, np.cos(0.5 * np.pi * x1) ** H)
298
+
299
+ return get_PF(np.array([f1, f2, f3]), False)
300
+
301
+
302
+ class DF11(DF):
303
+
304
+ def __init__(self, **kwargs):
305
+ super().__init__(**kwargs)
306
+ self.n_obj = 3
307
+
308
+ def _evaluate(self, x, out, *args, **kwargs):
309
+ G = np.abs(np.sin(0.5 * np.pi * self.time))
310
+ g = 1 + G + np.sum((x[:, 2:] - 0.5 * G * x[:, 0].reshape(len(x), 1)) ** 2, axis=1)
311
+ y = [np.pi * G / 6.0 + (np.pi / 2 - np.pi * G / 3.0) * x[:, i] for i in [0, 1]]
312
+
313
+ f1 = g * np.sin(y[0])
314
+ f2 = g * np.sin(y[1]) * np.cos(y[0])
315
+ f3 = g * np.cos(y[1]) * np.cos(y[0])
316
+
317
+ out["F"] = np.column_stack([f1, f2, f3])
318
+
319
+ def _calc_pareto_front(self, *args, n_pareto_points=100, **kwargs):
320
+ H = 20
321
+ x1, x2 = np.meshgrid(np.linspace(0, 1, H), np.linspace(0, 1, H), indexing='xy')
322
+ G = np.abs(np.sin(0.5 * np.pi * self.time))
323
+ y1 = np.pi * G / 6 + (np.pi / 2 - np.pi * G / 3) * x1
324
+ y2 = np.pi * G / 6 + (np.pi / 2 - np.pi * G / 3) * x2
325
+
326
+ f1 = (1 + G) * np.sin(y1)
327
+ f2 = (1 + G) * np.sin(y2) * np.cos(y1) # Correct element-wise multiplication
328
+ f3 = (1 + G) * np.cos(y2) * np.cos(y1) # Correct element-wise multiplication
329
+
330
+ return get_PF(np.array([f1, f2, f3]), False)
331
+
332
+
333
+ class DF12(DF):
334
+
335
+ def __init__(self, **kwargs):
336
+ super().__init__(**kwargs)
337
+ self.n_obj = 3
338
+ self.xl[2:] = -1.0
339
+ self.xu[2:] = +1.0
340
+
341
+ def _evaluate(self, x, out, *args, **kwargs):
342
+ k = 10 * np.sin(np.pi * self.time)
343
+ # r = 1 - np.modulo(k,2)
344
+ r = 1
345
+ x0 = x[:, 0].reshape(len(x), 1)
346
+ tmp1 = x[:, 2:] - np.sin(self.time * x0)
347
+ tmp2 = np.abs(np.sin(np.floor(k * (2 * x[:, 0:2] - r)) * np.pi / 2))
348
+ g = 1 + np.sum(tmp1 ** 2, axis=1) + np.prod(tmp2)
349
+
350
+ f1 = g * np.cos(0.5 * np.pi * x[:, 1]) * np.cos(0.5 * np.pi * x[:, 0])
351
+ f2 = g * np.sin(0.5 * np.pi * x[:, 1]) * np.cos(0.5 * np.pi * x[:, 0])
352
+ f3 = g * np.sin(0.5 * np.pi * x[:, 0])
353
+
354
+ out["F"] = np.column_stack([f1, f2, f3])
355
+
356
+ def _calc_pareto_front(self, *args, n_pareto_points=100, **kwargs):
357
+ H = 20
358
+ x1, x2 = np.meshgrid(np.linspace(0, 1, H), np.linspace(0, 1, H), indexing='xy')
359
+ k = 10 * np.sin(np.pi * self.time)
360
+ tmp2 = np.abs(
361
+ (np.sin((np.floor(k * (2 * x1 - 1)) * np.pi) / 2) *
362
+ np.sin((np.floor(k * (2 * x2 - 1)) * np.pi) / 2)))
363
+ g = 1 + tmp2
364
+ f1 = np.multiply(np.multiply(g, np.cos(0.5 * np.pi * x2)), np.cos(0.5 * np.pi * x1))
365
+ f2 = np.multiply(np.multiply(g, np.sin(0.5 * np.pi * x2)), np.cos(0.5 * np.pi * x1))
366
+ f3 = np.multiply(g, np.sin(0.5 * np.pi * x1))
367
+
368
+ return get_PF(np.array([f1, f2, f3]), True)
369
+
370
+
371
+ class DF13(DF):
372
+
373
+ def __init__(self, **kwargs):
374
+ super().__init__(**kwargs)
375
+ self.n_obj = 3
376
+ self.xl[2:] = -1.0
377
+ self.xu[2:] = +1.0
378
+
379
+ def _evaluate(self, x, out, *args, **kwargs):
380
+ G = np.sin(0.5 * np.pi * self.time)
381
+ p = np.floor(6 * G)
382
+ x0 = x[:, 0].reshape(len(x), 1)
383
+ x1 = x[:, 1].reshape(len(x), 1)
384
+ g = 1 + np.sum((x[:, 2:] - G) ** 2, axis=1)
385
+ g = g.reshape(len(g), 1)
386
+ f1 = g * np.cos(0.5 * np.pi * x0) ** 2
387
+ f2 = g * np.cos(0.5 * np.pi * x1) ** 2
388
+ f3 = g * (np.sin(0.5 * np.pi * x0) ** 2 + np.sin(0.5 * np.pi * x0) * np.cos(p * np.pi * x0) ** 2 + np.sin(
389
+ 0.5 * np.pi * x1) ** 2 + np.sin(0.5 * np.pi * x1) * np.cos(p * np.pi * x1) ** 2)
390
+
391
+ out["F"] = np.column_stack([f1, f2, f3])
392
+
393
+ def _calc_pareto_front(self, *args, n_pareto_points=100, **kwargs):
394
+ H = 20
395
+ x1, x2 = np.meshgrid(np.linspace(0, 1, H), np.linspace(0, 1, H), indexing='xy')
396
+ G = np.sin(0.5 * np.pi * self.time)
397
+ p = np.floor(6 * G)
398
+
399
+ f1 = np.cos(0.5 * np.pi * x1) ** 2
400
+ f2 = np.cos(0.5 * np.pi * x2) ** 2
401
+ f3 = np.sin(0.5 * np.pi * x1) ** 2 + np.sin(0.5 * np.pi * x1) * np.cos(p * np.pi * x1) ** 2 + np.sin(
402
+ 0.5 * np.pi * x2) ** 2 + np.sin(0.5 * np.pi * x2) * np.cos(p * np.pi * x2) ** 2
403
+
404
+ return get_PF(np.array([f1, f2, f3]), True)
405
+
406
+
407
+ class DF14(DF):
408
+
409
+ def __init__(self, **kwargs):
410
+ super().__init__(**kwargs)
411
+ self.n_obj = 3
412
+ self.xl[2:] = -1.0
413
+ self.xu[2:] = +1.0
414
+
415
+ def _evaluate(self, x, out, *args, **kwargs):
416
+ G = np.sin(0.5 * np.pi * self.time)
417
+ x0 = x[:, 0].reshape(len(x), 1)
418
+ x1 = x[:, 1].reshape(len(x), 1)
419
+
420
+ g = 1 + np.sum((x[:, 2:] - G) ** 2, axis=1)
421
+ g = g.reshape(len(g), 1)
422
+ y = 0.5 + G * (x0 - 0.5)
423
+
424
+ f1 = g * (1 - y + 0.05 * np.sin(6 * np.pi * y))
425
+ f2 = g * (1 - x1 + 0.05 * np.sin(6 * np.pi * x1)) * (y + 0.05 * np.sin(6 * np.pi * y))
426
+ f3 = g * (x1 + 0.05 * np.sin(6 * np.pi * x1)) * (y + 0.05 * np.sin(6 * np.pi * y))
427
+
428
+ out["F"] = np.column_stack([f1, f2, f3])
429
+
430
+ def _calc_pareto_front(self, *args, n_pareto_points=100, **kwargs):
431
+ H = 20
432
+ x1, x2 = np.meshgrid(np.linspace(0, 1, H), np.linspace(0, 1, H), indexing='xy')
433
+ G = np.sin(0.5 * np.pi * self.time)
434
+ y = 0.5 + G * (x1 - 0.5)
435
+ f1 = 1 - y + 0.05 * np.sin(6 * np.pi * y)
436
+ f2 = np.multiply(1 - x2 + 0.05 * np.sin(6 * np.pi * x2), y + 0.05 * np.sin(6 * np.pi * y))
437
+ f3 = np.multiply(x2 + 0.05 * np.sin(6 * np.pi * x2), y + 0.05 * np.sin(6 * np.pi * y))
438
+
439
+ return get_PF(np.array([f1, f2, f3]), False)
440
+
441
+
442
+ def get_PF(f=None, nondominate=None):
443
+ nds = NonDominatedSorting()
444
+ ncell = len(f)
445
+ s = np.size(f[1])
446
+ h = []
447
+ for i in np.arange(ncell):
448
+ fi = np.reshape(f[i], s, order='F')
449
+ h.append(fi)
450
+ h = np.array(h).T
451
+ h = np.reshape(h, (s, ncell))
452
+
453
+ if nondominate:
454
+ fronts = nds.do(F=h, only_non_dominated_front=True)
455
+ h = h[fronts]
456
+ return h