pyMachDM 0.1.0__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.
- pymachdm/ANN_weights/1.Weld_Beam_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/10.DTLZ7_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/11.DTLZ7_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/12.MW8_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/13.MW8_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/14.WAVY_3Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/15.FLOW_3Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/16.DPF4_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/17.DPF4_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/18.River_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/19.River_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/2.OSY_2Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/20.C2DTLZ2_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/21.C2DTLZ2_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/22.Knee_5Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/23.WATER_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/24.WATER_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/25.Clutch_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/26.Clutch_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/27.NIMBUS_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/28.NIMBUS_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/29.DTLZ2_8Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/3.ZDT2_2Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/30.GAA_10Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/4.Crash_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/4.ZDT3_2Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/4a.ZDT3_2Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/5.WAVY_2Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/6.WAVY_2Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/7.Carside_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/8.Carside_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/9.FLOWER_3Obj_MachineDM.joblib +0 -0
- pymachdm/__init__.py +71 -0
- pymachdm/ann/__init__.py +16 -0
- pymachdm/ann/multioutput_class.py +115 -0
- pymachdm/ann/multioutput_reg.py +110 -0
- pymachdm/imcdm_methods/__init__.py +25 -0
- pymachdm/imcdm_methods/guess_start.py +46 -0
- pymachdm/imcdm_methods/guess_sub.py +49 -0
- pymachdm/imcdm_methods/mod_guess_start.py +47 -0
- pymachdm/imcdm_methods/mod_guess_sub.py +47 -0
- pymachdm/imcdm_methods/nimbus_inter.py +64 -0
- pymachdm/imcdm_methods/nimbus_start.py +48 -0
- pymachdm/imcdm_methods/nimbus_sub.py +56 -0
- pymachdm/imcdm_methods/stem_start.py +47 -0
- pymachdm/imcdm_methods/stem_sub.py +51 -0
- pymachdm/imcdm_methods/stom_start.py +46 -0
- pymachdm/imcdm_methods/stom_sub.py +47 -0
- pymachdm/machdm_imcdm/__init__.py +4 -0
- pymachdm/machdm_imcdm/machdm_all.py +771 -0
- pymachdm/machdm_imcdm/machine_dm.py +124 -0
- pymachdm/pareto/__init__.py +3 -0
- pymachdm/pareto/pareto_analyser.py +162 -0
- pymachdm/plots/__init__.py +7 -0
- pymachdm/plots/plot_2d_scatter.py +57 -0
- pymachdm/plots/plot_3d_scatter.py +91 -0
- pymachdm/plots/plot_pcp.py +93 -0
- pymachdm/plots/plot_radviz.py +496 -0
- pymachdm/plots/plot_tsne.py +369 -0
- pymachdm/problems/__init__.py +4 -0
- pymachdm/problems/problem_factory.py +879 -0
- pymachdm/problems/symbolic_problem_factory.py +696 -0
- pymachdm/run_machdm.py +232 -0
- pymachdm/soo_aasf/__init__.py +7 -0
- pymachdm/soo_aasf/guess_asf.py +99 -0
- pymachdm/soo_aasf/mod_guess_asf.py +112 -0
- pymachdm/soo_aasf/nimbus_asf.py +104 -0
- pymachdm/soo_aasf/stem_asf.py +99 -0
- pymachdm/soo_aasf/stom_asf.py +81 -0
- pymachdm/utils/__init__.py +21 -0
- pymachdm/utils/auto_tradeoff_stom.py +34 -0
- pymachdm/utils/compute_lambda.py +71 -0
- pymachdm/utils/compute_lambda_with_g.py +85 -0
- pymachdm/utils/cos_sim.py +8 -0
- pymachdm/utils/generate_ref_dirs.py +6 -0
- pymachdm/utils/predict_best.py +45 -0
- pymachdm/utils/predict_best2.py +62 -0
- pymachdm/utils/predict_prob.py +67 -0
- pymachdm/utils/predict_rank.py +47 -0
- pymachdm-0.1.0.dist-info/LICENSE +21 -0
- pymachdm-0.1.0.dist-info/METADATA +223 -0
- pymachdm-0.1.0.dist-info/RECORD +84 -0
- pymachdm-0.1.0.dist-info/WHEEL +5 -0
- pymachdm-0.1.0.dist-info/top_level.txt +1 -0
pymachdm/run_machdm.py
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
|
|
2
|
+
import __main__
|
|
3
|
+
import numpy as np
|
|
4
|
+
import joblib
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from pymachdm.problems import get_Myproblem, get_symbolic_problem
|
|
8
|
+
|
|
9
|
+
from pymachdm.ann.multioutput_class import MultiOutputANN
|
|
10
|
+
from pymachdm.ann.multioutput_reg import MultiOutputANNRegressor, R2_Score
|
|
11
|
+
|
|
12
|
+
from pymachdm.machdm_imcdm.machine_dm import MachineDM
|
|
13
|
+
from pymachdm.machdm_imcdm.machdm_all import MachDM_iMCDM
|
|
14
|
+
from pymachdm.pareto import ParetoAnalyzer
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# Register classes required by saved Joblib models
|
|
18
|
+
__main__.MachineDM = MachineDM
|
|
19
|
+
__main__.MachDM_iMCDM = MachDM_iMCDM
|
|
20
|
+
__main__.ParetoAnalyzer = ParetoAnalyzer
|
|
21
|
+
__main__.MultiOutputANN = MultiOutputANN
|
|
22
|
+
__main__.MultiOutputANNRegressor = MultiOutputANNRegressor
|
|
23
|
+
__main__.R2_Score = R2_Score
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# Problem-to-model mapping
|
|
27
|
+
MODEL_FILES = {
|
|
28
|
+
"welded_beam": "1.Weld_Beam_MachineDM.joblib",
|
|
29
|
+
"osy_2Obj": "2.OSY_2Obj_MachineDM.joblib",
|
|
30
|
+
"zdt2_pow": "3.ZDT2_MachineDM.joblib",
|
|
31
|
+
"zdt3_example": "4.ZDT3_2Obj_MachineDM.joblib",
|
|
32
|
+
"wavy_2obj_1": "5.Wavy_2Obj_MachineDM.joblib",
|
|
33
|
+
"wavy_2obj_2": "6.Wavy_2Obj_MachineDM.joblib",
|
|
34
|
+
"carside_1": "7.CarSide_MachineDM.joblib",
|
|
35
|
+
"carside_2": "8.CarSide_MachineDM.joblib",
|
|
36
|
+
"flower_3obj": "9.FLOWER_3Obj_MachineDM.joblib",
|
|
37
|
+
"dtlz7_1": "10.DTLZ7_MachineDM.joblib",
|
|
38
|
+
"dtlz7_2": "11.DTLZ7_MachineDM.joblib",
|
|
39
|
+
"mw8_1": "12.MW8_MachineDM.joblib",
|
|
40
|
+
"mw8_2": "13.MW8_MachineDM.joblib",
|
|
41
|
+
"wavy_3obj": "14.Wavy_3Obj_MachineDM.joblib",
|
|
42
|
+
"flow_3obj": "15.FLOW_3Obj_MachineDM.joblib",
|
|
43
|
+
"dpf4_ex1": "16.DPF4_MachineDM.joblib",
|
|
44
|
+
"dpf4_ex2": "17.DPF4_MachineDM.joblib",
|
|
45
|
+
"river_ex1": "18.RIVER_MachineDM.joblib",
|
|
46
|
+
"river_ex2": "19.RIVER_MachineDM.joblib",
|
|
47
|
+
"c2dtlz2_5obj_ex1": "20.C2DTLZ2_MachineDM.joblib",
|
|
48
|
+
"c2dtlz2_5obj_ex2": "21.C2DTLZ2_MachineDM.joblib",
|
|
49
|
+
"knee_5obj": "22.Knee_5Obj_MachineDM.joblib",
|
|
50
|
+
"water_ex1": "23.WATER_MachineDM.joblib",
|
|
51
|
+
"water_ex2": "24.WATER_MachineDM.joblib",
|
|
52
|
+
"clutch_ex1": "25.Clutch_Brake_MachineDM.joblib",
|
|
53
|
+
"clutch_ex2": "26.Clutch_Brake_MachineDM.joblib",
|
|
54
|
+
"nimbus_bench1": "27.NIMBUS_Bench_MachineDM.joblib",
|
|
55
|
+
"nimbus_bench2": "28.NIMBUS_Bench_MachineDM.joblib",
|
|
56
|
+
"dtlz2_8obj": "29.DTLZ2_8Obj_MachineDM.joblib",
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# Method-to-function mapping
|
|
61
|
+
METHODS = {
|
|
62
|
+
"guess": "MachDM_GUESS",
|
|
63
|
+
"stom": "MachDM_STOM",
|
|
64
|
+
"stem": "MachDM_STEM",
|
|
65
|
+
"nimbus": "MachDM_NIMBUS",
|
|
66
|
+
"mod_guess": "MachDM_Mod_GUESS",
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def run_machdm(
|
|
71
|
+
problem_name,
|
|
72
|
+
method,
|
|
73
|
+
x_start,
|
|
74
|
+
n_iter=15,
|
|
75
|
+
ga_pop=100,
|
|
76
|
+
ga_gen=200,
|
|
77
|
+
n_int_sol=1,
|
|
78
|
+
RNG=142,
|
|
79
|
+
**method_kwargs
|
|
80
|
+
):
|
|
81
|
+
|
|
82
|
+
# Validate problem
|
|
83
|
+
if problem_name not in MODEL_FILES:
|
|
84
|
+
raise ValueError(
|
|
85
|
+
f"No trained model registered for '{problem_name}'. "
|
|
86
|
+
f"Available problems: {list(MODEL_FILES.keys())}"
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
# Validate method
|
|
90
|
+
method = method.lower()
|
|
91
|
+
|
|
92
|
+
if method not in METHODS:
|
|
93
|
+
raise ValueError(
|
|
94
|
+
f"Unknown method '{method}'. "
|
|
95
|
+
f"Available methods: {list(METHODS.keys())}"
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
# Generate problems
|
|
99
|
+
problem = get_Myproblem(problem_name)
|
|
100
|
+
sym_problem = get_symbolic_problem("sym_" + problem_name)
|
|
101
|
+
|
|
102
|
+
x_start = np.asarray(x_start, dtype=float)
|
|
103
|
+
|
|
104
|
+
# Load trained model
|
|
105
|
+
package_dir = Path(__file__).resolve().parent
|
|
106
|
+
model_path = package_dir / "ANN_weights" / MODEL_FILES[problem_name]
|
|
107
|
+
|
|
108
|
+
if not model_path.exists():
|
|
109
|
+
raise FileNotFoundError(f"Model not found: {model_path}")
|
|
110
|
+
|
|
111
|
+
machdm = joblib.load(model_path)
|
|
112
|
+
|
|
113
|
+
# Initialize Machine-DM
|
|
114
|
+
machine_dm = MachDM_iMCDM(
|
|
115
|
+
problem=problem,
|
|
116
|
+
sym_problem=sym_problem,
|
|
117
|
+
machdm=machdm,
|
|
118
|
+
x_Start=x_start,
|
|
119
|
+
n_iter=n_iter,
|
|
120
|
+
ga_pop=ga_pop,
|
|
121
|
+
ga_gen=ga_gen,
|
|
122
|
+
n_int_sol=n_int_sol,
|
|
123
|
+
RNG=RNG
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
# Select interactive MCDM method
|
|
127
|
+
method_function = getattr(machine_dm, METHODS[method], None)
|
|
128
|
+
|
|
129
|
+
if method_function is None:
|
|
130
|
+
raise AttributeError(
|
|
131
|
+
f"{METHODS[method]} is not available in MachDM_iMCDM."
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
# Run selected method
|
|
136
|
+
results = method_function(
|
|
137
|
+
x_Start=x_start,
|
|
138
|
+
n_iter=n_iter,
|
|
139
|
+
ga_pop=ga_pop,
|
|
140
|
+
ga_gen=ga_gen,
|
|
141
|
+
n_int_sol=n_int_sol,
|
|
142
|
+
RNG=RNG,
|
|
143
|
+
**method_kwargs
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
# Store method-specific outputs
|
|
147
|
+
if method == "guess":
|
|
148
|
+
(
|
|
149
|
+
X0, F0, SubX, SubF,
|
|
150
|
+
X, F, Class, Param
|
|
151
|
+
) = results
|
|
152
|
+
|
|
153
|
+
output = {
|
|
154
|
+
"X0": X0,
|
|
155
|
+
"F0": F0,
|
|
156
|
+
"SubX": SubX,
|
|
157
|
+
"SubF": SubF,
|
|
158
|
+
"X": X,
|
|
159
|
+
"F": F,
|
|
160
|
+
"Class": Class,
|
|
161
|
+
"Param": Param
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
elif method == "stem":
|
|
165
|
+
(
|
|
166
|
+
X0, F0, SubX, SubF,
|
|
167
|
+
X, F, G, Class, Param
|
|
168
|
+
) = results
|
|
169
|
+
|
|
170
|
+
output = {
|
|
171
|
+
"X0": X0,
|
|
172
|
+
"F0": F0,
|
|
173
|
+
"SubX": SubX,
|
|
174
|
+
"SubF": SubF,
|
|
175
|
+
"X": X,
|
|
176
|
+
"F": F,
|
|
177
|
+
"G": G,
|
|
178
|
+
"Class": Class,
|
|
179
|
+
"Param": Param
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
elif method == "nimbus":
|
|
183
|
+
(
|
|
184
|
+
X0, F0, SubX, SubF,
|
|
185
|
+
intX, intF, X, F, G, Class, Param
|
|
186
|
+
) = results
|
|
187
|
+
|
|
188
|
+
output = {
|
|
189
|
+
"X0": X0,
|
|
190
|
+
"F0": F0,
|
|
191
|
+
"SubX": SubX,
|
|
192
|
+
"SubF": SubF,
|
|
193
|
+
"intX": intX,
|
|
194
|
+
"intF": intF,
|
|
195
|
+
"X": X,
|
|
196
|
+
"F": F,
|
|
197
|
+
"G": G,
|
|
198
|
+
"Class": Class,
|
|
199
|
+
"Param": Param
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
elif method in ["stom", "mod_guess"]:
|
|
203
|
+
(
|
|
204
|
+
X0, F0, SubX, SubF,
|
|
205
|
+
X, F, Class, Param
|
|
206
|
+
) = results
|
|
207
|
+
|
|
208
|
+
output = {
|
|
209
|
+
"X0": X0,
|
|
210
|
+
"F0": F0,
|
|
211
|
+
"SubX": SubX,
|
|
212
|
+
"SubF": SubF,
|
|
213
|
+
"X": X,
|
|
214
|
+
"F": F,
|
|
215
|
+
"Class": Class,
|
|
216
|
+
"Param": Param
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
# Rank final solutions
|
|
220
|
+
Ranks, Classes, Pref_Vals = machine_dm._Rank_Solutions(
|
|
221
|
+
np.asarray(output["X"])
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
output.update({
|
|
225
|
+
"Ranks": Ranks,
|
|
226
|
+
"Classes": Classes,
|
|
227
|
+
"Pref_Vals": Pref_Vals,
|
|
228
|
+
"MachineDM": machine_dm
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
return output
|
|
232
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
from .guess_asf import GUESS_Problem
|
|
2
|
+
from .stom_asf import STOM_Problem
|
|
3
|
+
from .stem_asf import STEM_Problem
|
|
4
|
+
from .nimbus_asf import NIMBUS_Problem
|
|
5
|
+
from .mod_guess_asf import COIN_Problem
|
|
6
|
+
|
|
7
|
+
__all__ = ["GUESS_Problem", "STOM_Problem", "STEM_Problem", "NIMBUS_Problem", "COIN_Problem"]
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from pymoo.core.problem import ElementwiseProblem
|
|
3
|
+
|
|
4
|
+
class GUESS_Problem(ElementwiseProblem):
|
|
5
|
+
def __init__(self, problem=None, start_F=None, Ref_F=None, eps=None, i1=None, i2=None, i3=None, i4=None, mode=None,
|
|
6
|
+
ideal_point=None, nadir_point=None):
|
|
7
|
+
|
|
8
|
+
self.problem = problem
|
|
9
|
+
self.start_F = np.array(start_F)
|
|
10
|
+
self.Ref_F = np.array(Ref_F)
|
|
11
|
+
self.eps = eps
|
|
12
|
+
|
|
13
|
+
self.i1 = np.array(i1) if i1 is not None else np.array([])
|
|
14
|
+
self.i2 = np.array(i2) if i2 is not None else np.array([])
|
|
15
|
+
self.i3 = np.array(i3) if i3 is not None else np.array([])
|
|
16
|
+
self.i4 = np.array(i4) if i4 is not None else np.array([])
|
|
17
|
+
self.mode = mode
|
|
18
|
+
self.n_ieq = len(self.i1) + len(self.i2) + len(self.i3) + len(self.i4)
|
|
19
|
+
|
|
20
|
+
self.ideal_point = np.array(ideal_point)
|
|
21
|
+
self.nadir_point = np.array(nadir_point)
|
|
22
|
+
self.rho = 0.001
|
|
23
|
+
# print("Ideal, Nadir:", ideal_point, nadir_point)
|
|
24
|
+
# Count constraints from the base problem
|
|
25
|
+
n_ieq_constr_base = getattr(problem, "n_ieq_constr", 0)
|
|
26
|
+
n_eq_constr_base = getattr(problem, "n_eq_constr", 0)
|
|
27
|
+
|
|
28
|
+
# For NIMBUS 'sub' mode, include additional constraints
|
|
29
|
+
# n_ieq_constr_total = (self.n_ieq if mode == 'sub' else 0) + n_ieq_constr_base
|
|
30
|
+
n_ieq_constr_total = n_ieq_constr_base
|
|
31
|
+
n_eq_constr_total = n_eq_constr_base
|
|
32
|
+
|
|
33
|
+
super().__init__(
|
|
34
|
+
n_var=self.problem.n_var,
|
|
35
|
+
n_obj=1,
|
|
36
|
+
n_ieq_constr=n_ieq_constr_total,
|
|
37
|
+
n_eq_constr=n_eq_constr_total,
|
|
38
|
+
xl=self.problem.xl,
|
|
39
|
+
xu=self.problem.xu
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
def _evaluate(self, x, out, *args, **kwargs):
|
|
43
|
+
# Evaluate original problem
|
|
44
|
+
base_out = {}
|
|
45
|
+
self.problem._evaluate(x, base_out)
|
|
46
|
+
|
|
47
|
+
f = np.array(base_out.get("F"))
|
|
48
|
+
G_base = np.array(base_out.get("G", [])) # inequality constraints (<=0)
|
|
49
|
+
H_base = np.array(base_out.get("H", [])) # equality constraints (=0)
|
|
50
|
+
|
|
51
|
+
# Handle empty constraints gracefully
|
|
52
|
+
if G_base.size == 0:
|
|
53
|
+
G_base = np.empty(0)
|
|
54
|
+
if H_base.size == 0:
|
|
55
|
+
H_base = np.empty(0)
|
|
56
|
+
|
|
57
|
+
# Combined index set
|
|
58
|
+
if len(self.i1) == 0 and len(self.i2) == 0 and len(self.i3) == 0 and len(self.i4) == 0:
|
|
59
|
+
i1234 = np.arange(len(f))
|
|
60
|
+
else:
|
|
61
|
+
i1234 = np.concatenate([self.i1, self.i2, self.i3, self.i4])
|
|
62
|
+
|
|
63
|
+
# --- Start mode ---
|
|
64
|
+
if self.mode == 'start':
|
|
65
|
+
|
|
66
|
+
F = np.max((f[i1234]-self.start_F[i1234])/(self.nadir_point[i1234]-self.ideal_point[i1234] + 0.0001) +
|
|
67
|
+
self.rho*np.sum((f[i1234])/(self.nadir_point[i1234]-self.ideal_point[i1234] + 0.0001)))
|
|
68
|
+
|
|
69
|
+
out["F"] = [F]
|
|
70
|
+
out["G"] = G_base
|
|
71
|
+
out["H"] = H_base
|
|
72
|
+
|
|
73
|
+
# --- Subproblem mode ---
|
|
74
|
+
elif self.mode == 'sub':
|
|
75
|
+
|
|
76
|
+
if len(self.i1) == 0 and len(self.i2) == 0:
|
|
77
|
+
G1 = [] # nothing to compute
|
|
78
|
+
else:
|
|
79
|
+
i12 = np.concatenate([self.i1, self.i2])
|
|
80
|
+
i12 = [i for i in i12 if i < len(f)]
|
|
81
|
+
G1 = [f[i] - self.start_F[i] for i in i12]
|
|
82
|
+
|
|
83
|
+
G2 = [f[j] - self.start_F[j] for j in self.i3]
|
|
84
|
+
G3 = [f[k] - self.eps[k] for k in self.i4]
|
|
85
|
+
|
|
86
|
+
F = np.max((f[i1234]-self.nadir_point[i1234])/(self.nadir_point[i1234]-self.Ref_F[i1234]+0.0001))
|
|
87
|
+
# + self.rho*np.sum((f[i1234])/(self.nadir_point[i1234]-self.Ref_F[i1234]+0.0001)))
|
|
88
|
+
# print("Prinintg Size of F", np.size(F))
|
|
89
|
+
|
|
90
|
+
G_step = np.concatenate([G1, G2, G3])
|
|
91
|
+
|
|
92
|
+
# Combine with original problem constraints
|
|
93
|
+
out["F"] = [F]
|
|
94
|
+
# out["G"] = np.concatenate([G_base, G_step]) if G_base.size > 0 else G_step
|
|
95
|
+
out["G"] = G_base
|
|
96
|
+
out["H"] = H_base
|
|
97
|
+
|
|
98
|
+
else:
|
|
99
|
+
raise ValueError("mode must be 'start', or 'sub'")
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from pymoo.core.problem import ElementwiseProblem
|
|
3
|
+
|
|
4
|
+
class COIN_Problem(ElementwiseProblem):
|
|
5
|
+
def __init__(self, problem=None, start_F=None, Ref_F=None, eps=None, i1=None, i2=None, i3=None, i4=None, mode=None,
|
|
6
|
+
ideal_point=None, nadir_point=None, lb=None, ub=None):
|
|
7
|
+
|
|
8
|
+
self.problem = problem
|
|
9
|
+
self.start_F = np.array(start_F)
|
|
10
|
+
self.Ref_F = np.array(Ref_F)
|
|
11
|
+
self.eps = eps
|
|
12
|
+
|
|
13
|
+
self.i1 = np.array(i1) if i1 is not None else np.array([])
|
|
14
|
+
self.i2 = np.array(i2) if i2 is not None else np.array([])
|
|
15
|
+
self.i3 = np.array(i3) if i3 is not None else np.array([])
|
|
16
|
+
self.i4 = np.array(i4) if i4 is not None else np.array([])
|
|
17
|
+
self.mode = mode
|
|
18
|
+
self.n_ieq = len(self.i1) + len(self.i2) + len(self.i3) + len(self.i4)
|
|
19
|
+
|
|
20
|
+
self.ideal_point = np.array(ideal_point)
|
|
21
|
+
self.nadir_point = np.array(nadir_point)
|
|
22
|
+
self.ub = np.array(ub); self.lb = np.array(lb)
|
|
23
|
+
self.rho = 0.001
|
|
24
|
+
# print("Ideal, Nadir:", ideal_point, nadir_point)
|
|
25
|
+
# Count constraints from the base problem
|
|
26
|
+
n_ieq_constr_base = getattr(problem, "n_ieq_constr", 0)
|
|
27
|
+
n_eq_constr_base = getattr(problem, "n_eq_constr", 0)
|
|
28
|
+
|
|
29
|
+
# For STEM 'sub' mode, include additional constraints
|
|
30
|
+
# n_ieq_constr_total = (self.n_ieq if mode == 'sub' else 0) + n_ieq_constr_base
|
|
31
|
+
n_ieq_constr_total = n_ieq_constr_base
|
|
32
|
+
n_eq_constr_total = n_eq_constr_base
|
|
33
|
+
|
|
34
|
+
super().__init__(
|
|
35
|
+
n_var=self.problem.n_var,
|
|
36
|
+
n_obj=1,
|
|
37
|
+
n_ieq_constr=n_ieq_constr_total,
|
|
38
|
+
n_eq_constr=n_eq_constr_total,
|
|
39
|
+
xl=self.problem.xl,
|
|
40
|
+
xu=self.problem.xu
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
def _evaluate(self, x, out, *args, **kwargs):
|
|
44
|
+
# Evaluate original problem
|
|
45
|
+
base_out = {}
|
|
46
|
+
self.problem._evaluate(x, base_out)
|
|
47
|
+
|
|
48
|
+
f = np.array(base_out.get("F"))
|
|
49
|
+
G_base = np.array(base_out.get("G", [])) # inequality constraints (<=0)
|
|
50
|
+
H_base = np.array(base_out.get("H", [])) # equality constraints (=0)
|
|
51
|
+
|
|
52
|
+
# Handle empty constraints gracefully
|
|
53
|
+
if G_base.size == 0:
|
|
54
|
+
G_base = np.empty(0)
|
|
55
|
+
if H_base.size == 0:
|
|
56
|
+
H_base = np.empty(0)
|
|
57
|
+
|
|
58
|
+
# Combined index set
|
|
59
|
+
if len(self.i1) == 0 and len(self.i2) == 0 and len(self.i3) == 0 and len(self.i4) == 0:
|
|
60
|
+
i1234 = np.arange(len(f))
|
|
61
|
+
else:
|
|
62
|
+
i1234 = np.concatenate([self.i1, self.i2, self.i3, self.i4])
|
|
63
|
+
|
|
64
|
+
# --- Start mode ---
|
|
65
|
+
if self.mode == 'start':
|
|
66
|
+
|
|
67
|
+
F = np.max((f[i1234]-self.start_F[i1234])/(self.nadir_point[i1234]-self.ideal_point[i1234] + 0.0001) +
|
|
68
|
+
self.rho*np.sum((f[i1234])/(self.nadir_point[i1234]-self.ideal_point[i1234] + 0.0001)))
|
|
69
|
+
|
|
70
|
+
out["F"] = [F]
|
|
71
|
+
out["G"] = G_base
|
|
72
|
+
out["H"] = H_base
|
|
73
|
+
|
|
74
|
+
# --- Subproblem mode ---
|
|
75
|
+
elif self.mode == 'sub':
|
|
76
|
+
|
|
77
|
+
if len(self.i1) == 0 and len(self.i2) == 0:
|
|
78
|
+
G1 = [] # nothing to compute
|
|
79
|
+
else:
|
|
80
|
+
i12 = np.concatenate([self.i1, self.i2])
|
|
81
|
+
i12 = [i for i in i12 if i < len(f)]
|
|
82
|
+
G1 = [f[i] - self.start_F[i] for i in i12]
|
|
83
|
+
|
|
84
|
+
G2 = [f[j] - self.start_F[j] for j in self.i3]
|
|
85
|
+
G3 = [f[k] - self.eps[k] for k in self.i4]
|
|
86
|
+
G_step = np.concatenate([G1, G2, G3])
|
|
87
|
+
|
|
88
|
+
e = (self.ub - self.lb)
|
|
89
|
+
w = e/np.sum(e);
|
|
90
|
+
# F = np.max((f[i1234]-self.ub[i1234])/(self.ub[i1234]-self.Ref_F[i1234]+0.0001))
|
|
91
|
+
w[self.i3] = 0;
|
|
92
|
+
F = np.max((f[i1234]-self.nadir_point[i1234])/(self.nadir_point[i1234]-self.Ref_F[i1234]+0.0001))
|
|
93
|
+
# + self.rho*np.sum((f[i1234])/(self.nadir_point[i1234]-self.Ref_F[i1234]+0.0001)))
|
|
94
|
+
|
|
95
|
+
# F = np.max((f[i1234]-self.Ref_F[i1234])/(self.nadir_point[i1234]-self.ideal_point[i1234]+0.0001)
|
|
96
|
+
# + self.rho*np.sum((f[i1234])/(self.nadir_point[i1234]-self.ideal_point[i1234]+0.0001)))
|
|
97
|
+
|
|
98
|
+
# F = np.max((f[i1234]-self.nadir_point[i1234])/(self.nadir_point[i1234]-self.Ref_F[i1234]+0.0001)
|
|
99
|
+
# + self.rho*np.sum((f[i1234])/(self.nadir_point[i1234]-self.Ref_F[i1234]+0.0001)))
|
|
100
|
+
|
|
101
|
+
# Combine with original problem constraints
|
|
102
|
+
out["F"] = [F]
|
|
103
|
+
out["G"] = G_base
|
|
104
|
+
# out["G"] = np.concatenate([G_base, G_step]) if G_base.size > 0 else G_step
|
|
105
|
+
out["H"] = H_base
|
|
106
|
+
|
|
107
|
+
else:
|
|
108
|
+
raise ValueError("mode must be 'start', or 'sub'")
|
|
109
|
+
|
|
110
|
+
# # ===================== Subproblem Evaluation =====================
|
|
111
|
+
# STEM_sub = STEM_Problem(problem, start_F=None, eps=None, i1=None, i2=None, i3=None, i4=None,
|
|
112
|
+
# mode='sub', ideal_point=None, nadir_point=None)
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from pymoo.core.problem import ElementwiseProblem
|
|
3
|
+
|
|
4
|
+
class NIMBUS_Problem(ElementwiseProblem):
|
|
5
|
+
def __init__(self, problem=None, start_F=None, eps=None, i1=None, i2=None, i3=None, i4=None, mode=None,
|
|
6
|
+
ideal_point=None, nadir_point=None):
|
|
7
|
+
|
|
8
|
+
self.problem = problem
|
|
9
|
+
self.start_F = np.array(start_F)
|
|
10
|
+
self.eps = eps
|
|
11
|
+
|
|
12
|
+
self.i1 = np.array(i1) if i1 is not None else np.array([])
|
|
13
|
+
self.i2 = np.array(i2) if i2 is not None else np.array([])
|
|
14
|
+
self.i3 = np.array(i3) if i3 is not None else np.array([])
|
|
15
|
+
self.i4 = np.array(i4) if i4 is not None else np.array([])
|
|
16
|
+
self.mode = mode
|
|
17
|
+
self.n_ieq = len(self.i1) + len(self.i2) + len(self.i3) + len(self.i4)
|
|
18
|
+
|
|
19
|
+
self.ideal_point = np.array(ideal_point)
|
|
20
|
+
self.nadir_point = np.array(nadir_point)
|
|
21
|
+
self.rho = 0.001
|
|
22
|
+
# print("Ideal, Nadir:", ideal_point, nadir_point)
|
|
23
|
+
# Count constraints from the base problem
|
|
24
|
+
n_ieq_constr_base = getattr(problem, "n_ieq_constr", 0)
|
|
25
|
+
n_eq_constr_base = getattr(problem, "n_eq_constr", 0)
|
|
26
|
+
|
|
27
|
+
# For NIMBUS 'sub' mode, include additional constraints
|
|
28
|
+
n_ieq_constr_total = (self.n_ieq if mode == 'sub' else 0) + n_ieq_constr_base
|
|
29
|
+
n_eq_constr_total = n_eq_constr_base
|
|
30
|
+
|
|
31
|
+
super().__init__(
|
|
32
|
+
n_var=self.problem.n_var,
|
|
33
|
+
n_obj=1,
|
|
34
|
+
n_ieq_constr=n_ieq_constr_total,
|
|
35
|
+
n_eq_constr=n_eq_constr_total,
|
|
36
|
+
xl=self.problem.xl,
|
|
37
|
+
xu=self.problem.xu
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
def _evaluate(self, x, out, *args, **kwargs):
|
|
41
|
+
# Evaluate original problem
|
|
42
|
+
base_out = {}
|
|
43
|
+
self.problem._evaluate(x, base_out)
|
|
44
|
+
|
|
45
|
+
f = np.array(base_out.get("F"))
|
|
46
|
+
G_base = np.array(base_out.get("G", [])) # inequality constraints (<=0)
|
|
47
|
+
H_base = np.array(base_out.get("H", [])) # equality constraints (=0)
|
|
48
|
+
|
|
49
|
+
# Handle empty constraints gracefully
|
|
50
|
+
if G_base.size == 0:
|
|
51
|
+
G_base = np.empty(0)
|
|
52
|
+
if H_base.size == 0:
|
|
53
|
+
H_base = np.empty(0)
|
|
54
|
+
|
|
55
|
+
# Combined index set
|
|
56
|
+
if len(self.i1) == 0 and len(self.i2) == 0 and len(self.i3) == 0 and len(self.i4) == 0:
|
|
57
|
+
i1234 = np.arange(len(f))
|
|
58
|
+
else:
|
|
59
|
+
i1234 = np.concatenate([self.i1, self.i2, self.i3, self.i4])
|
|
60
|
+
|
|
61
|
+
# --- Start mode ---
|
|
62
|
+
if self.mode == 'start':
|
|
63
|
+
|
|
64
|
+
F = np.max((f[i1234]-self.start_F[i1234])/(self.nadir_point[i1234]-self.ideal_point[i1234]) +
|
|
65
|
+
self.rho*np.sum((f[i1234])/(self.nadir_point[i1234]-self.ideal_point[i1234])))
|
|
66
|
+
|
|
67
|
+
out["F"] = [F]
|
|
68
|
+
out["G"] = G_base
|
|
69
|
+
out["H"] = H_base
|
|
70
|
+
|
|
71
|
+
# --- Subproblem mode ---
|
|
72
|
+
elif self.mode == 'sub':
|
|
73
|
+
# delta1 = self.Delta * (self.nadir_point - self.ideal_point)
|
|
74
|
+
Fc = np.array([self.rho * np.sum(f[i1234] / (self.nadir_point[i1234] - self.ideal_point[i1234]))])
|
|
75
|
+
|
|
76
|
+
Fa = (f[self.i1] - self.ideal_point[self.i1]) / (self.nadir_point[self.i1] - self.ideal_point[self.i1]) + Fc if len(self.i1) > 0 else Fc
|
|
77
|
+
Fb = (f[self.i2] - self.eps[self.i2]) / (self.nadir_point[self.i2] - self.ideal_point[self.i2]) + Fc if len(self.i2) > 0 else Fc
|
|
78
|
+
|
|
79
|
+
if len(self.i1) == 0 and len(self.i2) == 0:
|
|
80
|
+
G1 = [] # nothing to compute
|
|
81
|
+
else:
|
|
82
|
+
i12 = np.concatenate([self.i1, self.i2])
|
|
83
|
+
i12 = [i for i in i12 if i < len(f)]
|
|
84
|
+
G1 = [f[i] - self.start_F[i] for i in i12]
|
|
85
|
+
G2 = [f[j] - self.start_F[j] for j in self.i3]
|
|
86
|
+
G3 = [f[k] - self.eps[k] for k in self.i4]
|
|
87
|
+
|
|
88
|
+
F = np.max(np.concatenate([Fa, Fb]))
|
|
89
|
+
G_nimbus = np.concatenate([G1, G2, G3])
|
|
90
|
+
|
|
91
|
+
# Combine with original problem constraints
|
|
92
|
+
out["F"] = [F]
|
|
93
|
+
out["G"] = np.concatenate([G_base, G_nimbus]) if G_base.size > 0 else G_nimbus
|
|
94
|
+
out["H"] = H_base
|
|
95
|
+
|
|
96
|
+
# --- Intermediate mode ---
|
|
97
|
+
elif self.mode == 'inter':
|
|
98
|
+
F = np.max(f[i1234] - self.start_F[i1234])
|
|
99
|
+
out["F"] = [F]
|
|
100
|
+
out["G"] = G_base
|
|
101
|
+
out["H"] = H_base
|
|
102
|
+
|
|
103
|
+
else:
|
|
104
|
+
raise ValueError("mode must be 'start', 'sub', or 'inter'")
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from pymoo.core.problem import ElementwiseProblem
|
|
3
|
+
|
|
4
|
+
class STEM_Problem(ElementwiseProblem):
|
|
5
|
+
def __init__(self, problem=None, start_F=None, eps=None, i1=None, i2=None, i3=None, i4=None, mode=None,
|
|
6
|
+
ideal_point=None, nadir_point=None):
|
|
7
|
+
|
|
8
|
+
self.problem = problem
|
|
9
|
+
self.start_F = np.array(start_F)
|
|
10
|
+
self.eps = eps
|
|
11
|
+
|
|
12
|
+
self.i1 = np.array(i1) if i1 is not None else np.array([])
|
|
13
|
+
self.i2 = np.array(i2) if i2 is not None else np.array([])
|
|
14
|
+
self.i3 = np.array(i3) if i3 is not None else np.array([])
|
|
15
|
+
self.i4 = np.array(i4) if i4 is not None else np.array([])
|
|
16
|
+
self.mode = mode
|
|
17
|
+
self.n_ieq = len(self.i1) + len(self.i2) + len(self.i3) + len(self.i4)
|
|
18
|
+
|
|
19
|
+
self.ideal_point = np.array(ideal_point)
|
|
20
|
+
self.nadir_point = np.array(nadir_point)
|
|
21
|
+
self.rho = 0.001
|
|
22
|
+
# print("Ideal, Nadir:", ideal_point, nadir_point)
|
|
23
|
+
# Count constraints from the base problem
|
|
24
|
+
n_ieq_constr_base = getattr(problem, "n_ieq_constr", 0)
|
|
25
|
+
n_eq_constr_base = getattr(problem, "n_eq_constr", 0)
|
|
26
|
+
|
|
27
|
+
# For STEM 'sub' mode, include additional constraints
|
|
28
|
+
n_ieq_constr_total = (self.n_ieq if mode == 'sub' else 0) + n_ieq_constr_base
|
|
29
|
+
n_eq_constr_total = n_eq_constr_base
|
|
30
|
+
|
|
31
|
+
super().__init__(
|
|
32
|
+
n_var=self.problem.n_var,
|
|
33
|
+
n_obj=1,
|
|
34
|
+
n_ieq_constr=n_ieq_constr_total,
|
|
35
|
+
n_eq_constr=n_eq_constr_total,
|
|
36
|
+
xl=self.problem.xl,
|
|
37
|
+
xu=self.problem.xu
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
def _evaluate(self, x, out, *args, **kwargs):
|
|
41
|
+
# Evaluate original problem
|
|
42
|
+
base_out = {}
|
|
43
|
+
self.problem._evaluate(x, base_out)
|
|
44
|
+
|
|
45
|
+
f = np.array(base_out.get("F"))
|
|
46
|
+
G_base = np.array(base_out.get("G", [])) # inequality constraints (<=0)
|
|
47
|
+
H_base = np.array(base_out.get("H", [])) # equality constraints (=0)
|
|
48
|
+
|
|
49
|
+
# Handle empty constraints gracefully
|
|
50
|
+
if G_base.size == 0:
|
|
51
|
+
G_base = np.empty(0)
|
|
52
|
+
if H_base.size == 0:
|
|
53
|
+
H_base = np.empty(0)
|
|
54
|
+
|
|
55
|
+
# Combined index set
|
|
56
|
+
if len(self.i1) == 0 and len(self.i2) == 0 and len(self.i3) == 0 and len(self.i4) == 0:
|
|
57
|
+
i1234 = np.arange(len(f))
|
|
58
|
+
else:
|
|
59
|
+
i1234 = np.concatenate([self.i1, self.i2, self.i3, self.i4])
|
|
60
|
+
|
|
61
|
+
# --- Start mode ---
|
|
62
|
+
if self.mode == 'start':
|
|
63
|
+
|
|
64
|
+
F = np.max((f[i1234]-self.start_F[i1234])/(self.nadir_point[i1234]-self.ideal_point[i1234]) +
|
|
65
|
+
self.rho*np.sum((f[i1234])/(self.nadir_point[i1234]-self.ideal_point[i1234])))
|
|
66
|
+
|
|
67
|
+
out["F"] = [F]
|
|
68
|
+
out["G"] = G_base
|
|
69
|
+
out["H"] = H_base
|
|
70
|
+
|
|
71
|
+
# --- Subproblem mode ---
|
|
72
|
+
elif self.mode == 'sub':
|
|
73
|
+
|
|
74
|
+
e = (self.nadir_point - self.ideal_point)/(self.nadir_point*(self.ideal_point+0.001))
|
|
75
|
+
w = e/np.sum(e)
|
|
76
|
+
w[self.i4] = 0
|
|
77
|
+
w[self.i3] = 0
|
|
78
|
+
|
|
79
|
+
if len(self.i1) == 0 and len(self.i2) == 0:
|
|
80
|
+
G1 = [] # nothing to compute
|
|
81
|
+
else:
|
|
82
|
+
i12 = np.concatenate([self.i1, self.i2])
|
|
83
|
+
i12 = [i for i in i12 if i < len(f)]
|
|
84
|
+
G1 = [f[i] - self.start_F[i] for i in i12]
|
|
85
|
+
|
|
86
|
+
G2 = [f[j] - self.start_F[j] for j in self.i3]
|
|
87
|
+
G3 = [f[k] - self.eps[k] for k in self.i4]
|
|
88
|
+
|
|
89
|
+
F = np.max(abs(w[i1234]*(f[i1234]-self.ideal_point[i1234])))
|
|
90
|
+
|
|
91
|
+
G_step = np.concatenate([G1, G2, G3])
|
|
92
|
+
|
|
93
|
+
# Combine with original problem constraints
|
|
94
|
+
out["F"] = [F]
|
|
95
|
+
out["G"] = np.concatenate([G_base, G_step]) if G_base.size > 0 else G_step
|
|
96
|
+
out["H"] = H_base
|
|
97
|
+
|
|
98
|
+
else:
|
|
99
|
+
raise ValueError("mode must be 'start', or 'sub'")
|