desdeo 1.2__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.
Files changed (122) hide show
  1. desdeo/__init__.py +8 -8
  2. desdeo/api/README.md +73 -0
  3. desdeo/api/__init__.py +15 -0
  4. desdeo/api/app.py +40 -0
  5. desdeo/api/config.py +69 -0
  6. desdeo/api/config.toml +53 -0
  7. desdeo/api/db.py +25 -0
  8. desdeo/api/db_init.py +79 -0
  9. desdeo/api/db_models.py +164 -0
  10. desdeo/api/malaga_db_init.py +27 -0
  11. desdeo/api/models/__init__.py +66 -0
  12. desdeo/api/models/archive.py +34 -0
  13. desdeo/api/models/preference.py +90 -0
  14. desdeo/api/models/problem.py +507 -0
  15. desdeo/api/models/reference_point_method.py +18 -0
  16. desdeo/api/models/session.py +46 -0
  17. desdeo/api/models/state.py +96 -0
  18. desdeo/api/models/user.py +51 -0
  19. desdeo/api/routers/_NAUTILUS.py +245 -0
  20. desdeo/api/routers/_NAUTILUS_navigator.py +233 -0
  21. desdeo/api/routers/_NIMBUS.py +762 -0
  22. desdeo/api/routers/__init__.py +5 -0
  23. desdeo/api/routers/problem.py +110 -0
  24. desdeo/api/routers/reference_point_method.py +117 -0
  25. desdeo/api/routers/session.py +76 -0
  26. desdeo/api/routers/test.py +16 -0
  27. desdeo/api/routers/user_authentication.py +366 -0
  28. desdeo/api/schema.py +94 -0
  29. desdeo/api/tests/__init__.py +0 -0
  30. desdeo/api/tests/conftest.py +59 -0
  31. desdeo/api/tests/test_models.py +701 -0
  32. desdeo/api/tests/test_routes.py +216 -0
  33. desdeo/api/utils/database.py +274 -0
  34. desdeo/api/utils/logger.py +29 -0
  35. desdeo/core.py +27 -0
  36. desdeo/emo/__init__.py +29 -0
  37. desdeo/emo/hooks/archivers.py +172 -0
  38. desdeo/emo/methods/EAs.py +418 -0
  39. desdeo/emo/methods/__init__.py +0 -0
  40. desdeo/emo/methods/bases.py +59 -0
  41. desdeo/emo/operators/__init__.py +1 -0
  42. desdeo/emo/operators/crossover.py +780 -0
  43. desdeo/emo/operators/evaluator.py +118 -0
  44. desdeo/emo/operators/generator.py +356 -0
  45. desdeo/emo/operators/mutation.py +1053 -0
  46. desdeo/emo/operators/selection.py +1036 -0
  47. desdeo/emo/operators/termination.py +178 -0
  48. desdeo/explanations/__init__.py +6 -0
  49. desdeo/explanations/explainer.py +100 -0
  50. desdeo/explanations/utils.py +90 -0
  51. desdeo/mcdm/__init__.py +19 -0
  52. desdeo/mcdm/nautili.py +345 -0
  53. desdeo/mcdm/nautilus.py +477 -0
  54. desdeo/mcdm/nautilus_navigator.py +655 -0
  55. desdeo/mcdm/nimbus.py +417 -0
  56. desdeo/mcdm/pareto_navigator.py +269 -0
  57. desdeo/mcdm/reference_point_method.py +116 -0
  58. desdeo/problem/__init__.py +79 -0
  59. desdeo/problem/evaluator.py +561 -0
  60. desdeo/problem/gurobipy_evaluator.py +562 -0
  61. desdeo/problem/infix_parser.py +341 -0
  62. desdeo/problem/json_parser.py +944 -0
  63. desdeo/problem/pyomo_evaluator.py +468 -0
  64. desdeo/problem/schema.py +1808 -0
  65. desdeo/problem/simulator_evaluator.py +298 -0
  66. desdeo/problem/sympy_evaluator.py +244 -0
  67. desdeo/problem/testproblems/__init__.py +73 -0
  68. desdeo/problem/testproblems/binh_and_korn_problem.py +88 -0
  69. desdeo/problem/testproblems/dtlz2_problem.py +102 -0
  70. desdeo/problem/testproblems/forest_problem.py +275 -0
  71. desdeo/problem/testproblems/knapsack_problem.py +163 -0
  72. desdeo/problem/testproblems/mcwb_problem.py +831 -0
  73. desdeo/problem/testproblems/mixed_variable_dimenrions_problem.py +83 -0
  74. desdeo/problem/testproblems/momip_problem.py +172 -0
  75. desdeo/problem/testproblems/nimbus_problem.py +143 -0
  76. desdeo/problem/testproblems/pareto_navigator_problem.py +89 -0
  77. desdeo/problem/testproblems/re_problem.py +492 -0
  78. desdeo/problem/testproblems/river_pollution_problem.py +434 -0
  79. desdeo/problem/testproblems/rocket_injector_design_problem.py +140 -0
  80. desdeo/problem/testproblems/simple_problem.py +351 -0
  81. desdeo/problem/testproblems/simulator_problem.py +92 -0
  82. desdeo/problem/testproblems/spanish_sustainability_problem.py +945 -0
  83. desdeo/problem/testproblems/zdt_problem.py +271 -0
  84. desdeo/problem/utils.py +245 -0
  85. desdeo/tools/GenerateReferencePoints.py +181 -0
  86. desdeo/tools/__init__.py +102 -0
  87. desdeo/tools/generics.py +145 -0
  88. desdeo/tools/gurobipy_solver_interfaces.py +258 -0
  89. desdeo/tools/indicators_binary.py +11 -0
  90. desdeo/tools/indicators_unary.py +375 -0
  91. desdeo/tools/interaction_schema.py +38 -0
  92. desdeo/tools/intersection.py +54 -0
  93. desdeo/tools/iterative_pareto_representer.py +99 -0
  94. desdeo/tools/message.py +234 -0
  95. desdeo/tools/ng_solver_interfaces.py +199 -0
  96. desdeo/tools/non_dominated_sorting.py +133 -0
  97. desdeo/tools/patterns.py +281 -0
  98. desdeo/tools/proximal_solver.py +99 -0
  99. desdeo/tools/pyomo_solver_interfaces.py +464 -0
  100. desdeo/tools/reference_vectors.py +462 -0
  101. desdeo/tools/scalarization.py +3138 -0
  102. desdeo/tools/scipy_solver_interfaces.py +454 -0
  103. desdeo/tools/score_bands.py +464 -0
  104. desdeo/tools/utils.py +320 -0
  105. desdeo/utopia_stuff/__init__.py +0 -0
  106. desdeo/utopia_stuff/data/1.json +15 -0
  107. desdeo/utopia_stuff/data/2.json +13 -0
  108. desdeo/utopia_stuff/data/3.json +15 -0
  109. desdeo/utopia_stuff/data/4.json +17 -0
  110. desdeo/utopia_stuff/data/5.json +15 -0
  111. desdeo/utopia_stuff/from_json.py +40 -0
  112. desdeo/utopia_stuff/reinit_user.py +38 -0
  113. desdeo/utopia_stuff/utopia_db_init.py +212 -0
  114. desdeo/utopia_stuff/utopia_problem.py +403 -0
  115. desdeo/utopia_stuff/utopia_problem_old.py +415 -0
  116. desdeo/utopia_stuff/utopia_reference_solutions.py +79 -0
  117. desdeo-2.0.0.dist-info/LICENSE +21 -0
  118. desdeo-2.0.0.dist-info/METADATA +168 -0
  119. desdeo-2.0.0.dist-info/RECORD +120 -0
  120. {desdeo-1.2.dist-info → desdeo-2.0.0.dist-info}/WHEEL +1 -1
  121. desdeo-1.2.dist-info/METADATA +0 -16
  122. desdeo-1.2.dist-info/RECORD +0 -4
