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,120 @@
1
+ """Imports available form the desdeo-tools package."""
2
+
3
+ __all__ = [
4
+ "BaseSolver",
5
+ "BonminOptions",
6
+ "GurobipySolver",
7
+ "IpoptOptions",
8
+ "NevergradGenericOptions",
9
+ "NevergradGenericSolver",
10
+ "PersistentGurobipySolver",
11
+ "ProximalSolver",
12
+ "PyomoBonminSolver",
13
+ "PyomoCBCSolver",
14
+ "PyomoGurobiSolver",
15
+ "PyomoIpoptSolver",
16
+ "ScalarizationError",
17
+ "ScipyDeSolver",
18
+ "ScipyMinimizeSolver",
19
+ "SolverOptions",
20
+ "SolverResults",
21
+ "add_asf_diff",
22
+ "add_asf_generic_diff",
23
+ "add_asf_generic_nondiff",
24
+ "add_asf_nondiff",
25
+ "add_epsilon_constraints",
26
+ "add_group_asf",
27
+ "add_group_asf_agg",
28
+ "add_group_asf_agg_diff",
29
+ "add_group_asf_diff",
30
+ "add_group_guess",
31
+ "add_group_guess_agg",
32
+ "add_group_guess_agg_diff",
33
+ "add_group_guess_diff",
34
+ "add_group_nimbus",
35
+ "add_group_nimbus_compromise",
36
+ "add_group_nimbus_compromise_diff",
37
+ "add_group_nimbus_diff",
38
+ "add_group_stom",
39
+ "add_group_stom_agg",
40
+ "add_group_stom_agg_diff",
41
+ "add_group_stom_diff",
42
+ "add_guess_sf_diff",
43
+ "add_guess_sf_nondiff",
44
+ "add_nimbus_sf_diff",
45
+ "add_nimbus_sf_nondiff",
46
+ "add_objective_as_scalarization",
47
+ "add_stom_sf_diff",
48
+ "add_stom_sf_nondiff",
49
+ "add_weighted_sums",
50
+ "available_nevergrad_optimizers",
51
+ "available_solvers",
52
+ "find_compatible_solvers",
53
+ "flip_maximized_objective_values",
54
+ "get_corrected_ideal_and_nadir",
55
+ "guess_best_solver",
56
+ "payoff_table_method",
57
+ ]
58
+
59
+ from desdeo.tools.generics import BaseSolver, SolverOptions, SolverResults
60
+ from desdeo.tools.group_scalarization import (
61
+ add_group_asf,
62
+ add_group_asf_agg,
63
+ add_group_asf_agg_diff,
64
+ add_group_asf_diff,
65
+ add_group_guess,
66
+ add_group_guess_agg,
67
+ add_group_guess_agg_diff,
68
+ add_group_guess_diff,
69
+ add_group_nimbus,
70
+ add_group_nimbus_compromise,
71
+ add_group_nimbus_compromise_diff,
72
+ add_group_nimbus_diff,
73
+ add_group_stom,
74
+ add_group_stom_agg,
75
+ add_group_stom_agg_diff,
76
+ add_group_stom_diff,
77
+ )
78
+ from desdeo.tools.gurobipy_solver_interfaces import (
79
+ GurobipySolver,
80
+ PersistentGurobipySolver,
81
+ )
82
+ from desdeo.tools.ng_solver_interfaces import (
83
+ NevergradGenericOptions,
84
+ NevergradGenericSolver,
85
+ available_nevergrad_optimizers,
86
+ )
87
+ from desdeo.tools.proximal_solver import ProximalSolver
88
+ from desdeo.tools.pyomo_solver_interfaces import (
89
+ BonminOptions,
90
+ IpoptOptions,
91
+ PyomoBonminSolver,
92
+ PyomoCBCSolver,
93
+ PyomoGurobiSolver,
94
+ PyomoIpoptSolver,
95
+ )
96
+ from desdeo.tools.scalarization import (
97
+ ScalarizationError,
98
+ add_asf_diff,
99
+ add_asf_generic_diff,
100
+ add_asf_generic_nondiff,
101
+ add_asf_nondiff,
102
+ add_epsilon_constraints,
103
+ add_guess_sf_diff,
104
+ add_guess_sf_nondiff,
105
+ add_nimbus_sf_diff,
106
+ add_nimbus_sf_nondiff,
107
+ add_objective_as_scalarization,
108
+ add_stom_sf_diff,
109
+ add_stom_sf_nondiff,
110
+ add_weighted_sums,
111
+ )
112
+ from desdeo.tools.scipy_solver_interfaces import ScipyDeSolver, ScipyMinimizeSolver
113
+ from desdeo.tools.utils import (
114
+ available_solvers,
115
+ find_compatible_solvers,
116
+ flip_maximized_objective_values,
117
+ get_corrected_ideal_and_nadir,
118
+ guess_best_solver,
119
+ payoff_table_method,
120
+ )
@@ -0,0 +1,22 @@
1
+ """An utility function to generate descriptions related to UTOPIA matters"""
2
+
3
+ def generate_descriptions(mapjson: dict, sid: str, stand: str, holding: str, extension: str) -> dict:
4
+ descriptions = {}
5
+ if holding:
6
+ for feat in mapjson["features"]:
7
+ if False: # noqa: SIM108
8
+ ext = f".{feat["properties"][extension]}"
9
+ else:
10
+ ext = ""
11
+ descriptions[feat["properties"][sid]] = (
12
+ f"Ala {feat["properties"][holding].split("-")[-1]} kuvio {feat["properties"][stand]}{ext}: "
13
+ )
14
+ else:
15
+ for feat in mapjson["features"]:
16
+ if False: # noqa: SIM108
17
+ ext = f".{feat["properties"][extension]}"
18
+ else:
19
+ ext = ""
20
+ descriptions[feat["properties"][sid]
21
+ ] = f"Kuvio {feat["properties"][stand]}{ext}: "
22
+ return descriptions
@@ -0,0 +1,165 @@
1
+ """Defines generic classes, functions, and objects utilized in the tools module."""
2
+
3
+ from abc import ABC, abstractmethod
4
+ from typing import Any, TypeVar
5
+
6
+ import polars as pl
7
+ from pydantic import BaseModel, ConfigDict, Field, field_serializer
8
+
9
+ from desdeo.problem import (
10
+ Constraint,
11
+ Objective,
12
+ Problem,
13
+ ScalarizationFunction,
14
+ Variable,
15
+ )
16
+
17
+
18
+ class SolverError(Exception):
19
+ """Raised when an error with a solver is encountered."""
20
+
21
+
22
+ class EMOResult(BaseModel):
23
+ """Defines a schema for a dataclass to store the results of an EMO method."""
24
+
25
+ model_config = ConfigDict(arbitrary_types_allowed=True, use_attribute_docstrings=True)
26
+
27
+ optimal_variables: pl.DataFrame = Field()
28
+ """The decision vectors of the final population."""
29
+ optimal_outputs: pl.DataFrame = Field()
30
+ """The objective vectors, constraint vectors, extra_funcs, and targets of the final population."""
31
+
32
+ @field_serializer("optimal_variables")
33
+ def _serialize_optimal_variables(self, value: pl.DataFrame) -> dict[str, list[int | float]]:
34
+ return value.to_dict(as_series=False)
35
+
36
+ @field_serializer("optimal_outputs")
37
+ def _serialize_optimal_outputs(self, value: pl.DataFrame) -> dict[str, list[int | float]]:
38
+ return value.to_dict(as_series=False)
39
+
40
+
41
+ class SolverResults(BaseModel):
42
+ """Defines a schema for a dataclass to store the results of a solver."""
43
+
44
+ optimal_variables: dict[str, int | float | list] = Field(description="The optimal decision variables found.")
45
+ optimal_objectives: dict[str, float | list[float]] = Field(
46
+ description="The objective function values corresponding to the optimal decision variables found."
47
+ )
48
+ constraint_values: dict[str, float | int | list[float] | list] | None | Any = Field(
49
+ description=(
50
+ "The constraint values of the problem. A negative value means the constraint is respected, "
51
+ "a positive one means it has been breached."
52
+ ),
53
+ default=None,
54
+ )
55
+ extra_func_values: dict[str, float | list[float]] | None = Field(
56
+ description=("The extra function values of the problem."), default=None
57
+ )
58
+ scalarization_values: dict[str, float | list[float]] | None = Field(
59
+ description=("The scalarization function values of the problem."), default=None
60
+ )
61
+ success: bool = Field(description="A boolean flag indicating whether the optimization was successful or not.")
62
+ message: str = Field(description="Description of the cause of termination.")
63
+
64
+
65
+ class BaseSolver(ABC):
66
+ """Defines a schema for a solver base class."""
67
+
68
+ evaluator: object
69
+ problem: Problem
70
+
71
+ def __init__(self, problem: Problem, options: dict[str, any] | None = None):
72
+ """Initializer for the persistent solver.
73
+
74
+ Args:
75
+ problem (Problem): The problem for the solver.
76
+ options (dict[str,any]): Dictionary of parameters to set.
77
+ What these should be depends on the solver used.
78
+ """
79
+ self.problem = problem
80
+
81
+ @abstractmethod
82
+ def solve(self, target: str) -> SolverResults:
83
+ """Solves the current problem with the specified target.
84
+
85
+ Args:
86
+ target (str): a str representing the symbol of the target function.
87
+
88
+ Returns:
89
+ SolverResults: The results of the solver
90
+ """
91
+
92
+
93
+ class PersistentSolver:
94
+ """Defines a schema for a persistent solver class.
95
+
96
+ Can be used when reinitializing the solver every time the problem is changed is not practical.
97
+ """
98
+
99
+ evaluator: object
100
+ problem: Problem
101
+
102
+ def __init__(self, problem: Problem, options: dict[str, any] | None = None):
103
+ """Initializer for the persistent solver.
104
+
105
+ Args:
106
+ problem (Problem): The problem for the solver.
107
+ options (dict[str,any]): Dictionary of parameters to set.
108
+ What these should be depends on the solver used.
109
+ """
110
+ self.problem = problem
111
+
112
+ def add_constraint(self, constraint: Constraint | list[Constraint]):
113
+ """Add a constraint expression to the solver.
114
+
115
+ Args:
116
+ constraint (Constraint): the constraint function expression.
117
+ """
118
+
119
+ def add_objective(self, objective: Objective):
120
+ """Adds an objective function expression to the solver.
121
+
122
+ Args:
123
+ objective (Objective): an objective function expression to be added.
124
+ """
125
+
126
+ def add_scalarization_function(self, scalarization: ScalarizationFunction):
127
+ """Adds a scalrization expression to the solver.
128
+
129
+ Args:
130
+ scalarization (ScalarizationFunction): A scalarization function to be added.
131
+ """
132
+
133
+ def add_variable(self, variable: Variable):
134
+ """Add a variable to the solver.
135
+
136
+ Args:
137
+ variable (Variable): The definition of the variable to be added.
138
+ """
139
+
140
+ def remove_constraint(self, symbol: str):
141
+ """Removes a constraint from the solver.
142
+
143
+ Args:
144
+ symbol (str): a str representing the symbol of the constraint to be removed.
145
+ """
146
+
147
+ def remove_variable(self, symbol: str):
148
+ """Removes a variable from the model.
149
+
150
+ Args:
151
+ symbol (str): a str representing the symbol of the variable to be removed.
152
+ """
153
+
154
+ def solve(self, target: str) -> SolverResults:
155
+ """Solves the current problem with the specified target.
156
+
157
+ Args:
158
+ target (str): a str representing the symbol of the target function.
159
+
160
+ Returns:
161
+ SolverResults: The results of the solver
162
+ """
163
+
164
+
165
+ SolverOptions = TypeVar("SolverOptions", bound=Any)