forked from anyoptimization/pymoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta.py
79 lines (52 loc) · 1.86 KB
/
meta.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from copy import deepcopy
from typing import Any
from pymoo.core.algorithm import Algorithm
class MetaAlgorithm:
def __new__(cls, algorithm) -> Any:
return algorithm
def __init__(self, algorithm) -> None:
super().__init__()
self.algorithm = algorithm
def __getattr__(self, attr):
print(attr)
if attr in self.__dict__:
return getattr(self, attr)
return getattr(self.__dict__["algorithm"], attr)
class MetaAlgorithm2(Algorithm):
def __init__(self,
algorithm,
copy=False,
):
super().__init__()
# if the algorithm object should be copied to keep the original one unmodified
if copy:
algorithm = deepcopy(algorithm)
self.algorithm = algorithm
def _copy_from_orig(self):
for k, v in self.algorithm.__dict__.items():
if k not in ["opt", "display"]:
self.__dict__[k] = v
def setup(self, *args, **kwargs):
self.algorithm.setup(*args, **kwargs)
self._copy_from_orig()
self.display = self.algorithm.display
self.algorithm.display = None
self._setup(*args, **kwargs)
return self
def _infill(self):
ret = self.algorithm.infill()
self._copy_from_orig()
return ret
def _initialize_infill(self):
return self._infill()
def _initialize_advance(self, infills=None, **kwargs):
self.algorithm.advance(infills=infills, **kwargs)
self._copy_from_orig()
def _advance(self, infills=None, **kwargs):
self.algorithm.advance(infills=infills, **kwargs)
self._copy_from_orig()
def advance(self, infills=None, **kwargs):
super().advance(infills, **kwargs)
self._copy_from_orig()
def _set_optimum(self):
self.opt = self.algorithm.opt