@@ -0,0 +1,434 @@
1
+ from pathlib import Path
2
+
3
+ import polars as pl
4
+
5
+ from desdeo.problem.schema import (
6
+ DiscreteRepresentation,
7
+ Objective,
8
+ ObjectiveTypeEnum,
9
+ Problem,
10
+ TensorConstant,
11
+ Variable,
12
+ VariableTypeEnum,
13
+ )
14
+
15
+ def river_pollution_problem(*, five_objective_variant: bool = True) -> Problem:
16
+ r"""Create a pydantic dataclass representation of the river pollution problem with either five or four variables.
17
+
18
+ The objective functions "DO city" ($f_1$), "DO municipality" ($f_2), and
19
+ "ROI fishery" ($f_3$) and "ROI city" ($f_4$) are to be
20
+ maximized. If the four variant problem is used, the the "BOD deviation" objective
21
+ function ($f_5$) is not present, but if it is, it is to be minimized.
22
+ The problem is defined as follows:
23
+
24
+ \begin{align*}
25
+ \max f_1(x) &= 4.07 + 2.27 x_1 \\
26
+ \max f_2(x) &= 2.60 + 0.03 x_1 + 0.02 x_2 + \frac{0.01}{1.39 - x_1^2} + \frac{0.30}{1.39 - x_2^2} \\
27
+ \max f_3(x) &= 8.21 - \frac{0.71}{1.09 - x_1^2} \\
28
+ \max f_4(x) &= 0.96 - \frac{0.96}{1.09 - x_2^2} \\
29
+ \min f_5(x) &= \max(|x_1 - 0.65|, |x_2 - 0.65|) \\
30
+ \text{s.t.}\quad & 0.3 \leq x_1 \leq 1.0,\\
31
+ & 0.3 \leq x_2 \leq 1.0,\\
32
+ \end{align*}
33
+
34
+ where the fifth objective is part of the problem definition only if
35
+ `five_objective_variant = True`.
36
+
37
+ Args:
38
+ five_objective_variant (bool, optional): Whether to use to five
39
+ objective function variant of the problem or not. Defaults to True.
40
+
41
+ Returns:
42
+ Problem: the river pollution problem.
43
+
44
+ References:
45
+ Narula, Subhash C., and HRoland Weistroffer. "A flexible method for
46
+ nonlinear multicriteria decision-making problems." IEEE Transactions on
47
+ Systems, Man, and Cybernetics 19.4 (1989): 883-887.
48
+
49
+ Miettinen, Kaisa, and Marko M. Mäkelä. "Interactive method NIMBUS for
50
+ nondifferentiable multiobjective optimization problems." Multicriteria
51
+ Analysis: Proceedings of the XIth International Conference on MCDM, 1-6
52
+ August 1994, Coimbra, Portugal. Berlin, Heidelberg: Springer Berlin
53
+ Heidelberg, 1997.
54
+ """
55
+ variable_1 = Variable(
56
+ name="BOD", symbol="x_1", variable_type="real", lowerbound=0.3, upperbound=1.0, initial_value=0.65
57
+ )
58
+ variable_2 = Variable(
59
+ name="DO", symbol="x_2", variable_type="real", lowerbound=0.3, upperbound=1.0, initial_value=0.65
60
+ )
61
+
62
+ f_1 = "4.07 + 2.27 * x_1"
63
+ f_2 = "2.60 + 0.03 * x_1 + 0.02 * x_2 + 0.01 / (1.39 - x_1**2) + 0.30 / (1.39 - x_2**2)"
64
+ f_3 = "8.21 - 0.71 / (1.09 - x_1**2)"
65
+ f_4 = "0.96 - 0.96 / (1.09 - x_2**2)"
66
+ f_5 = "Max(Abs(x_1 - 0.65), Abs(x_2 - 0.65))"
67
+
68
+ objective_1 = Objective(
69
+ name="DO city",
70
+ symbol="f_1",
71
+ func=f_1,
72
+ maximize=True,
73
+ ideal=6.34,
74
+ nadir=4.75,
75
+ is_convex=True,
76
+ is_linear=True,
77
+ is_twice_differentiable=True,
78
+ )
79
+ objective_2 = Objective(
80
+ name="DO municipality",
81
+ symbol="f_2",
82
+ func=f_2,
83
+ maximize=True,
84
+ ideal=3.44,
85
+ nadir=2.85,
86
+ is_convex=False,
87
+ is_linear=False,
88
+ is_twice_differentiable=True,
89
+ )
90
+ objective_3 = Objective(
91
+ name="ROI fishery",
92
+ symbol="f_3",
93
+ func=f_3,
94
+ maximize=True,
95
+ ideal=7.5,
96
+ nadir=0.32,
97
+ is_convex=True,
98
+ is_linear=False,
99
+ is_twice_differentiable=True,
100
+ )
101
+ objective_4 = Objective(
102
+ name="ROI city",
103
+ symbol="f_4",
104
+ func=f_4,
105
+ maximize=True,
106
+ ideal=0,
107
+ nadir=-9.70,
108
+ is_convex=True,
109
+ is_linear=False,
110
+ is_twice_differentiable=True,
111
+ )
112
+ objective_5 = Objective(
113
+ name="BOD deviation",
114
+ symbol="f_5",
115
+ func=f_5,
116
+ maximize=False,
117
+ ideal=0,
118
+ nadir=0.35,
119
+ is_convex=False,
120
+ is_linear=False,
121
+ is_twice_differentiable=False,
122
+ )
123
+
124
+ objectives = (
125
+ [objective_1, objective_2, objective_3, objective_4, objective_5]
126
+ if five_objective_variant
127
+ else [objective_1, objective_2, objective_3, objective_4]
128
+ )
129
+
130
+ return Problem(
131
+ name="The river pollution problem",
132
+ description="The river pollution problem to maximize return of investments (ROI) and dissolved oxygen (DO).",
133
+ variables=[variable_1, variable_2],
134
+ objectives=objectives,
135
+ )
136
+
137
+
138
+ def river_pollution_problem_discrete(*, five_objective_variant: bool = True) -> Problem:
139
+ """Create a pydantic dataclass representation of the river pollution problem with either five or four variables.
140
+
141
+ The objective functions "DO city" ($f_1$), "DO municipality" ($f_2), and
142
+ "ROI fishery" ($f_3$) and "ROI city" ($f_4$) are to be
143
+ maximized. If the four variant problem is used, the the "BOD deviation" objective
144
+ function ($f_5$) is not present, but if it is, it is to be minimized.
145
+ This version of the problem uses discrete representation of the variables and objectives and does not provide
146
+ the analytical functions for the objectives.
147
+
148
+ Args:
149
+ five_objective_variant (bool, optional): Whether to use to five
150
+ objective function variant of the problem or not. Defaults to True.
151
+
152
+ Returns:
153
+ Problem: the river pollution problem.
154
+
155
+ References:
156
+ Narula, Subhash C., and HRoland Weistroffer. "A flexible method for
157
+ nonlinear multicriteria decision-making problems." IEEE Transactions on
158
+ Systems, Man, and Cybernetics 19.4 (1989): 883-887.
159
+
160
+ Miettinen, Kaisa, and Marko M. Mäkelä. "Interactive method NIMBUS for
161
+ nondifferentiable multiobjective optimization problems." Multicriteria
162
+ Analysis: Proceedings of the XIth International Conference on MCDM, 1-6
163
+ August 1994, Coimbra, Portugal. Berlin, Heidelberg: Springer Berlin
164
+ Heidelberg, 1997.
165
+ """
166
+ filename = "datasets/river_poll_4_objs.csv"
167
+ trueVarNames = {"x_1": "BOD", "x_2": "DO"}
168
+ trueObjNames = {"f1": "DO city", "f2": "DO municipality", "f3": "ROI fishery", "f4": "ROI city"}
169
+ if five_objective_variant:
170
+ filename = "datasets/river_poll_5_objs.csv"
171
+ trueObjNames["f5"] = "BOD deviation"
172
+
173
+ path = Path(__file__).parent.parent.parent.parent / filename
174
+ data = pl.read_csv(path, has_header=True)
175
+
176
+ variables = [
177
+ Variable(
178
+ name=trueVarNames[varName],
179
+ symbol=varName,
180
+ variable_type=VariableTypeEnum.real,
181
+ lowerbound=0.3,
182
+ upperbound=1.0,
183
+ initial_value=0.65,
184
+ )
185
+ for varName in trueVarNames
186
+ ]
187
+ maximize = {"f1": True, "f2": True, "f3": True, "f4": True, "f5": False}
188
+ ideal = {objName: (data[objName].max() if maximize[objName] else data[objName].min()) for objName in trueObjNames}
189
+ nadir = {objName: (data[objName].min() if maximize[objName] else data[objName].max()) for objName in trueObjNames}
190
+ units = {"f1": "mg/L", "f2": "mg/L", "f3": "%", "f4": "%", "f5": "mg/L"}
191
+
192
+ objectives = [
193
+ Objective(
194
+ name=trueObjNames[objName],
195
+ symbol=objName,
196
+ func=None,
197
+ unit=units[objName],
198
+ objective_type=ObjectiveTypeEnum.data_based,
199
+ maximize=maximize[objName],
200
+ ideal=ideal[objName],
201
+ nadir=nadir[objName],
202
+ )
203
+ for objName in trueObjNames
204
+ ]
205
+
206
+ discrete_def = DiscreteRepresentation(
207
+ variable_values=data[list(trueVarNames.keys())].to_dict(),
208
+ objective_values=data[list(trueObjNames.keys())].to_dict(),
209
+ )
210
+
211
+ return Problem(
212
+ name="The river pollution problem (Discrete)",
213
+ description="The river pollution problem to maximize return of investments (ROI) and dissolved oxygen (DO).",
214
+ variables=variables,
215
+ objectives=objectives,
216
+ discrete_representation=discrete_def,
217
+ )
218
+
219
+
220
+ def river_pollution_scenario() -> Problem:
221
+ r"""Defines the scenario-based uncertain variant of the river pollution problem.
222
+
223
+ The river pollution problem considers a river close to a city.
224
+ There are two sources of pollution: industrial pollution from a
225
+ fishery and municipal waste from the city. Two treatment plants
226
+ (in the fishery and the city) are responsible for managing the pollution.
227
+ Pollution is reported in pounds of biochemical oxygen demanding material (BOD),
228
+ and water quality is measured in dissolved oxygen concentration (DO).
229
+
230
+ Cleaning water in the city increases the tax rate, and cleaning in the
231
+ fishery reduces the return on investment. The problem is to improve
232
+ the DO level in the city and at the municipality border (`f1` and `f2`, respectively),
233
+ while, at the same time, maximizing the percent return on investment at the fishery (`f3`)
234
+ and minimizing additions to the city tax (`f4`).
235
+
236
+ Decision variables are:
237
+
238
+ * `x1`: The proportional amount of BOD removed from water after the fishery (treatment plant 1).
239
+ * `x2`: The proportional amount of BOD removed from water after the city (treatment plant 2).
240
+
241
+ The original problem considered specific values for all parameters. However, in this formulation,
242
+ some parameters are deeply uncertain, and only a range of plausible values is known for each.
243
+ These deeply uncertain parameters are as follows:
244
+
245
+ * `α ∈ [3, 4.24]`: Water quality index after the fishery.
246
+ * `β ∈ [2.25, 2.4]`: BOD reduction rate at treatment plant 1 (after the fishery).
247
+ * `δ ∈ [0.075, 0.092]`: BOD reduction rate at treatment plant 2 (after the city).
248
+ * `ξ ∈ [0.067, 0.083]`: Effective rate of BOD reduction at treatment plant 1 after the city.
249
+ * `η ∈ [1.2, 1.50]`: Parameter used to calculate the effective BOD reduction rate at the second treatment plant.
250
+ * `r ∈ [5.1, 12.5]`: Investment return rate.
251
+
252
+ The uncertain version of the river problem is formulated as follows:
253
+
254
+ $$
255
+ \\begin{equation}
256
+ \\begin{array}{rll}
257
+ \\text{maximize} & f_1(\\mathbf{x}) = & \\alpha + \\left(\\log\\left(\\left(\\frac{\\beta}{2} - 1.14\\right)^2\\right) + \\beta^3\\right) x_1 \\\\
258
+ \\text{maximize} & f_2(\\mathbf{x}) = & \\gamma + \\delta x_1 + \\xi x_2 + \\frac{0.01}{\\eta - x_1^2} + \\frac{0.30}{\\eta - x_2^2} \\\\
259
+ \\text{maximize} & f_3(\\mathbf{x}) = & r - \\frac{0.71}{1.09 - x_1^2} \\\\
260
+ \\text{minimize} & f_4(\\mathbf{x}) = & -0.96 + \\frac{0.96}{1.09 - x_2^2} \\\\
261
+ \\text{subject to} & & 0.3 \\leq x_1, x_2 \\leq 1.0.
262
+ \\end{array}
263
+ \\end{equation}
264
+ $$
265
+
266
+ where $\\gamma = \\log\\left(\\frac{\\alpha}{2} - 1\\right) + \\frac{\\alpha}{2} + 1.5$.
267
+
268
+ Returns:
269
+ Problem: the scenario-based river pollution problem.
270
+
271
+ References:
272
+ Narula, Subhash C., and HRoland Weistroffer. "A flexible method for
273
+ nonlinear multicriteria decision-making problems." IEEE Transactions on
274
+ Systems, Man, and Cybernetics 19.4 (1989): 883-887.
275
+
276
+ Miettinen, Kaisa, and Marko M. Mäkelä. "Interactive method NIMBUS for
277
+ nondifferentiable multiobjective optimization problems." Multicriteria
278
+ Analysis: Proceedings of the XIth International Conference on MCDM, 1-6
279
+ August 1994, Coimbra, Portugal. Berlin, Heidelberg: Springer Berlin
280
+ Heidelberg, 1997.
281
+ """
282
+ num_scenarios = 6
283
+ scenario_key_stub = "scenario"
284
+
285
+ # defining scenario parameters
286
+ alpha_values = [4.070, 3.868, 3.620, 3.372, 3.124, 4.116]
287
+ beta_values = [2.270, 2.262, 2.278, 2.254, 2.270, 2.286]
288
+ delta_values = [0.0800, 0.0869, 0.0835, 0.0903, 0.0801, 0.0767]
289
+ xi_values = [0.0750, 0.0782, 0.0750, 0.0814, 0.0686, 0.0718]
290
+ eta_values = [1.39, 1.47, 1.23, 1.35, 1.29, 1.41]
291
+ r_values = [8.21, 10.28, 5.84, 11.76, 7.32, 8.80]
292
+
293
+ # each scenario parameter is defined as its own tensor constant
294
+ alpha_constant = TensorConstant(
295
+ name="Water quality index after fishery", symbol="alpha", shape=[num_scenarios], values=alpha_values
296
+ )
297
+ beta_constant = TensorConstant(
298
+ name="BOD reduction rate at treatment plant 1 (after the fishery)",
299
+ symbol="beta",
300
+ shape=[num_scenarios],
301
+ values=beta_values,
302
+ )
303
+ delta_constant = TensorConstant(
304
+ name="BOD reduction rate at treatment plant 2 (after the city)",
305
+ symbol="delta",
306
+ shape=[num_scenarios],
307
+ values=delta_values,
308
+ )
309
+ xi_constant = TensorConstant(
310
+ name="The effective rate of BOD reduction at treatment plant 1 (after the city)",
311
+ symbol="xi",
312
+ shape=[num_scenarios],
313
+ values=xi_values,
314
+ )
315
+ eta_constant = TensorConstant(
316
+ name="The effective rate of BOD reduction rate at plant 2 (after the fishery)",
317
+ symbol="eta",
318
+ shape=[num_scenarios],
319
+ values=eta_values,
320
+ )
321
+ r_constant = TensorConstant(
322
+ name="Investment return rate",
323
+ symbol="r",
324
+ shape=[num_scenarios],
325
+ values=r_values,
326
+ )
327
+
328
+ constants = [alpha_constant, beta_constant, delta_constant, xi_constant, eta_constant, r_constant]
329
+
330
+ # define variables
331
+ x1 = Variable(
332
+ name="BOD removed after fishery",
333
+ symbol="x_1",
334
+ variable_type=VariableTypeEnum.real,
335
+ lowerbound=0.3,
336
+ upperbound=1.0,
337
+ )
338
+
339
+ x2 = Variable(
340
+ name="BOD removed after city",
341
+ symbol="x_2",
342
+ variable_type=VariableTypeEnum.real,
343
+ lowerbound=0.3,
344
+ upperbound=1.0,
345
+ )
346
+
347
+ variables = [x1, x2]
348
+
349
+ # define objectives for each scenario
350
+ objectives = []
351
+ scenario_keys = []
352
+
353
+ for i in range(num_scenarios):
354
+ scenario_key = f"{scenario_key_stub}_{i+1}"
355
+ scenario_keys.append(scenario_key)
356
+
357
+ gamma_expr = f"Ln(alpha[{i+1}]/2 - 1) + alpha[{i+1}]/2 + 1.5"
358
+
359
+ f1_expr = f"alpha[{i+1}] + (Ln((beta[{i+1}]/2 - 1.14)**2) + beta[{i+1}]**3)*x_1"
360
+ f2_expr = (
361
+ f"{gamma_expr} + delta[{i+1}]*x_1 + xi[{i+1}]*x_2 + 0.01/(eta[{i+1}] - x_1**2) + 0.3/(eta[{i+1}] - x_2**2)"
362
+ )
363
+ f3_expr = f"r[{i+1}] - 0.71/(1.09 - x_1**2)"
364
+
365
+ # f1
366
+ objectives.append(
367
+ Objective(
368
+ name="DO level city",
369
+ symbol=f"f1_{i+1}",
370
+ scenario_keys=[scenario_key],
371
+ func=f1_expr,
372
+ objective_type=ObjectiveTypeEnum.analytical,
373
+ maximize=True,
374
+ is_linear=False,
375
+ is_convex=False,
376
+ is_twice_differentiable=True,
377
+ )
378
+ )
379
+
380
+ # f2
381
+ objectives.append(
382
+ Objective(
383
+ name="DO level fishery",
384
+ symbol=f"f2_{i+1}",
385
+ scenario_keys=[scenario_key],
386
+ func=f2_expr,
387
+ objective_type=ObjectiveTypeEnum.analytical,
388
+ maximize=True,
389
+ is_linear=False,
390
+ is_convex=False,
391
+ is_twice_differentiable=True,
392
+ )
393
+ )
394
+
395
+ # f3
396
+ objectives.append(
397
+ Objective(
398
+ name="Return of investment",
399
+ symbol=f"f3_{i+1}",
400
+ scenario_keys=[scenario_key],
401
+ func=f3_expr,
402
+ objective_type=ObjectiveTypeEnum.analytical,
403
+ maximize=True,
404
+ is_linear=False,
405
+ is_convex=False,
406
+ is_twice_differentiable=True,
407
+ )
408
+ )
409
+
410
+ f4_expr = "-0.96 + 0.96/(1.09 - x_2**2)"
411
+
412
+ # f4, by setting the scenario_key to None, the objective function is assumed to be part of all the scenarios.
413
+ objectives.append(
414
+ Objective(
415
+ name="Addition to city tax",
416
+ symbol="f4",
417
+ scenario_keys=None,
418
+ func=f4_expr,
419
+ objective_type=ObjectiveTypeEnum.analytical,
420
+ maximize=False,
421
+ is_linear=False,
422
+ is_convex=False,
423
+ is_twice_differentiable=True,
424
+ )
425
+ )
426
+
427
+ return Problem(
428
+ name="Scenario-based river pollution problem",
429
+ description="The scenario-based river pollution problem",
430
+ constants=constants,
431
+ variables=variables,
432
+ objectives=objectives,
433
+ scenario_keys=scenario_keys,
434
+ )
@@ -0,0 +1,140 @@
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 rocket_injector_design(original_version=False) -> Problem:
15
+ """The rocekt injector design problem as published in Vaidyanathan, et al. (2003).
16
+
17
+ The original version of the problem has 4 objectives. In Goel et al. (2007), the TW4 objective is dropped
18
+ due to high correlation with one of the other objectives. Hence, the default version of the problem is the
19
+ modified version with 3 objectives.
20
+
21
+ Args:
22
+ original_version (bool): If True, the original version of the problem with 4 objectives is returned.
23
+
24
+ References:
25
+ R. Vaidyanathan, K. Tucker, N. Papila, W. Shyy, CFD-Based Design Optimization For Single Element Rocket
26
+ Injector, in: AIAA Aerospace Sciences Meeting, 2003, pp. 1-21.
27
+
28
+ Goel, T., Vaidyanathan, R., Haftka, R. T., Shyy, W., Queipo, N. V., & Tucker, K. (2007).
29
+ Response surface approximation of Pareto optimal front in multi-objective optimization.
30
+ Computer methods in applied mechanics and engineering, 196(4-6), 879-893.
31
+
32
+ Returns:
33
+ Problem: The rocket injector design problem.
34
+ """
35
+ # Variables
36
+ alpha = Variable(name="alpha", symbol="a", variable_type=VariableTypeEnum.real, lowerbound=0.0, upperbound=1.0)
37
+
38
+ deltaHA = Variable(
39
+ name="deltaHA", symbol="DHA", variable_type=VariableTypeEnum.real, lowerbound=0.0, upperbound=1.0
40
+ )
41
+
42
+ deltaOA = Variable(
43
+ name="deltaOA", symbol="DOA", variable_type=VariableTypeEnum.real, lowerbound=0.0, upperbound=1.0
44
+ )
45
+
46
+ OPTT = Variable(name="OPTT", symbol="OPTT", variable_type=VariableTypeEnum.real, lowerbound=0.0, upperbound=1.0)
47
+
48
+ # Objectives
49
+
50
+ tfmax_eqn = """
51
+ 0.692+ 0.477 * a- 0.687 * DHA- 0.080 * DOA- 0.0650 * OPTT- 0.167 * a * a- 0.0129 * DHA * a
52
+ + 0.0796 * DHA * DHA- 0.0634 * DOA * a- 0.0257 * DOA * DHA+ 0.0877 * DOA * DOA- 0.0521 * OPTT * a
53
+ + 0.00156 * OPTT * DHA+ 0.00198 * OPTT * DOA+ 0.0184 * OPTT * OPTT
54
+ """
55
+
56
+ xccmax_eqn = """
57
+ 0.153- 0.322 * a+ 0.396 * DHA+ 0.424 * DOA+ 0.0226 * OPTT+ 0.175 * a * a
58
+ + 0.0185 * DHA * a- 0.0701 * DHA * DHA- 0.251 * DOA * a+ 0.179 * DOA * DHA+ 0.0150 * DOA * DOA
59
+ + 0.0134 * OPTT * a+ 0.0296 * OPTT * DHA+ 0.0752 * OPTT * DOA+ 0.0192 * OPTT * OPTT
60
+ """
61
+
62
+ ttmax_eqn = """
63
+ 0.370- 0.205 * a+ 0.0307 * DHA+ 0.108 * DOA+ 1.019 * OPTT- 0.135 * a * a+ 0.0141 * DHA * a
64
+ + 0.0998 * DHA * DHA+ 0.208 * DOA * a- 0.0301 * DOA * DHA- 0.226 * DOA * DOA+ 0.353 * OPTT * a
65
+ - 0.0497 * OPTT * DOA- 0.423 * OPTT * OPTT+ 0.202 * DHA * a * a- 0.281 * DOA * a * a
66
+ - 0.342 * DHA * DHA * a- 0.245 * DHA * DHA * DOA+ 0.281 * DOA * DOA * DHA- 0.184 * OPTT * OPTT * a
67
+ - 0.281 * DHA * a * DOA
68
+ """
69
+
70
+ tw4_eqn = """
71
+ 0.758 + 0.358 * a - 0.807 * DHA + 0.0925 * DOA - 0.0468 * OPTT
72
+ - 0.172 * a * a + 0.0106 * DHA * a + 0.0697 * DHA * DHA
73
+ - 0.146 * DOA * a - 0.0416 * DOA * DHA + 0.102 * DOA * DOA
74
+ - 0.0694 * OPTT * a - 0.00503 * OPTT * DHA + 0.0151 * OPTT * DOA
75
+ + 0.0173 * OPTT * OPTT
76
+ """
77
+
78
+ # The ideal and nadir values are estimates. If you get a better estimate, feel free to update them.
79
+ tf_max = Objective(
80
+ name="TF_max",
81
+ symbol="TF_max",
82
+ func=tfmax_eqn,
83
+ maximize=False,
84
+ is_linear=False,
85
+ is_convex=False,
86
+ is_twice_differentiable=True,
87
+ ideal=-0.008907,
88
+ nadir=1.002000,
89
+ )
90
+
91
+ xcc_max = Objective(
92
+ name="Xcc_max",
93
+ symbol="Xcc_max",
94
+ func=xccmax_eqn,
95
+ maximize=False,
96
+ is_linear=False,
97
+ is_convex=False,
98
+ is_twice_differentiable=True,
99
+ ideal=0.004883,
100
+ nadir=1.075655,
101
+ )
102
+
103
+ tt_max = Objective(
104
+ name="TT_max",
105
+ symbol="TT_max",
106
+ func=ttmax_eqn,
107
+ maximize=False,
108
+ is_linear=False,
109
+ is_convex=False,
110
+ is_twice_differentiable=True,
111
+ ideal=-0.419077,
112
+ nadir=1.092842,
113
+ )
114
+
115
+ tw4 = Objective(
116
+ name="TW4",
117
+ symbol="TW4",
118
+ func=tw4_eqn,
119
+ maximize=False,
120
+ is_linear=False,
121
+ is_convex=False,
122
+ is_twice_differentiable=True,
123
+ ideal=-0.013602,
124
+ nadir=0.244688,
125
+ )
126
+
127
+ if original_version: # NOQA:SIM108
128
+ objectives = [tf_max, tw4, tt_max, xcc_max]
129
+ else:
130
+ objectives = [tf_max, tt_max, xcc_max]
131
+
132
+ return Problem(
133
+ name="Rocket Injector Design Problem",
134
+ description=(
135
+ "R. Vaidyanathan, K. Tucker, N. Papila, W. Shyy, CFD-Based Design Optimization For Single Element"
136
+ " Rocket Injector, in: AIAA Aerospace Sciences Meeting, 2003, pp. 1-21."
137
+ ),
138
+ variables=[alpha, deltaHA, deltaOA, OPTT],
139
+ objectives=objectives,
140
+ )