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,945 @@
1
+ from pathlib import Path
2
+
3
+ import polars as pl
4
+
5
+ from desdeo.problem.schema import (
6
+ Constant,
7
+ Constraint,
8
+ ConstraintTypeEnum,
9
+ DiscreteRepresentation,
10
+ Objective,
11
+ ObjectiveTypeEnum,
12
+ Problem,
13
+ TensorConstant,
14
+ TensorVariable,
15
+ Variable,
16
+ VariableTypeEnum,
17
+ )
18
+
19
+ def spanish_sustainability_problem():
20
+ """Implements the Spanish sustainability problem."""
21
+ coefficients_dict = {
22
+ "social_linear": {
23
+ "x_1": -0.0108,
24
+ "x_2": 0.0,
25
+ "x_3": 0.0,
26
+ "x_4": 0.185,
27
+ "x_5": 0.0,
28
+ "x_6": 0.0,
29
+ "x_7": 0.0,
30
+ "x_8": 0.0,
31
+ "x_9": 0.00855,
32
+ "x_10": 0.0,
33
+ "x_11": 0.0,
34
+ },
35
+ "social_quadratic": {
36
+ "x_1": 0.0,
37
+ "x_2": 0.0,
38
+ "x_3": 0.0,
39
+ "x_4": 0.0,
40
+ "x_5": 0.0,
41
+ "x_6": 0.0,
42
+ "x_7": 0.0,
43
+ "x_8": 0.0,
44
+ "x_9": 0.0,
45
+ "x_10": 0.0,
46
+ "x_11": 0.0,
47
+ },
48
+ "social_cubic": {
49
+ "x_1": 0.0,
50
+ "x_2": 9.79e-07,
51
+ "x_3": 0.0,
52
+ "x_4": 0.0,
53
+ "x_5": 0.0,
54
+ "x_6": 0.0,
55
+ "x_7": 0.0,
56
+ "x_8": 0.0,
57
+ "x_9": 0.0,
58
+ "x_10": 0.0,
59
+ "x_11": 0.0,
60
+ },
61
+ "social_log": {
62
+ "x_1": 0.0,
63
+ "x_2": 0.0,
64
+ "x_3": 0.0,
65
+ "x_4": 0.0,
66
+ "x_5": 0.0,
67
+ "x_6": 0.0,
68
+ "x_7": 0.0,
69
+ "x_8": 0.0,
70
+ "x_9": 0.0,
71
+ "x_10": 0.0,
72
+ "x_11": 0.0,
73
+ },
74
+ "economical_linear": {
75
+ "x_1": 0.0,
76
+ "x_2": 0.0,
77
+ "x_3": 0.0,
78
+ "x_4": 0.38,
79
+ "x_5": 0.0281,
80
+ "x_6": 0.0,
81
+ "x_7": 0.00826,
82
+ "x_8": 0.0,
83
+ "x_9": 0.0,
84
+ "x_10": 0.0,
85
+ "x_11": 0.0,
86
+ },
87
+ "economical_quadratic": {
88
+ "x_1": -0.000316,
89
+ "x_2": 3.18e-05,
90
+ "x_3": 0.0,
91
+ "x_4": 0.0,
92
+ "x_5": 0.0,
93
+ "x_6": 0.0,
94
+ "x_7": 0.0,
95
+ "x_8": 0.000662,
96
+ "x_9": 0.0,
97
+ "x_10": 1.81e-05,
98
+ "x_11": 0.0,
99
+ },
100
+ "economical_cubic": {
101
+ "x_1": 0.0,
102
+ "x_2": 0.0,
103
+ "x_3": 0.0,
104
+ "x_4": 0.0,
105
+ "x_5": 0.0,
106
+ "x_6": 0.0,
107
+ "x_7": 0.0,
108
+ "x_8": 0.0,
109
+ "x_9": 0.0,
110
+ "x_10": 0.0,
111
+ "x_11": 0.0,
112
+ },
113
+ "economical_log": {
114
+ "x_1": 0.0,
115
+ "x_2": 0.0,
116
+ "x_3": 0.121,
117
+ "x_4": 0.0,
118
+ "x_5": 0.0,
119
+ "x_6": 0.0,
120
+ "x_7": 0.0,
121
+ "x_8": 0.0,
122
+ "x_9": 0.0,
123
+ "x_10": 0.0,
124
+ "x_11": -0.262,
125
+ },
126
+ "enviro_linear": {
127
+ "x_1": 0.0,
128
+ "x_2": 0.0,
129
+ "x_3": 0.0,
130
+ "x_4": 0.0,
131
+ "x_5": 0.0,
132
+ "x_6": 0.0,
133
+ "x_7": 0.0,
134
+ "x_8": 0.0,
135
+ "x_9": 0.0,
136
+ "x_10": -0.00122,
137
+ "x_11": 0.0,
138
+ },
139
+ "enviro_quadratic": {
140
+ "x_1": 0.0,
141
+ "x_2": 0.0,
142
+ "x_3": 0.0,
143
+ "x_4": 0.0,
144
+ "x_5": 0.0,
145
+ "x_6": 0.0,
146
+ "x_7": -0.000245,
147
+ "x_8": 0.0,
148
+ "x_9": 0.0,
149
+ "x_10": 0.0,
150
+ "x_11": 1.2e-05,
151
+ },
152
+ "enviro_cubic": {
153
+ "x_1": 0.0,
154
+ "x_2": 0.0,
155
+ "x_3": 0.0,
156
+ "x_4": 0.0,
157
+ "x_5": 0.0,
158
+ "x_6": -2.37e-06,
159
+ "x_7": 0.0,
160
+ "x_8": 0.0,
161
+ "x_9": 0.0,
162
+ "x_10": 0.0,
163
+ "x_11": 0.0,
164
+ },
165
+ "enviro_log": {
166
+ "x_1": 0.0,
167
+ "x_2": 0.0,
168
+ "x_3": 0.0,
169
+ "x_4": 0.0,
170
+ "x_5": -0.329,
171
+ "x_6": 0.0,
172
+ "x_7": 0.0,
173
+ "x_8": 0.0,
174
+ "x_9": 0.0,
175
+ "x_10": 0.0,
176
+ "x_11": 0.0,
177
+ },
178
+ "lower_bounds": {
179
+ "x_1": 1,
180
+ "x_2": 60,
181
+ "x_3": 1,
182
+ "x_4": 1,
183
+ "x_5": 1,
184
+ "x_6": 1,
185
+ "x_7": 1,
186
+ "x_8": 1,
187
+ "x_9": 40,
188
+ "x_10": 75,
189
+ "x_11": 80,
190
+ },
191
+ "upper_bounds": {
192
+ "x_1": 40,
193
+ "x_2": 90,
194
+ "x_3": 25,
195
+ "x_4": 3,
196
+ "x_5": 40,
197
+ "x_6": 15,
198
+ "x_7": 30,
199
+ "x_8": 25,
200
+ "x_9": 70,
201
+ "x_10": 105,
202
+ "x_11": 120,
203
+ },
204
+ }
205
+
206
+ social_cte_value = -0.46
207
+ economical_cte_value = 0.12
208
+ enviro_cte_value = 2.92
209
+
210
+ coefficients = (
211
+ pl.DataFrame(coefficients_dict)
212
+ .transpose(include_header=True, column_names=["coefficients"])
213
+ .unnest("coefficients")
214
+ )
215
+
216
+ variable_names = [f"x_{i}" for i in range(1, 12)]
217
+ n_variables = len(variable_names)
218
+
219
+ # Define constants
220
+ # For the social indicator
221
+ social_linear = TensorConstant(
222
+ name="Linear coefficients for the social indicator",
223
+ symbol="beta_social",
224
+ shape=[n_variables],
225
+ values=list(coefficients.filter(pl.col("column") == "social_linear").row(0)[1:]),
226
+ )
227
+
228
+ social_quadratic = TensorConstant(
229
+ name="Quadratic coefficients for the social indicator",
230
+ symbol="gamma_social",
231
+ shape=[n_variables],
232
+ values=list(coefficients.filter(pl.col("column") == "social_quadratic").row(0)[1:]),
233
+ )
234
+
235
+ social_cubic = TensorConstant(
236
+ name="Cubic coefficients for the social indicator",
237
+ symbol="delta_social",
238
+ shape=[n_variables],
239
+ values=list(coefficients.filter(pl.col("column") == "social_cubic").row(0)[1:]),
240
+ )
241
+
242
+ social_log = TensorConstant(
243
+ name="Logarithmic coefficients for the social indicator",
244
+ symbol="omega_social",
245
+ shape=[n_variables],
246
+ values=list(coefficients.filter(pl.col("column") == "social_log").row(0)[1:]),
247
+ )
248
+
249
+ social_c = Constant(
250
+ name="Constant coefficient for the social indicator", symbol="cte_social", value=social_cte_value
251
+ )
252
+
253
+ # For the economical indicator
254
+ economical_linear = TensorConstant(
255
+ name="Linear coefficients for the economical indicator",
256
+ symbol="beta_economical",
257
+ shape=[n_variables],
258
+ values=list(coefficients.filter(pl.col("column") == "economical_linear").row(0)[1:]),
259
+ )
260
+
261
+ economical_quadratic = TensorConstant(
262
+ name="Quadratic coefficients for the economical indicator",
263
+ symbol="gamma_economical",
264
+ shape=[n_variables],
265
+ values=list(coefficients.filter(pl.col("column") == "economical_quadratic").row(0)[1:]),
266
+ )
267
+
268
+ economical_cubic = TensorConstant(
269
+ name="Cubic coefficients for the economical indicator",
270
+ symbol="delta_economical",
271
+ shape=[n_variables],
272
+ values=list(coefficients.filter(pl.col("column") == "economical_cubic").row(0)[1:]),
273
+ )
274
+
275
+ economical_log = TensorConstant(
276
+ name="Logarithmic coefficients for the economical indicator",
277
+ symbol="omega_economical",
278
+ shape=[n_variables],
279
+ values=list(coefficients.filter(pl.col("column") == "economical_log").row(0)[1:]),
280
+ )
281
+
282
+ economical_c = Constant(
283
+ name="Constant coefficient for the economical indicator", symbol="cte_economical", value=economical_cte_value
284
+ )
285
+
286
+ # For the environmental indicator
287
+ enviro_linear = TensorConstant(
288
+ name="Linear coefficients for the environmental indicator",
289
+ symbol="beta_enviro",
290
+ shape=[n_variables],
291
+ values=list(coefficients.filter(pl.col("column") == "enviro_linear").row(0)[1:]),
292
+ )
293
+
294
+ enviro_quadratic = TensorConstant(
295
+ name="Quadratic coefficients for the environmental indicator",
296
+ symbol="gamma_enviro",
297
+ shape=[n_variables],
298
+ values=list(coefficients.filter(pl.col("column") == "enviro_quadratic").row(0)[1:]),
299
+ )
300
+
301
+ enviro_cubic = TensorConstant(
302
+ name="Cubic coefficients for the environmental indicator",
303
+ symbol="delta_enviro",
304
+ shape=[n_variables],
305
+ values=list(coefficients.filter(pl.col("column") == "enviro_cubic").row(0)[1:]),
306
+ )
307
+
308
+ enviro_log = TensorConstant(
309
+ name="Logarithmic coefficients for the environmental indicator",
310
+ symbol="omega_enviro",
311
+ shape=[n_variables],
312
+ values=list(coefficients.filter(pl.col("column") == "enviro_log").row(0)[1:]),
313
+ )
314
+
315
+ enviro_c = Constant(
316
+ name="Constant coefficient for the environmental indicator", symbol="cte_enviro", value=enviro_cte_value
317
+ )
318
+
319
+ constants = [
320
+ social_linear,
321
+ social_quadratic,
322
+ social_cubic,
323
+ social_log,
324
+ social_c,
325
+ economical_linear,
326
+ economical_quadratic,
327
+ economical_cubic,
328
+ economical_log,
329
+ economical_c,
330
+ enviro_linear,
331
+ enviro_quadratic,
332
+ enviro_cubic,
333
+ enviro_log,
334
+ enviro_c,
335
+ ]
336
+
337
+ # Define variables
338
+ x = TensorVariable(
339
+ name="Variables 'x_1' through 'x_11' defined as a vector.",
340
+ symbol="X",
341
+ variable_type=VariableTypeEnum.real,
342
+ shape=[n_variables],
343
+ lowerbounds=list(coefficients.filter(pl.col("column") == "lower_bounds").row(0)[1:]),
344
+ upperbounds=list(coefficients.filter(pl.col("column") == "upper_bounds").row(0)[1:]),
345
+ initial_values=1.0,
346
+ )
347
+
348
+ variables = [x]
349
+
350
+ # Define objective functions
351
+ # Social
352
+ f1_expr = "cte_social + X @ beta_social + (X**2) @ gamma_social + (X**3) @ delta_social + Ln(X) @ omega_social"
353
+
354
+ f1 = Objective(
355
+ name="Societal indicator",
356
+ symbol="f1",
357
+ func=f1_expr,
358
+ objective_type=ObjectiveTypeEnum.analytical,
359
+ ideal=1.17,
360
+ nadir=1.15,
361
+ maximize=True,
362
+ is_linear=False,
363
+ is_convex=False,
364
+ is_twice_differentiable=True,
365
+ )
366
+
367
+ # economical
368
+ f2_expr = (
369
+ "cte_economical + beta_economical @ X + gamma_economical @ (X**2) + delta_economical @ (X**3) "
370
+ "+ omega_economical @ Ln(X)"
371
+ )
372
+
373
+ f2 = Objective(
374
+ name="economical indicator",
375
+ symbol="f2",
376
+ func=f2_expr,
377
+ objective_type=ObjectiveTypeEnum.analytical,
378
+ ideal=1.98,
379
+ nadir=0.63,
380
+ maximize=True,
381
+ is_linear=False,
382
+ is_convex=False,
383
+ is_twice_differentiable=True,
384
+ )
385
+
386
+ # Environmental
387
+ f3_expr = "cte_enviro + beta_enviro @ X + gamma_enviro @ (X**2) + delta_enviro @ (X**3) " "+ omega_enviro @ Ln(X)"
388
+
389
+ f3 = Objective(
390
+ name="Environmental indicator",
391
+ symbol="f3",
392
+ func=f3_expr,
393
+ objective_type=ObjectiveTypeEnum.analytical,
394
+ ideal=2.93,
395
+ nadir=1.52,
396
+ maximize=True,
397
+ is_linear=False,
398
+ is_convex=False,
399
+ is_twice_differentiable=True,
400
+ )
401
+
402
+ objectives = [f1, f2, f3]
403
+
404
+ # Define constraints
405
+
406
+ con_1_expr = "(18844.09 * X[3] + 31749.1) - X[9]**3"
407
+ con_1 = Constraint(
408
+ name="Independent X[3], dependent X[9]. Less than part.",
409
+ symbol="con_1",
410
+ func=con_1_expr,
411
+ cons_type=ConstraintTypeEnum.LTE,
412
+ is_linear=False,
413
+ is_convex=False,
414
+ is_twice_differentiable=True,
415
+ )
416
+
417
+ con_2_expr = "X[9]**3 - (25429.65 * X[3] + 114818.5)"
418
+ con_2 = Constraint(
419
+ name="Independent X[3], dependent X[9]. More than part.",
420
+ symbol="con_2",
421
+ func=con_2_expr,
422
+ cons_type=ConstraintTypeEnum.LTE,
423
+ is_linear=False,
424
+ is_convex=False,
425
+ is_twice_differentiable=True,
426
+ )
427
+
428
+ con_3_expr = "(0.0696724 * X[3] + 0.4026487) - X[4]"
429
+ con_3 = Constraint(
430
+ name="Independent X[3], dependent X[4]. Less than part.",
431
+ symbol="con_3",
432
+ func=con_3_expr,
433
+ cons_type=ConstraintTypeEnum.LTE,
434
+ is_linear=True,
435
+ is_convex=True,
436
+ is_twice_differentiable=True,
437
+ )
438
+
439
+ con_4_expr = "X[4] - (0.1042275 * X[3] + 0.8385217)"
440
+ con_4 = Constraint(
441
+ name="Independent X[3], dependent X[4]. More than part.",
442
+ symbol="con_4",
443
+ func=con_4_expr,
444
+ cons_type=ConstraintTypeEnum.LTE,
445
+ is_linear=True,
446
+ is_convex=True,
447
+ is_twice_differentiable=True,
448
+ )
449
+
450
+ con_5_expr = "(2.90e-06 * X[9]**3 + 0.2561155) - X[4]"
451
+ con_5 = Constraint(
452
+ name="Independent X[9]^3, dependent X[4]. Less than part.",
453
+ symbol="con_5",
454
+ func=con_5_expr,
455
+ cons_type=ConstraintTypeEnum.LTE,
456
+ is_linear=False,
457
+ is_convex=False,
458
+ is_twice_differentiable=True,
459
+ )
460
+
461
+ con_6_expr = "X[4] - (4.07e-06 * X[9]**3 + 0.6763224)"
462
+ con_6 = Constraint(
463
+ name="Independent X[9]^3, dependent X[4]. More than part.",
464
+ symbol="con_6",
465
+ func=con_6_expr,
466
+ cons_type=ConstraintTypeEnum.LTE,
467
+ is_linear=False,
468
+ is_convex=False,
469
+ is_twice_differentiable=True,
470
+ )
471
+
472
+ con_7_expr = "(-0.0121761 * X[6] + 4.272166) - Ln(X[9])"
473
+ con_7 = Constraint(
474
+ name="Independent X[6], dependent Ln(X[9]). Less than part.",
475
+ symbol="con_7",
476
+ func=con_7_expr,
477
+ cons_type=ConstraintTypeEnum.LTE,
478
+ is_linear=False,
479
+ is_convex=False,
480
+ is_twice_differentiable=True,
481
+ )
482
+
483
+ con_8_expr = "Ln(X[9]) - (-0.0078968 * X[6] + 4.387051)"
484
+ con_8 = Constraint(
485
+ name="Independent X[6], dependent Ln(X[9]). More than part.",
486
+ symbol="con_8",
487
+ func=con_8_expr,
488
+ cons_type=ConstraintTypeEnum.LTE,
489
+ is_linear=False,
490
+ is_convex=False,
491
+ is_twice_differentiable=True,
492
+ )
493
+
494
+ con_9_expr = "(-0.6514348 * Ln(X[1]) + 5.368645) - Ln(X[9])"
495
+ con_9 = Constraint(
496
+ name="Independent Ln(X[1]), dependent Ln(X[9]). Less than part.",
497
+ symbol="con_9",
498
+ func=con_9_expr,
499
+ cons_type=ConstraintTypeEnum.LTE,
500
+ is_linear=False,
501
+ is_convex=False,
502
+ is_twice_differentiable=True,
503
+ )
504
+
505
+ con_10_expr = "Ln(X[9]) - (-0.3965489 * Ln(X[1]) + 6.174052)"
506
+ con_10 = Constraint(
507
+ name="Independent Ln(X[1]), dependent Ln(X[9]). More than part.",
508
+ symbol="con_10",
509
+ func=con_10_expr,
510
+ cons_type=ConstraintTypeEnum.LTE,
511
+ is_linear=False,
512
+ is_convex=False,
513
+ is_twice_differentiable=True,
514
+ )
515
+
516
+ con_11_expr = "(-1.660054 * Ln(X[1]) + 3.524567) - Ln(X[4])"
517
+ con_11 = Constraint(
518
+ name="Independent Ln(X[1]), dependent Ln(X[4]). Less than part.",
519
+ symbol="con_11",
520
+ func=con_11_expr,
521
+ cons_type=ConstraintTypeEnum.LTE,
522
+ is_linear=False,
523
+ is_convex=False,
524
+ is_twice_differentiable=True,
525
+ )
526
+
527
+ con_12_expr = "Ln(X[4]) - (-1.045873 * Ln(X[1]) + 5.4653)"
528
+ con_12 = Constraint(
529
+ name="Independent Ln(X[1]), dependent Ln(X[4]). More than part.",
530
+ symbol="con_12",
531
+ func=con_12_expr,
532
+ cons_type=ConstraintTypeEnum.LTE,
533
+ is_linear=False,
534
+ is_convex=False,
535
+ is_twice_differentiable=True,
536
+ )
537
+
538
+ con_13_expr = "(54.36616 * X[1] - 1525.248) - X[6]**2"
539
+ con_13 = Constraint(
540
+ name="Independent X[1], dependent X[6]^2. Less than part.",
541
+ symbol="con_13",
542
+ func=con_13_expr,
543
+ cons_type=ConstraintTypeEnum.LTE,
544
+ is_linear=False,
545
+ is_convex=False,
546
+ is_twice_differentiable=True,
547
+ )
548
+
549
+ con_14_expr = "X[6]**2 - (90.89275 * X[1] - 581.0572)"
550
+ con_14 = Constraint(
551
+ name="Independent X[1], dependent X[6]^2. More than part.",
552
+ symbol="con_14",
553
+ func=con_14_expr,
554
+ cons_type=ConstraintTypeEnum.LTE,
555
+ is_linear=False,
556
+ is_convex=False,
557
+ is_twice_differentiable=True,
558
+ )
559
+
560
+ con_15_expr = "(0.5171291 * X[1]**3 + 4384.214) - X[7]**3"
561
+ con_15 = Constraint(
562
+ name="Independent X[1]^3, dependent X[7]^3. Less than part.",
563
+ symbol="con_15",
564
+ func=con_15_expr,
565
+ cons_type=ConstraintTypeEnum.LTE,
566
+ is_linear=False,
567
+ is_convex=False,
568
+ is_twice_differentiable=True,
569
+ )
570
+
571
+ con_16_expr = "X[7]**3 - (0.7551735 * X[1]**3 + 13106.71)"
572
+ con_16 = Constraint(
573
+ name="Independent X[1]^3, dependent X[7]^3. More than part.",
574
+ symbol="con_16",
575
+ func=con_16_expr,
576
+ cons_type=ConstraintTypeEnum.LTE,
577
+ is_linear=False,
578
+ is_convex=False,
579
+ is_twice_differentiable=True,
580
+ )
581
+
582
+ con_17_expr = "(-9.537996 * Ln(X[3]) + 36.99891) - X[7]"
583
+ con_17 = Constraint(
584
+ name="Independent Ln(X[3]), dependent X[7]. Less than part.",
585
+ symbol="con_17",
586
+ func=con_17_expr,
587
+ cons_type=ConstraintTypeEnum.LTE,
588
+ is_linear=False,
589
+ is_convex=False,
590
+ is_twice_differentiable=True,
591
+ )
592
+
593
+ con_18_expr = "X[7] - (-5.908175 * Ln(X[3]) + 44.97534)"
594
+ con_18 = Constraint(
595
+ name="Independent Ln(X[3]), dependent X[7]. More than part.",
596
+ symbol="con_18",
597
+ func=con_18_expr,
598
+ cons_type=ConstraintTypeEnum.LTE,
599
+ is_linear=False,
600
+ is_convex=False,
601
+ is_twice_differentiable=True,
602
+ )
603
+
604
+ con_19_expr = "(-1.233805 * Ln(X[9]) + 6.303354) - Ln(X[7])"
605
+ con_19 = Constraint(
606
+ name="Independent Ln(X[9]), dependent Ln(X[7]). Less than part.",
607
+ symbol="con_19",
608
+ func=con_19_expr,
609
+ cons_type=ConstraintTypeEnum.LTE,
610
+ is_linear=False,
611
+ is_convex=False,
612
+ is_twice_differentiable=True,
613
+ )
614
+
615
+ con_20_expr = "Ln(X[7]) - (-0.7622909 * Ln(X[9]) + 8.251018)"
616
+ con_20 = Constraint(
617
+ name="Independent Ln(X[9]), dependent Ln(X[7]). More than part.",
618
+ symbol="con_20",
619
+ func=con_20_expr,
620
+ cons_type=ConstraintTypeEnum.LTE,
621
+ is_linear=False,
622
+ is_convex=False,
623
+ is_twice_differentiable=True,
624
+ )
625
+
626
+ con_21_expr = "(0.0701477 * X[10] + 4.270586) - X[8]"
627
+ con_21 = Constraint(
628
+ name="Independent X[10], dependent X[8]. Less than part.",
629
+ symbol="con_21",
630
+ func=con_21_expr,
631
+ cons_type=ConstraintTypeEnum.LTE,
632
+ is_linear=True,
633
+ is_convex=True,
634
+ is_twice_differentiable=True,
635
+ )
636
+
637
+ con_22_expr = "X[8] - (0.1216334 * X[10] + 6.975359)"
638
+ con_22 = Constraint(
639
+ name="Independent X[10], dependent X[8]. More than part.",
640
+ symbol="con_22",
641
+ func=con_22_expr,
642
+ cons_type=ConstraintTypeEnum.LTE,
643
+ is_linear=True,
644
+ is_convex=True,
645
+ is_twice_differentiable=True,
646
+ )
647
+
648
+ con_23_expr = "(-11.7387 * Ln(X[4]) + 25.75422) - X[7]"
649
+ con_23 = Constraint(
650
+ name="Independent Ln(X[4]), dependent X[7]. Less than part.",
651
+ symbol="con_23",
652
+ func=con_23_expr,
653
+ cons_type=ConstraintTypeEnum.LTE,
654
+ is_linear=False,
655
+ is_convex=False,
656
+ is_twice_differentiable=True,
657
+ )
658
+
659
+ con_24_expr = "X[7] - (-6.886529 * Ln(X[4]) + 28.89969)"
660
+ con_24 = Constraint(
661
+ name="Independent Ln(X[4]), dependent X[7]. More than part.",
662
+ symbol="con_24",
663
+ func=con_24_expr,
664
+ cons_type=ConstraintTypeEnum.LTE,
665
+ is_linear=False,
666
+ is_convex=False,
667
+ is_twice_differentiable=True,
668
+ )
669
+
670
+ con_25_expr = "(-1217.427 * Ln(X[4]) + 773.2538) - X[6]**2"
671
+ con_25 = Constraint(
672
+ name="Independent Ln(X[4]), dependent X[6]^2. Less than part.",
673
+ symbol="con_25",
674
+ func=con_25_expr,
675
+ cons_type=ConstraintTypeEnum.LTE,
676
+ is_linear=False,
677
+ is_convex=False,
678
+ is_twice_differentiable=True,
679
+ )
680
+
681
+ con_26_expr = "X[6]**2 - (-677.1691 * Ln(X[4]) + 1123.481)"
682
+ con_26 = Constraint(
683
+ name="Independent Ln(X[4]), dependent X[6]^2. More than part.",
684
+ symbol="con_26",
685
+ func=con_26_expr,
686
+ cons_type=ConstraintTypeEnum.LTE,
687
+ is_linear=False,
688
+ is_convex=False,
689
+ is_twice_differentiable=True,
690
+ )
691
+
692
+ con_27_expr = "(-0.0793273 * X[1] + 3.300731) - Ln(X[3])"
693
+ con_27 = Constraint(
694
+ name="Independent X[1], dependent Ln(X[3]). Less than part.",
695
+ symbol="con_27",
696
+ func=con_27_expr,
697
+ cons_type=ConstraintTypeEnum.LTE,
698
+ is_linear=False,
699
+ is_convex=False,
700
+ is_twice_differentiable=True,
701
+ )
702
+
703
+ con_28_expr = "Ln(X[3]) - (-0.0516687 * X[1] + 4.015687)"
704
+ con_28 = Constraint(
705
+ name="Independent X[1], dependent Ln(X[3]). More than part.",
706
+ symbol="con_28",
707
+ func=con_28_expr,
708
+ cons_type=ConstraintTypeEnum.LTE,
709
+ is_linear=False,
710
+ is_convex=False,
711
+ is_twice_differentiable=True,
712
+ )
713
+
714
+ con_29_expr = "(-6.32e-06 * X[2]**3 + 3.694027) - Ln(X[6])"
715
+ con_29 = Constraint(
716
+ name="Independent X[2]^3, dependent Ln(X[6]). Less than part.",
717
+ symbol="con_29",
718
+ func=con_29_expr,
719
+ cons_type=ConstraintTypeEnum.LTE,
720
+ is_linear=False,
721
+ is_convex=False,
722
+ is_twice_differentiable=True,
723
+ )
724
+
725
+ con_30_expr = "Ln(X[6]) - (-3.72e-06 * X[2]**3 + 4.566568)"
726
+ con_30 = Constraint(
727
+ name="Independent X[2]^3, dependent Ln(X[6]). More than part.",
728
+ symbol="con_30",
729
+ func=con_30_expr,
730
+ cons_type=ConstraintTypeEnum.LTE,
731
+ is_linear=False,
732
+ is_convex=False,
733
+ is_twice_differentiable=True,
734
+ )
735
+
736
+ con_31_expr = "(-19.18876 * Ln(X[3]) + 44.91148) - X[6]"
737
+ con_31 = Constraint(
738
+ name="Independent Ln(X[3]), dependent X[6]. Less than part.",
739
+ symbol="con_31",
740
+ func=con_31_expr,
741
+ cons_type=ConstraintTypeEnum.LTE,
742
+ is_linear=False,
743
+ is_convex=False,
744
+ is_twice_differentiable=True,
745
+ )
746
+
747
+ con_32_expr = "X[6] - (-12.08424 * Ln(X[3]) + 60.52347)"
748
+ con_32 = Constraint(
749
+ name="Independent Ln(X[3]), dependent X[6]. More than part.",
750
+ symbol="con_32",
751
+ func=con_32_expr,
752
+ cons_type=ConstraintTypeEnum.LTE,
753
+ is_linear=False,
754
+ is_convex=False,
755
+ is_twice_differentiable=True,
756
+ )
757
+
758
+ con_33_expr = "(0.6393434 * Ln(X[4]) + 1.433712) - Ln(X[8])"
759
+ con_33 = Constraint(
760
+ name="Independent Ln(X[4]), dependent Ln(X[8]). Less than part.",
761
+ symbol="con_33",
762
+ func=con_33_expr,
763
+ cons_type=ConstraintTypeEnum.LTE,
764
+ is_linear=False,
765
+ is_convex=False,
766
+ is_twice_differentiable=True,
767
+ )
768
+
769
+ con_34_expr = "Ln(X[8]) - (1.1418 * Ln(X[4]) + 1.759434)"
770
+ con_34 = Constraint(
771
+ name="Independent Ln(X[4]), dependent Ln(X[8]). More than part.",
772
+ symbol="con_34",
773
+ func=con_34_expr,
774
+ cons_type=ConstraintTypeEnum.LTE,
775
+ is_linear=False,
776
+ is_convex=False,
777
+ is_twice_differentiable=True,
778
+ )
779
+
780
+ con_f1_1_expr = "-1.0*f1"
781
+ con_f1_1 = Constraint(
782
+ name="f1 greater than zero",
783
+ symbol="con_f1_1",
784
+ func=con_f1_1_expr,
785
+ cons_type=ConstraintTypeEnum.LTE,
786
+ is_linear=False,
787
+ is_convex=False,
788
+ is_twice_differentiable=True,
789
+ )
790
+
791
+ con_f1_2_expr = "f1 - 4.0"
792
+ con_f1_2 = Constraint(
793
+ name="f1 less than four",
794
+ symbol="con_f1_2",
795
+ func=con_f1_2_expr,
796
+ cons_type=ConstraintTypeEnum.LTE,
797
+ is_linear=False,
798
+ is_convex=False,
799
+ is_twice_differentiable=True,
800
+ )
801
+
802
+ con_f2_1_expr = "-1.0*f2"
803
+ con_f2_1 = Constraint(
804
+ name="f2 greater than zero",
805
+ symbol="con_f2_1",
806
+ func=con_f2_1_expr,
807
+ cons_type=ConstraintTypeEnum.LTE,
808
+ is_linear=False,
809
+ is_convex=False,
810
+ is_twice_differentiable=True,
811
+ )
812
+
813
+ con_f2_2_expr = "f2 - 4.0"
814
+ con_f2_2 = Constraint(
815
+ name="f2 less than four",
816
+ symbol="con_f2_2",
817
+ func=con_f2_2_expr,
818
+ cons_type=ConstraintTypeEnum.LTE,
819
+ is_linear=False,
820
+ is_convex=False,
821
+ is_twice_differentiable=True,
822
+ )
823
+
824
+ con_f3_1_expr = "-1.0*f3"
825
+ con_f3_1 = Constraint(
826
+ name="f3 greater than zero",
827
+ symbol="con_f3_1",
828
+ func=con_f3_1_expr,
829
+ cons_type=ConstraintTypeEnum.LTE,
830
+ is_linear=False,
831
+ is_convex=False,
832
+ is_twice_differentiable=True,
833
+ )
834
+
835
+ con_f3_2_expr = "f3 - 4.0"
836
+ con_f3_2 = Constraint(
837
+ name="f3 less than four",
838
+ symbol="con_f3_2",
839
+ func=con_f3_2_expr,
840
+ cons_type=ConstraintTypeEnum.LTE,
841
+ is_linear=False,
842
+ is_convex=False,
843
+ is_twice_differentiable=True,
844
+ )
845
+
846
+ constraints = [
847
+ con_1,
848
+ con_2,
849
+ con_3,
850
+ con_4,
851
+ con_5,
852
+ con_6,
853
+ con_7,
854
+ con_8,
855
+ con_9,
856
+ con_10,
857
+ con_11,
858
+ con_12,
859
+ con_13,
860
+ con_14,
861
+ con_15,
862
+ con_16,
863
+ con_17,
864
+ con_18,
865
+ con_19,
866
+ con_20,
867
+ con_21,
868
+ con_22,
869
+ con_23,
870
+ con_24,
871
+ con_25,
872
+ con_26,
873
+ con_27,
874
+ con_28,
875
+ con_29,
876
+ con_30,
877
+ con_31,
878
+ con_32,
879
+ con_33,
880
+ con_34,
881
+ con_f1_1,
882
+ con_f1_2,
883
+ con_f2_1,
884
+ con_f2_2,
885
+ con_f3_1,
886
+ con_f3_2,
887
+ ]
888
+
889
+ return Problem(
890
+ name="Spanish sustainability problem.",
891
+ description="Defines a sustainability problem with three indicators: societal, economical, and environmental.",
892
+ constants=constants,
893
+ variables=variables,
894
+ objectives=objectives,
895
+ constraints=constraints,
896
+ )
897
+
898
+
899
+ def spanish_sustainability_problem_discrete():
900
+ """Implements the Spanish sustainability problem using Pareto front representation."""
901
+ filename = "datasets/sustainability_spanish.csv"
902
+ varnames = [f"x{i}" for i in range(1, 12)]
903
+ objNames = {"f1": "social", "f2": "economic", "f3": "environmental"}
904
+
905
+ path = Path(__file__).parent.parent.parent.parent / filename
906
+ data = pl.read_csv(path, has_header=True)
907
+
908
+ data = data.rename({"social": "f1", "economic": "f2", "environmental": "f3"})
909
+
910
+ variables = [
911
+ Variable(
912
+ name=varname,
913
+ symbol=varname,
914
+ variable_type=VariableTypeEnum.real,
915
+ lowerbound=data[varname].min(),
916
+ upperbound=data[varname].max(),
917
+ initial_value=data[varname].mean(),
918
+ )
919
+ for varname in varnames
920
+ ]
921
+
922
+ objectives = [
923
+ Objective(
924
+ name=objNames[objname],
925
+ symbol=objname,
926
+ objective_type=ObjectiveTypeEnum.data_based,
927
+ ideal=data[objname].max(),
928
+ nadir=data[objname].min(),
929
+ maximize=True,
930
+ )
931
+ for objname in objNames
932
+ ]
933
+
934
+ discrete_def = DiscreteRepresentation(
935
+ variable_values=data[varnames].to_dict(),
936
+ objective_values=data[[obj.symbol for obj in objectives]].to_dict(),
937
+ )
938
+
939
+ return Problem(
940
+ name="Spanish sustainability problem (Discrete)",
941
+ description="Defines a sustainability problem with three indicators: social, ecological, and environmental.",
942
+ variables=variables,
943
+ objectives=objectives,
944
+ discrete_representation=discrete_def,
945
+ )