desdeo 1.2__py3-none-any.whl → 2.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.
Files changed (182) hide show
  1. desdeo/__init__.py +8 -8
  2. desdeo/adm/ADMAfsar.py +551 -0
  3. desdeo/adm/ADMChen.py +414 -0
  4. desdeo/adm/BaseADM.py +119 -0
  5. desdeo/adm/__init__.py +11 -0
  6. desdeo/api/README.md +73 -0
  7. desdeo/api/__init__.py +15 -0
  8. desdeo/api/app.py +50 -0
  9. desdeo/api/config.py +90 -0
  10. desdeo/api/config.toml +64 -0
  11. desdeo/api/db.py +27 -0
  12. desdeo/api/db_init.py +85 -0
  13. desdeo/api/db_models.py +164 -0
  14. desdeo/api/malaga_db_init.py +27 -0
  15. desdeo/api/models/__init__.py +266 -0
  16. desdeo/api/models/archive.py +23 -0
  17. desdeo/api/models/emo.py +128 -0
  18. desdeo/api/models/enautilus.py +69 -0
  19. desdeo/api/models/gdm/gdm_aggregate.py +139 -0
  20. desdeo/api/models/gdm/gdm_base.py +69 -0
  21. desdeo/api/models/gdm/gdm_score_bands.py +114 -0
  22. desdeo/api/models/gdm/gnimbus.py +138 -0
  23. desdeo/api/models/generic.py +104 -0
  24. desdeo/api/models/generic_states.py +401 -0
  25. desdeo/api/models/nimbus.py +158 -0
  26. desdeo/api/models/preference.py +128 -0
  27. desdeo/api/models/problem.py +717 -0
  28. desdeo/api/models/reference_point_method.py +18 -0
  29. desdeo/api/models/session.py +49 -0
  30. desdeo/api/models/state.py +463 -0
  31. desdeo/api/models/user.py +52 -0
  32. desdeo/api/models/utopia.py +25 -0
  33. desdeo/api/routers/_EMO.backup +309 -0
  34. desdeo/api/routers/_NAUTILUS.py +245 -0
  35. desdeo/api/routers/_NAUTILUS_navigator.py +233 -0
  36. desdeo/api/routers/_NIMBUS.py +765 -0
  37. desdeo/api/routers/__init__.py +5 -0
  38. desdeo/api/routers/emo.py +497 -0
  39. desdeo/api/routers/enautilus.py +237 -0
  40. desdeo/api/routers/gdm/gdm_aggregate.py +234 -0
  41. desdeo/api/routers/gdm/gdm_base.py +420 -0
  42. desdeo/api/routers/gdm/gdm_score_bands/gdm_score_bands_manager.py +398 -0
  43. desdeo/api/routers/gdm/gdm_score_bands/gdm_score_bands_routers.py +377 -0
  44. desdeo/api/routers/gdm/gnimbus/gnimbus_manager.py +698 -0
  45. desdeo/api/routers/gdm/gnimbus/gnimbus_routers.py +591 -0
  46. desdeo/api/routers/generic.py +233 -0
  47. desdeo/api/routers/nimbus.py +705 -0
  48. desdeo/api/routers/problem.py +307 -0
  49. desdeo/api/routers/reference_point_method.py +93 -0
  50. desdeo/api/routers/session.py +100 -0
  51. desdeo/api/routers/test.py +16 -0
  52. desdeo/api/routers/user_authentication.py +520 -0
  53. desdeo/api/routers/utils.py +187 -0
  54. desdeo/api/routers/utopia.py +230 -0
  55. desdeo/api/schema.py +100 -0
  56. desdeo/api/tests/__init__.py +0 -0
  57. desdeo/api/tests/conftest.py +151 -0
  58. desdeo/api/tests/test_enautilus.py +330 -0
  59. desdeo/api/tests/test_models.py +1179 -0
  60. desdeo/api/tests/test_routes.py +1075 -0
  61. desdeo/api/utils/_database.py +263 -0
  62. desdeo/api/utils/_logger.py +29 -0
  63. desdeo/api/utils/database.py +36 -0
  64. desdeo/api/utils/emo_database.py +40 -0
  65. desdeo/core.py +34 -0
  66. desdeo/emo/__init__.py +159 -0
  67. desdeo/emo/hooks/archivers.py +188 -0
  68. desdeo/emo/methods/EAs.py +541 -0
  69. desdeo/emo/methods/__init__.py +0 -0
  70. desdeo/emo/methods/bases.py +12 -0
  71. desdeo/emo/methods/templates.py +111 -0
  72. desdeo/emo/operators/__init__.py +1 -0
  73. desdeo/emo/operators/crossover.py +1282 -0
  74. desdeo/emo/operators/evaluator.py +114 -0
  75. desdeo/emo/operators/generator.py +459 -0
  76. desdeo/emo/operators/mutation.py +1224 -0
  77. desdeo/emo/operators/scalar_selection.py +202 -0
  78. desdeo/emo/operators/selection.py +1778 -0
  79. desdeo/emo/operators/termination.py +286 -0
  80. desdeo/emo/options/__init__.py +108 -0
  81. desdeo/emo/options/algorithms.py +435 -0
  82. desdeo/emo/options/crossover.py +164 -0
  83. desdeo/emo/options/generator.py +131 -0
  84. desdeo/emo/options/mutation.py +260 -0
  85. desdeo/emo/options/repair.py +61 -0
  86. desdeo/emo/options/scalar_selection.py +66 -0
  87. desdeo/emo/options/selection.py +127 -0
  88. desdeo/emo/options/templates.py +383 -0
  89. desdeo/emo/options/termination.py +143 -0
  90. desdeo/explanations/__init__.py +6 -0
  91. desdeo/explanations/explainer.py +100 -0
  92. desdeo/explanations/utils.py +90 -0
  93. desdeo/gdm/__init__.py +22 -0
  94. desdeo/gdm/gdmtools.py +45 -0
  95. desdeo/gdm/score_bands.py +114 -0
  96. desdeo/gdm/voting_rules.py +50 -0
  97. desdeo/mcdm/__init__.py +41 -0
  98. desdeo/mcdm/enautilus.py +338 -0
  99. desdeo/mcdm/gnimbus.py +484 -0
  100. desdeo/mcdm/nautili.py +345 -0
  101. desdeo/mcdm/nautilus.py +477 -0
  102. desdeo/mcdm/nautilus_navigator.py +656 -0
  103. desdeo/mcdm/nimbus.py +417 -0
  104. desdeo/mcdm/pareto_navigator.py +269 -0
  105. desdeo/mcdm/reference_point_method.py +186 -0
  106. desdeo/problem/__init__.py +83 -0
  107. desdeo/problem/evaluator.py +561 -0
  108. desdeo/problem/external/__init__.py +18 -0
  109. desdeo/problem/external/core.py +356 -0
  110. desdeo/problem/external/pymoo_provider.py +266 -0
  111. desdeo/problem/external/runtime.py +44 -0
  112. desdeo/problem/gurobipy_evaluator.py +562 -0
  113. desdeo/problem/infix_parser.py +341 -0
  114. desdeo/problem/json_parser.py +944 -0
  115. desdeo/problem/pyomo_evaluator.py +487 -0
  116. desdeo/problem/schema.py +1829 -0
  117. desdeo/problem/simulator_evaluator.py +348 -0
  118. desdeo/problem/sympy_evaluator.py +244 -0
  119. desdeo/problem/testproblems/__init__.py +88 -0
  120. desdeo/problem/testproblems/benchmarks_server.py +120 -0
  121. desdeo/problem/testproblems/binh_and_korn_problem.py +88 -0
  122. desdeo/problem/testproblems/cake_problem.py +185 -0
  123. desdeo/problem/testproblems/dmitry_forest_problem_discrete.py +71 -0
  124. desdeo/problem/testproblems/dtlz2_problem.py +102 -0
  125. desdeo/problem/testproblems/forest_problem.py +283 -0
  126. desdeo/problem/testproblems/knapsack_problem.py +163 -0
  127. desdeo/problem/testproblems/mcwb_problem.py +831 -0
  128. desdeo/problem/testproblems/mixed_variable_dimenrions_problem.py +83 -0
  129. desdeo/problem/testproblems/momip_problem.py +172 -0
  130. desdeo/problem/testproblems/multi_valued_constraints.py +119 -0
  131. desdeo/problem/testproblems/nimbus_problem.py +143 -0
  132. desdeo/problem/testproblems/pareto_navigator_problem.py +89 -0
  133. desdeo/problem/testproblems/re_problem.py +492 -0
  134. desdeo/problem/testproblems/river_pollution_problems.py +440 -0
  135. desdeo/problem/testproblems/rocket_injector_design_problem.py +140 -0
  136. desdeo/problem/testproblems/simple_problem.py +351 -0
  137. desdeo/problem/testproblems/simulator_problem.py +92 -0
  138. desdeo/problem/testproblems/single_objective.py +289 -0
  139. desdeo/problem/testproblems/spanish_sustainability_problem.py +945 -0
  140. desdeo/problem/testproblems/zdt_problem.py +274 -0
  141. desdeo/problem/utils.py +245 -0
  142. desdeo/tools/GenerateReferencePoints.py +181 -0
  143. desdeo/tools/__init__.py +120 -0
  144. desdeo/tools/desc_gen.py +22 -0
  145. desdeo/tools/generics.py +165 -0
  146. desdeo/tools/group_scalarization.py +3090 -0
  147. desdeo/tools/gurobipy_solver_interfaces.py +258 -0
  148. desdeo/tools/indicators_binary.py +117 -0
  149. desdeo/tools/indicators_unary.py +362 -0
  150. desdeo/tools/interaction_schema.py +38 -0
  151. desdeo/tools/intersection.py +54 -0
  152. desdeo/tools/iterative_pareto_representer.py +99 -0
  153. desdeo/tools/message.py +265 -0
  154. desdeo/tools/ng_solver_interfaces.py +199 -0
  155. desdeo/tools/non_dominated_sorting.py +134 -0
  156. desdeo/tools/patterns.py +283 -0
  157. desdeo/tools/proximal_solver.py +99 -0
  158. desdeo/tools/pyomo_solver_interfaces.py +477 -0
  159. desdeo/tools/reference_vectors.py +229 -0
  160. desdeo/tools/scalarization.py +2065 -0
  161. desdeo/tools/scipy_solver_interfaces.py +454 -0
  162. desdeo/tools/score_bands.py +627 -0
  163. desdeo/tools/utils.py +388 -0
  164. desdeo/tools/visualizations.py +67 -0
  165. desdeo/utopia_stuff/__init__.py +0 -0
  166. desdeo/utopia_stuff/data/1.json +15 -0
  167. desdeo/utopia_stuff/data/2.json +13 -0
  168. desdeo/utopia_stuff/data/3.json +15 -0
  169. desdeo/utopia_stuff/data/4.json +17 -0
  170. desdeo/utopia_stuff/data/5.json +15 -0
  171. desdeo/utopia_stuff/from_json.py +40 -0
  172. desdeo/utopia_stuff/reinit_user.py +38 -0
  173. desdeo/utopia_stuff/utopia_db_init.py +212 -0
  174. desdeo/utopia_stuff/utopia_problem.py +403 -0
  175. desdeo/utopia_stuff/utopia_problem_old.py +415 -0
  176. desdeo/utopia_stuff/utopia_reference_solutions.py +79 -0
  177. desdeo-2.1.0.dist-info/METADATA +186 -0
  178. desdeo-2.1.0.dist-info/RECORD +180 -0
  179. {desdeo-1.2.dist-info → desdeo-2.1.0.dist-info}/WHEEL +1 -1
  180. desdeo-2.1.0.dist-info/licenses/LICENSE +21 -0
  181. desdeo-1.2.dist-info/METADATA +0 -16
  182. desdeo-1.2.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
+ )