desdeo 1.1.3__py3-none-any.whl → 2.0.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.
- desdeo/__init__.py +8 -8
- desdeo/api/README.md +73 -0
- desdeo/api/__init__.py +15 -0
- desdeo/api/app.py +40 -0
- desdeo/api/config.py +69 -0
- desdeo/api/config.toml +53 -0
- desdeo/api/db.py +25 -0
- desdeo/api/db_init.py +79 -0
- desdeo/api/db_models.py +164 -0
- desdeo/api/malaga_db_init.py +27 -0
- desdeo/api/models/__init__.py +66 -0
- desdeo/api/models/archive.py +34 -0
- desdeo/api/models/preference.py +90 -0
- desdeo/api/models/problem.py +507 -0
- desdeo/api/models/reference_point_method.py +18 -0
- desdeo/api/models/session.py +46 -0
- desdeo/api/models/state.py +96 -0
- desdeo/api/models/user.py +51 -0
- desdeo/api/routers/_NAUTILUS.py +245 -0
- desdeo/api/routers/_NAUTILUS_navigator.py +233 -0
- desdeo/api/routers/_NIMBUS.py +762 -0
- desdeo/api/routers/__init__.py +5 -0
- desdeo/api/routers/problem.py +110 -0
- desdeo/api/routers/reference_point_method.py +117 -0
- desdeo/api/routers/session.py +76 -0
- desdeo/api/routers/test.py +16 -0
- desdeo/api/routers/user_authentication.py +366 -0
- desdeo/api/schema.py +94 -0
- desdeo/api/tests/__init__.py +0 -0
- desdeo/api/tests/conftest.py +59 -0
- desdeo/api/tests/test_models.py +701 -0
- desdeo/api/tests/test_routes.py +216 -0
- desdeo/api/utils/database.py +274 -0
- desdeo/api/utils/logger.py +29 -0
- desdeo/core.py +27 -0
- desdeo/emo/__init__.py +29 -0
- desdeo/emo/hooks/archivers.py +172 -0
- desdeo/emo/methods/EAs.py +418 -0
- desdeo/emo/methods/__init__.py +0 -0
- desdeo/emo/methods/bases.py +59 -0
- desdeo/emo/operators/__init__.py +1 -0
- desdeo/emo/operators/crossover.py +780 -0
- desdeo/emo/operators/evaluator.py +118 -0
- desdeo/emo/operators/generator.py +356 -0
- desdeo/emo/operators/mutation.py +1053 -0
- desdeo/emo/operators/selection.py +1036 -0
- desdeo/emo/operators/termination.py +178 -0
- desdeo/explanations/__init__.py +6 -0
- desdeo/explanations/explainer.py +100 -0
- desdeo/explanations/utils.py +90 -0
- desdeo/mcdm/__init__.py +19 -0
- desdeo/mcdm/nautili.py +345 -0
- desdeo/mcdm/nautilus.py +477 -0
- desdeo/mcdm/nautilus_navigator.py +655 -0
- desdeo/mcdm/nimbus.py +417 -0
- desdeo/mcdm/pareto_navigator.py +269 -0
- desdeo/mcdm/reference_point_method.py +116 -0
- desdeo/problem/__init__.py +79 -0
- desdeo/problem/evaluator.py +561 -0
- desdeo/problem/gurobipy_evaluator.py +562 -0
- desdeo/problem/infix_parser.py +341 -0
- desdeo/problem/json_parser.py +944 -0
- desdeo/problem/pyomo_evaluator.py +468 -0
- desdeo/problem/schema.py +1808 -0
- desdeo/problem/simulator_evaluator.py +298 -0
- desdeo/problem/sympy_evaluator.py +244 -0
- desdeo/problem/testproblems/__init__.py +73 -0
- desdeo/problem/testproblems/binh_and_korn_problem.py +88 -0
- desdeo/problem/testproblems/dtlz2_problem.py +102 -0
- desdeo/problem/testproblems/forest_problem.py +275 -0
- desdeo/problem/testproblems/knapsack_problem.py +163 -0
- desdeo/problem/testproblems/mcwb_problem.py +831 -0
- desdeo/problem/testproblems/mixed_variable_dimenrions_problem.py +83 -0
- desdeo/problem/testproblems/momip_problem.py +172 -0
- desdeo/problem/testproblems/nimbus_problem.py +143 -0
- desdeo/problem/testproblems/pareto_navigator_problem.py +89 -0
- desdeo/problem/testproblems/re_problem.py +492 -0
- desdeo/problem/testproblems/river_pollution_problem.py +434 -0
- desdeo/problem/testproblems/rocket_injector_design_problem.py +140 -0
- desdeo/problem/testproblems/simple_problem.py +351 -0
- desdeo/problem/testproblems/simulator_problem.py +92 -0
- desdeo/problem/testproblems/spanish_sustainability_problem.py +945 -0
- desdeo/problem/testproblems/zdt_problem.py +271 -0
- desdeo/problem/utils.py +245 -0
- desdeo/tools/GenerateReferencePoints.py +181 -0
- desdeo/tools/__init__.py +102 -0
- desdeo/tools/generics.py +145 -0
- desdeo/tools/gurobipy_solver_interfaces.py +258 -0
- desdeo/tools/indicators_binary.py +11 -0
- desdeo/tools/indicators_unary.py +375 -0
- desdeo/tools/interaction_schema.py +38 -0
- desdeo/tools/intersection.py +54 -0
- desdeo/tools/iterative_pareto_representer.py +99 -0
- desdeo/tools/message.py +234 -0
- desdeo/tools/ng_solver_interfaces.py +199 -0
- desdeo/tools/non_dominated_sorting.py +133 -0
- desdeo/tools/patterns.py +281 -0
- desdeo/tools/proximal_solver.py +99 -0
- desdeo/tools/pyomo_solver_interfaces.py +464 -0
- desdeo/tools/reference_vectors.py +462 -0
- desdeo/tools/scalarization.py +3138 -0
- desdeo/tools/scipy_solver_interfaces.py +454 -0
- desdeo/tools/score_bands.py +464 -0
- desdeo/tools/utils.py +320 -0
- desdeo/utopia_stuff/__init__.py +0 -0
- desdeo/utopia_stuff/data/1.json +15 -0
- desdeo/utopia_stuff/data/2.json +13 -0
- desdeo/utopia_stuff/data/3.json +15 -0
- desdeo/utopia_stuff/data/4.json +17 -0
- desdeo/utopia_stuff/data/5.json +15 -0
- desdeo/utopia_stuff/from_json.py +40 -0
- desdeo/utopia_stuff/reinit_user.py +38 -0
- desdeo/utopia_stuff/utopia_db_init.py +212 -0
- desdeo/utopia_stuff/utopia_problem.py +403 -0
- desdeo/utopia_stuff/utopia_problem_old.py +415 -0
- desdeo/utopia_stuff/utopia_reference_solutions.py +79 -0
- desdeo-2.0.0.dist-info/LICENSE +21 -0
- desdeo-2.0.0.dist-info/METADATA +168 -0
- desdeo-2.0.0.dist-info/RECORD +120 -0
- {desdeo-1.1.3.dist-info → desdeo-2.0.0.dist-info}/WHEEL +1 -1
- desdeo-1.1.3.dist-info/METADATA +0 -18
- desdeo-1.1.3.dist-info/RECORD +0 -4
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
from desdeo.problem.schema import (
|
|
2
|
+
Constant,
|
|
3
|
+
Constraint,
|
|
4
|
+
ConstraintTypeEnum,
|
|
5
|
+
DiscreteRepresentation,
|
|
6
|
+
ExtraFunction,
|
|
7
|
+
Objective,
|
|
8
|
+
ObjectiveTypeEnum,
|
|
9
|
+
Problem,
|
|
10
|
+
Variable,
|
|
11
|
+
VariableTypeEnum,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
def simple_test_problem() -> Problem:
|
|
15
|
+
"""Defines a simple problem suitable for testing purposes."""
|
|
16
|
+
variables = [
|
|
17
|
+
Variable(name="x_1", symbol="x_1", variable_type="real", lowerbound=0, upperbound=10, initial_value=5),
|
|
18
|
+
Variable(name="x_2", symbol="x_2", variable_type="real", lowerbound=0, upperbound=10, initial_value=5),
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
constants = [Constant(name="c", symbol="c", value=4.2)]
|
|
22
|
+
|
|
23
|
+
f_1 = "x_1 + x_2"
|
|
24
|
+
f_2 = "x_2**3"
|
|
25
|
+
f_3 = "x_1 + x_2"
|
|
26
|
+
f_4 = "Max(Abs(x_1 - x_2), c)" # c = 4.2
|
|
27
|
+
f_5 = "(-x_1) * (-x_2)"
|
|
28
|
+
|
|
29
|
+
objectives = [
|
|
30
|
+
Objective(name="f_1", symbol="f_1", func=f_1, maximize=False), # min!
|
|
31
|
+
Objective(name="f_2", symbol="f_2", func=f_2, maximize=True), # max!
|
|
32
|
+
Objective(name="f_3", symbol="f_3", func=f_3, maximize=True), # max!
|
|
33
|
+
Objective(name="f_4", symbol="f_4", func=f_4, maximize=False), # min!
|
|
34
|
+
Objective(name="f_5", symbol="f_5", func=f_5, maximize=True), # max!
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
return Problem(
|
|
38
|
+
name="Simple test problem.",
|
|
39
|
+
description="A simple problem for testing purposes.",
|
|
40
|
+
constants=constants,
|
|
41
|
+
variables=variables,
|
|
42
|
+
objectives=objectives,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def simple_integer_test_problem() -> Problem:
|
|
47
|
+
"""Defines a simple integer problem suitable for testing purposes."""
|
|
48
|
+
variables = [
|
|
49
|
+
Variable(
|
|
50
|
+
name="x_1",
|
|
51
|
+
symbol="x_1",
|
|
52
|
+
variable_type=VariableTypeEnum.integer,
|
|
53
|
+
lowerbound=0,
|
|
54
|
+
upperbound=10,
|
|
55
|
+
initial_value=5,
|
|
56
|
+
),
|
|
57
|
+
Variable(
|
|
58
|
+
name="x_2",
|
|
59
|
+
symbol="x_2",
|
|
60
|
+
variable_type=VariableTypeEnum.integer,
|
|
61
|
+
lowerbound=0,
|
|
62
|
+
upperbound=10,
|
|
63
|
+
initial_value=5,
|
|
64
|
+
),
|
|
65
|
+
Variable(
|
|
66
|
+
name="x_3",
|
|
67
|
+
symbol="x_3",
|
|
68
|
+
variable_type=VariableTypeEnum.integer,
|
|
69
|
+
lowerbound=0,
|
|
70
|
+
upperbound=10,
|
|
71
|
+
initial_value=5,
|
|
72
|
+
),
|
|
73
|
+
Variable(
|
|
74
|
+
name="x_4",
|
|
75
|
+
symbol="x_4",
|
|
76
|
+
variable_type=VariableTypeEnum.integer,
|
|
77
|
+
lowerbound=0,
|
|
78
|
+
upperbound=10,
|
|
79
|
+
initial_value=5,
|
|
80
|
+
),
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
constants = [Constant(name="c", symbol="c", value=4.2)]
|
|
84
|
+
|
|
85
|
+
f_1 = "x_1 + x_2 + x_3"
|
|
86
|
+
f_2 = "x_2**x_4 - x_3**x_1"
|
|
87
|
+
f_3 = "x_1 - x_2 + x_3*x_4"
|
|
88
|
+
f_4 = "Max(Abs(x_1 - x_2), c) + Max(x_3, x_4)" # c = 4.2
|
|
89
|
+
f_5 = "(-x_1) * (-x_2)"
|
|
90
|
+
|
|
91
|
+
objectives = [
|
|
92
|
+
Objective(name="f_1", symbol="f_1", func=f_1, maximize=False), # min!
|
|
93
|
+
Objective(name="f_2", symbol="f_2", func=f_2, maximize=True), # max!
|
|
94
|
+
Objective(name="f_3", symbol="f_3", func=f_3, maximize=True), # max!
|
|
95
|
+
Objective(name="f_4", symbol="f_4", func=f_4, maximize=False), # min!
|
|
96
|
+
Objective(name="f_5", symbol="f_5", func=f_5, maximize=True), # max!
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
return Problem(
|
|
100
|
+
name="Simple integer test problem.",
|
|
101
|
+
description="A simple problem for testing purposes.",
|
|
102
|
+
constants=constants,
|
|
103
|
+
variables=variables,
|
|
104
|
+
objectives=objectives,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def simple_data_problem() -> Problem:
|
|
109
|
+
"""Defines a simple problem with only data-based objective functions."""
|
|
110
|
+
constants = [Constant(name="c", symbol="c", value=1000)]
|
|
111
|
+
|
|
112
|
+
n_var = 5
|
|
113
|
+
variables = [
|
|
114
|
+
Variable(
|
|
115
|
+
name=f"y_{i}",
|
|
116
|
+
symbol=f"y_{i}",
|
|
117
|
+
variable_type=VariableTypeEnum.real,
|
|
118
|
+
lowerbound=-50.0,
|
|
119
|
+
upperbound=50.0,
|
|
120
|
+
initial_value=0.1,
|
|
121
|
+
)
|
|
122
|
+
for i in range(1, n_var + 1)
|
|
123
|
+
]
|
|
124
|
+
|
|
125
|
+
n_objectives = 3
|
|
126
|
+
# only the first objective is to be maximized, the rest are to be minimized
|
|
127
|
+
objectives = [
|
|
128
|
+
Objective(
|
|
129
|
+
name=f"g_{i}",
|
|
130
|
+
symbol=f"g_{i}",
|
|
131
|
+
func=None,
|
|
132
|
+
objective_type=ObjectiveTypeEnum.data_based,
|
|
133
|
+
maximize=i == 1,
|
|
134
|
+
ideal=3000 if i == 1 else -60.0 if i == 3 else 0,
|
|
135
|
+
nadir=0 if i == 1 else 15 - 2.0 if i == 3 else 15,
|
|
136
|
+
)
|
|
137
|
+
for i in range(1, n_objectives + 1)
|
|
138
|
+
]
|
|
139
|
+
|
|
140
|
+
constraints = [Constraint(name="cons 1", symbol="c_1", cons_type=ConstraintTypeEnum.EQ, func="y_1 + y_2 - c")]
|
|
141
|
+
|
|
142
|
+
data_len = 10
|
|
143
|
+
var_data = {f"y_{i}": [i * 0.5 + j for j in range(data_len)] for i in range(1, n_var + 1)}
|
|
144
|
+
obj_data = {
|
|
145
|
+
"g_1": [sum(var_data[f"y_{j}"][i] for j in range(1, n_var + 1)) ** 2 for i in range(data_len)],
|
|
146
|
+
"g_2": [max(var_data[f"y_{j}"][i] for j in range(1, n_var + 1)) for i in range(data_len)],
|
|
147
|
+
"g_3": [-sum(var_data[f"y_{j}"][i] for j in range(1, n_var + 1)) for i in range(data_len)],
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
discrete_def = DiscreteRepresentation(variable_values=var_data, objective_values=obj_data)
|
|
151
|
+
|
|
152
|
+
return Problem(
|
|
153
|
+
name="Simple data problem",
|
|
154
|
+
description="Simple problem with all objectives being data-based. Has constraints and a constant also.",
|
|
155
|
+
constants=constants,
|
|
156
|
+
variables=variables,
|
|
157
|
+
objectives=objectives,
|
|
158
|
+
constraints=constraints,
|
|
159
|
+
discrete_representation=discrete_def,
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def simple_linear_test_problem() -> Problem:
|
|
164
|
+
"""Defines a simple single objective linear problem suitable for testing purposes."""
|
|
165
|
+
variables = [
|
|
166
|
+
Variable(name="x_1", symbol="x_1", variable_type="real", lowerbound=-10, upperbound=10, initial_value=5),
|
|
167
|
+
Variable(name="x_2", symbol="x_2", variable_type="real", lowerbound=-10, upperbound=10, initial_value=5),
|
|
168
|
+
]
|
|
169
|
+
|
|
170
|
+
constants = [Constant(name="c", symbol="c", value=4.2)]
|
|
171
|
+
|
|
172
|
+
f_1 = "x_1 + x_2"
|
|
173
|
+
|
|
174
|
+
objectives = [
|
|
175
|
+
Objective(name="f_1", symbol="f_1", func=f_1, maximize=False), # min!
|
|
176
|
+
]
|
|
177
|
+
|
|
178
|
+
con_1 = Constraint(name="g_1", symbol="g_1", cons_type=ConstraintTypeEnum.LTE, func="c - x_1")
|
|
179
|
+
con_2 = Constraint(name="g_2", symbol="g_2", cons_type=ConstraintTypeEnum.LTE, func="0.5*x_1 - x_2")
|
|
180
|
+
|
|
181
|
+
return Problem(
|
|
182
|
+
name="Simple linear test problem.",
|
|
183
|
+
description="A simple problem for testing purposes.",
|
|
184
|
+
constants=constants,
|
|
185
|
+
variables=variables,
|
|
186
|
+
constraints=[con_1, con_2],
|
|
187
|
+
objectives=objectives,
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def simple_scenario_test_problem():
|
|
192
|
+
"""Returns a simple, scenario-based multiobjective optimization test problem."""
|
|
193
|
+
constants = [Constant(name="c_1", symbol="c_1", value=3)]
|
|
194
|
+
variables = [
|
|
195
|
+
Variable(
|
|
196
|
+
name="x_1",
|
|
197
|
+
symbol="x_1",
|
|
198
|
+
lowerbound=-5.1,
|
|
199
|
+
upperbound=6.2,
|
|
200
|
+
initial_value=0,
|
|
201
|
+
variable_type=VariableTypeEnum.real,
|
|
202
|
+
),
|
|
203
|
+
Variable(
|
|
204
|
+
name="x_2",
|
|
205
|
+
symbol="x_2",
|
|
206
|
+
lowerbound=-5.2,
|
|
207
|
+
upperbound=6.1,
|
|
208
|
+
initial_value=0,
|
|
209
|
+
variable_type=VariableTypeEnum.real,
|
|
210
|
+
),
|
|
211
|
+
]
|
|
212
|
+
|
|
213
|
+
constraints = [
|
|
214
|
+
Constraint(
|
|
215
|
+
name="con_1",
|
|
216
|
+
symbol="con_1",
|
|
217
|
+
cons_type=ConstraintTypeEnum.LTE,
|
|
218
|
+
func="x_1 + x_2 - 15",
|
|
219
|
+
is_linear=True,
|
|
220
|
+
is_convex=True,
|
|
221
|
+
is_twice_differentiable=True,
|
|
222
|
+
scenario_keys="s_1",
|
|
223
|
+
),
|
|
224
|
+
Constraint(
|
|
225
|
+
name="con_2",
|
|
226
|
+
symbol="con_2",
|
|
227
|
+
cons_type=ConstraintTypeEnum.LTE,
|
|
228
|
+
func="x_1 + x_2 - 65",
|
|
229
|
+
is_linear=True,
|
|
230
|
+
is_convex=True,
|
|
231
|
+
is_twice_differentiable=True,
|
|
232
|
+
scenario_keys="s_2",
|
|
233
|
+
),
|
|
234
|
+
Constraint(
|
|
235
|
+
name="con_3",
|
|
236
|
+
symbol="con_3",
|
|
237
|
+
cons_type=ConstraintTypeEnum.LTE,
|
|
238
|
+
func="x_2 - 50",
|
|
239
|
+
is_linear=True,
|
|
240
|
+
is_convex=True,
|
|
241
|
+
is_twice_differentiable=True,
|
|
242
|
+
scenario_keys=None,
|
|
243
|
+
),
|
|
244
|
+
Constraint(
|
|
245
|
+
name="con_4",
|
|
246
|
+
symbol="con_4",
|
|
247
|
+
cons_type=ConstraintTypeEnum.LTE,
|
|
248
|
+
func="x_1 - 5",
|
|
249
|
+
is_linear=True,
|
|
250
|
+
is_convex=True,
|
|
251
|
+
is_twice_differentiable=True,
|
|
252
|
+
scenario_keys=["s_1", "s_2"],
|
|
253
|
+
),
|
|
254
|
+
]
|
|
255
|
+
|
|
256
|
+
expr_1 = "x_1 + x_2"
|
|
257
|
+
expr_2 = "x_1 - x_2"
|
|
258
|
+
expr_3 = "(x_1 - 3)**2 + x_2"
|
|
259
|
+
expr_4 = "c_1 + x_2**2 - x_1"
|
|
260
|
+
expr_5 = "-x_1 - x_2"
|
|
261
|
+
|
|
262
|
+
objectives = [
|
|
263
|
+
Objective(
|
|
264
|
+
name="f_1",
|
|
265
|
+
symbol="f_1",
|
|
266
|
+
func=expr_1,
|
|
267
|
+
maximize=False,
|
|
268
|
+
ideal=-100,
|
|
269
|
+
nadir=100,
|
|
270
|
+
objective_type=ObjectiveTypeEnum.analytical,
|
|
271
|
+
is_linear=True,
|
|
272
|
+
is_convex=True,
|
|
273
|
+
is_twice_differentiable=True,
|
|
274
|
+
scenario_keys="s_1",
|
|
275
|
+
),
|
|
276
|
+
Objective(
|
|
277
|
+
name="f_2",
|
|
278
|
+
symbol="f_2",
|
|
279
|
+
func=expr_2,
|
|
280
|
+
maximize=False,
|
|
281
|
+
ideal=-100,
|
|
282
|
+
nadir=100,
|
|
283
|
+
objective_type=ObjectiveTypeEnum.analytical,
|
|
284
|
+
is_linear=True,
|
|
285
|
+
is_convex=True,
|
|
286
|
+
is_twice_differentiable=True,
|
|
287
|
+
scenario_keys=["s_1", "s_2"],
|
|
288
|
+
),
|
|
289
|
+
Objective(
|
|
290
|
+
name="f_3",
|
|
291
|
+
symbol="f_3",
|
|
292
|
+
func=expr_3,
|
|
293
|
+
maximize=False,
|
|
294
|
+
ideal=-100,
|
|
295
|
+
nadir=100,
|
|
296
|
+
objective_type=ObjectiveTypeEnum.analytical,
|
|
297
|
+
is_linear=True,
|
|
298
|
+
is_convex=True,
|
|
299
|
+
is_twice_differentiable=True,
|
|
300
|
+
scenario_keys=None,
|
|
301
|
+
),
|
|
302
|
+
Objective(
|
|
303
|
+
name="f_4",
|
|
304
|
+
symbol="f_4",
|
|
305
|
+
func=expr_4,
|
|
306
|
+
maximize=False,
|
|
307
|
+
ideal=-100,
|
|
308
|
+
nadir=100,
|
|
309
|
+
objective_type=ObjectiveTypeEnum.analytical,
|
|
310
|
+
is_linear=True,
|
|
311
|
+
is_convex=True,
|
|
312
|
+
is_twice_differentiable=True,
|
|
313
|
+
scenario_keys="s_2",
|
|
314
|
+
),
|
|
315
|
+
Objective(
|
|
316
|
+
name="f_5",
|
|
317
|
+
symbol="f_5",
|
|
318
|
+
func=expr_5,
|
|
319
|
+
maximize=False,
|
|
320
|
+
ideal=-100,
|
|
321
|
+
nadir=100,
|
|
322
|
+
objective_type=ObjectiveTypeEnum.analytical,
|
|
323
|
+
is_linear=True,
|
|
324
|
+
is_convex=True,
|
|
325
|
+
is_twice_differentiable=True,
|
|
326
|
+
scenario_keys="s_2",
|
|
327
|
+
),
|
|
328
|
+
]
|
|
329
|
+
|
|
330
|
+
extra_funcs = [
|
|
331
|
+
ExtraFunction(
|
|
332
|
+
name="extra_1",
|
|
333
|
+
symbol="extra_1",
|
|
334
|
+
func="5*x_1",
|
|
335
|
+
is_linear=True,
|
|
336
|
+
is_convex=True,
|
|
337
|
+
is_twice_differentiable=True,
|
|
338
|
+
scenario_keys="s_2",
|
|
339
|
+
)
|
|
340
|
+
]
|
|
341
|
+
|
|
342
|
+
return Problem(
|
|
343
|
+
name="Simple scenario test problem",
|
|
344
|
+
description="For testing the implementation of scenario-based problems.",
|
|
345
|
+
variables=variables,
|
|
346
|
+
constants=constants,
|
|
347
|
+
constraints=constraints,
|
|
348
|
+
objectives=objectives,
|
|
349
|
+
extra_funcs=extra_funcs,
|
|
350
|
+
scenario_keys=["s_1", "s_2"],
|
|
351
|
+
)
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from desdeo.problem.schema import (
|
|
4
|
+
Constraint,
|
|
5
|
+
ConstraintTypeEnum,
|
|
6
|
+
ExtraFunction,
|
|
7
|
+
Objective,
|
|
8
|
+
ObjectiveTypeEnum,
|
|
9
|
+
Problem,
|
|
10
|
+
Simulator,
|
|
11
|
+
Variable,
|
|
12
|
+
VariableTypeEnum,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
def simulator_problem(file_dir: str | Path):
|
|
16
|
+
"""A test problem with analytical, simulator and surrogate based objectives, constraints and extra functions.
|
|
17
|
+
|
|
18
|
+
The problem uses two different simulator files. There are also objectives, constraints and extra fucntions that
|
|
19
|
+
are surrogate based but it is assumed that the surrogate models are given when evaluating (while testing they
|
|
20
|
+
are stored as temporary directories and files by pytest). There are also analytical functions to test utilizing
|
|
21
|
+
PolarsEvaluator from the simulator evaluator.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
file_dir (str | Path): path to the directory with the simulator files.
|
|
25
|
+
"""
|
|
26
|
+
variables = [
|
|
27
|
+
Variable(name="x_1", symbol="x_1", variable_type=VariableTypeEnum.real),
|
|
28
|
+
Variable(name="x_2", symbol="x_2", variable_type=VariableTypeEnum.real),
|
|
29
|
+
Variable(name="x_3", symbol="x_3", variable_type=VariableTypeEnum.real),
|
|
30
|
+
Variable(name="x_4", symbol="x_4", variable_type=VariableTypeEnum.real),
|
|
31
|
+
]
|
|
32
|
+
f1 = Objective(
|
|
33
|
+
name="f_1",
|
|
34
|
+
symbol="f_1",
|
|
35
|
+
simulator_path=Path(f"{file_dir}/simulator_file.py"),
|
|
36
|
+
objective_type=ObjectiveTypeEnum.simulator,
|
|
37
|
+
)
|
|
38
|
+
f2 = Objective(
|
|
39
|
+
name="f_2", symbol="f_2", func="x_1 + x_2 + x_3", maximize=True, objective_type=ObjectiveTypeEnum.analytical
|
|
40
|
+
)
|
|
41
|
+
f3 = Objective(
|
|
42
|
+
name="f_3",
|
|
43
|
+
symbol="f_3",
|
|
44
|
+
maximize=True,
|
|
45
|
+
simulator_path=f"{file_dir}/simulator_file2.py",
|
|
46
|
+
objective_type=ObjectiveTypeEnum.simulator,
|
|
47
|
+
)
|
|
48
|
+
f4 = Objective(
|
|
49
|
+
name="f_4",
|
|
50
|
+
symbol="f_4",
|
|
51
|
+
simulator_path=f"{file_dir}/simulator_file.py",
|
|
52
|
+
objective_type=ObjectiveTypeEnum.simulator,
|
|
53
|
+
)
|
|
54
|
+
f5 = Objective(name="f_5", symbol="f_5", objective_type=ObjectiveTypeEnum.surrogate)
|
|
55
|
+
f6 = Objective(name="f_6", symbol="f_6", objective_type=ObjectiveTypeEnum.surrogate)
|
|
56
|
+
g1 = Constraint(
|
|
57
|
+
name="g_1",
|
|
58
|
+
symbol="g_1",
|
|
59
|
+
cons_type=ConstraintTypeEnum.LTE,
|
|
60
|
+
simulator_path=f"{file_dir}/simulator_file2.py",
|
|
61
|
+
)
|
|
62
|
+
g2 = Constraint(
|
|
63
|
+
name="g_2",
|
|
64
|
+
symbol="g_2",
|
|
65
|
+
cons_type=ConstraintTypeEnum.LTE,
|
|
66
|
+
func="-x_1 - x_2 - x_3",
|
|
67
|
+
)
|
|
68
|
+
g3 = Constraint(
|
|
69
|
+
name="g_3",
|
|
70
|
+
symbol="g_3",
|
|
71
|
+
cons_type=ConstraintTypeEnum.LTE,
|
|
72
|
+
)
|
|
73
|
+
e1 = ExtraFunction(name="e_1", symbol="e_1", simulator_path=f"{file_dir}/simulator_file.py")
|
|
74
|
+
e2 = ExtraFunction(name="e_2", symbol="e_2", func="x_1 * x_2 * x_3")
|
|
75
|
+
e3 = ExtraFunction(
|
|
76
|
+
name="e_3",
|
|
77
|
+
symbol="e_3",
|
|
78
|
+
)
|
|
79
|
+
return Problem(
|
|
80
|
+
name="Simulator problem",
|
|
81
|
+
description="",
|
|
82
|
+
variables=variables,
|
|
83
|
+
objectives=[f1, f2, f3, f4, f5, f6],
|
|
84
|
+
constraints=[g1, g2, g3],
|
|
85
|
+
extra_funcs=[e1, e2, e3],
|
|
86
|
+
simulators=[
|
|
87
|
+
Simulator(
|
|
88
|
+
name="s_1", symbol="s_1", file=Path(f"{file_dir}/simulator_file.py"), parameter_options={"delta": 0.5}
|
|
89
|
+
),
|
|
90
|
+
Simulator(name="s_2", symbol="s_2", file=Path(f"{file_dir}/simulator_file2.py")),
|
|
91
|
+
],
|
|
92
|
+
)
|