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,116 @@
1
+ """Functions related to the reference point method.
2
+
3
+ This module contains functions related to the reference point method as
4
+ presented in Wierzbicki, A. P. (1982). A mathematical basis for satisficing
5
+ decision making. Mathematical modelling, 3(5), 391-405.
6
+ """
7
+
8
+ import numpy as np
9
+
10
+ from desdeo.problem import (
11
+ Problem,
12
+ numpy_array_to_objective_dict,
13
+ objective_dict_to_numpy_array,
14
+ )
15
+ from desdeo.tools import (
16
+ BaseSolver,
17
+ SolverOptions,
18
+ SolverResults,
19
+ add_asf_diff,
20
+ add_asf_nondiff,
21
+ guess_best_solver,
22
+ )
23
+
24
+
25
+ class ReferencePointError(Exception):
26
+ """Raised when an error with the reference point method is encountered."""
27
+
28
+
29
+ def rpm_solve_solutions(
30
+ problem: Problem,
31
+ reference_point: dict[str, float],
32
+ scalarization_options: dict | None = None,
33
+ solver: BaseSolver | None = None,
34
+ solver_options: SolverOptions | None = None,
35
+ ) -> list[SolverResults]:
36
+ """Finds (near) Pareto optimal solutions based on a reference point.
37
+
38
+ Find a (near) Pareto optimal solution based on the given reference point by
39
+ optimizing an achievement scalarizing function. The original reference point
40
+ is also perturbed, and another k (near) Pareto optimal solutions are found.
41
+ The k+1 solutions are then returned.
42
+
43
+ Args:
44
+ problem (Problem): the problem to be solved.
45
+ reference_point (dict[str, float]): the reference point. The keys of the dict
46
+ represent the objective function symbols defined in problem. The values
47
+ represent the aspiration level values.
48
+ scalarization_options (dict | None, optional): keyword arguments to be
49
+ passed to the achievement scalarizing function. Defaults to None.
50
+ solver (BaseSolver | None, optional): solver to optimize the achievement
51
+ scalarizing function. If not given, the method tried to guess the
52
+ most suitable solver based on the problem. Defaults to None.
53
+ solver_options (SolverOptions | None, optional): options passed to the
54
+ solver. If not given, the solver will use its default options. Defaults to None.
55
+
56
+ Raises:
57
+ ReferencePointError: the reference point is ill-defined.
58
+
59
+ Returns:
60
+ list[SolverResults]: a list of results containing the solutions found using
61
+ the reference point and the k perturbed reference points.
62
+
63
+ Note:
64
+ If the problem is twice differentiable, `add_asf_diff` is used from `desdeo.tools`.
65
+ If the problem is not twice differentiable, then `add_asf_nondiff` is used.
66
+ """
67
+ # setup problem with ASF
68
+ # check if problem is differentiable or not, choose appropriate ASF variant.
69
+
70
+ if not all(obj.symbol in reference_point for obj in problem.objectives):
71
+ msg = f"The reference point {reference_point} is missing entries for one or more of the objective functions."
72
+ raise ReferencePointError(msg)
73
+
74
+ _add_asf = add_asf_diff if problem.is_twice_differentiable else add_asf_nondiff
75
+
76
+ problem_w_asf, target = _add_asf(
77
+ problem, "_asf", reference_point, **scalarization_options if scalarization_options is not None else {}
78
+ )
79
+
80
+ # setup solver
81
+ # solve scalarized problem with given reference point
82
+
83
+ _init_solver = guess_best_solver(problem_w_asf) if solver is None else solver
84
+ _solver = _init_solver(problem_w_asf, solver_options)
85
+
86
+ initial_solution = _solver.solve(target)
87
+
88
+ # using the found solution, perturb the reference point to get
89
+ # k (num of objectives) perturbed reference points
90
+
91
+ initial_objective_vector = objective_dict_to_numpy_array(problem, initial_solution.optimal_objectives)
92
+ reference_point_vector = objective_dict_to_numpy_array(problem, reference_point)
93
+
94
+ distance = np.linalg.norm(reference_point_vector - initial_objective_vector)
95
+ unit_vectors = np.eye(len(initial_objective_vector))
96
+
97
+ perturbed_reference_point_vectors = reference_point_vector + (distance * unit_vectors)
98
+
99
+ perturbed_reference_points = [numpy_array_to_objective_dict(problem, v) for v in perturbed_reference_point_vectors]
100
+
101
+ # scalarize the problem using the appropriate ASF variant and the perturbed
102
+ # reference points
103
+
104
+ perturbed_problems_and_targets = [
105
+ _add_asf(problem, "_asf", rp, **scalarization_options if scalarization_options is not None else {})
106
+ for rp in perturbed_reference_points
107
+ ]
108
+
109
+ # solve the problems
110
+ perturbed_solutions = [
111
+ _init_solver(problem_and_target[0], solver_options).solve(problem_and_target[1])
112
+ for problem_and_target in perturbed_problems_and_targets
113
+ ]
114
+
115
+ # return the original solution and the solutions found with the perturbed reference points
116
+ return [initial_solution, *perturbed_solutions]
@@ -0,0 +1,79 @@
1
+ """Imports available from the desdeo-problem package."""
2
+
3
+ __all__ = [
4
+ "Constant",
5
+ "Constraint",
6
+ "ConstraintTypeEnum",
7
+ "DiscreteRepresentation",
8
+ "Evaluator",
9
+ "ExtraFunction",
10
+ "flatten_variable_dict",
11
+ "FormatEnum",
12
+ "GurobipyEvaluator",
13
+ "get_nadir_dict",
14
+ "get_ideal_dict",
15
+ "InfixExpressionParser",
16
+ "MathParser",
17
+ "numpy_array_to_objective_dict",
18
+ "objective_dict_to_numpy_array",
19
+ "Objective",
20
+ "ObjectiveTypeEnum",
21
+ "Problem",
22
+ "PyomoEvaluator",
23
+ "SympyEvaluator",
24
+ "tensor_constant_from_dataframe",
25
+ "PolarsEvaluator",
26
+ "PolarsEvaluatorModesEnum",
27
+ "ScalarizationFunction",
28
+ "Simulator",
29
+ "TensorConstant",
30
+ "TensorVariable",
31
+ "unflatten_variable_array",
32
+ "Variable",
33
+ "VariableDimensionEnum",
34
+ "VariableDomainTypeEnum",
35
+ "VariableType",
36
+ "VariableTypeEnum",
37
+ "variable_dimension_enumerate",
38
+ ]
39
+
40
+
41
+ from .evaluator import (
42
+ PolarsEvaluator,
43
+ PolarsEvaluatorModesEnum,
44
+ VariableDimensionEnum,
45
+ variable_dimension_enumerate,
46
+ )
47
+ from .gurobipy_evaluator import GurobipyEvaluator
48
+ from .infix_parser import InfixExpressionParser
49
+ from .json_parser import FormatEnum, MathParser
50
+ from .pyomo_evaluator import PyomoEvaluator
51
+ from .schema import (
52
+ Constant,
53
+ Constraint,
54
+ ConstraintTypeEnum,
55
+ DiscreteRepresentation,
56
+ ExtraFunction,
57
+ Objective,
58
+ ObjectiveTypeEnum,
59
+ Problem,
60
+ ScalarizationFunction,
61
+ Simulator,
62
+ TensorConstant,
63
+ TensorVariable,
64
+ Variable,
65
+ VariableDomainTypeEnum,
66
+ VariableType,
67
+ VariableTypeEnum,
68
+ )
69
+ from .simulator_evaluator import Evaluator
70
+ from .sympy_evaluator import SympyEvaluator
71
+ from .utils import (
72
+ flatten_variable_dict,
73
+ get_ideal_dict,
74
+ get_nadir_dict,
75
+ numpy_array_to_objective_dict,
76
+ objective_dict_to_numpy_array,
77
+ tensor_constant_from_dataframe,
78
+ unflatten_variable_array,
79
+ )