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.
- desdeo/__init__.py +8 -8
- desdeo/api/README.md +73 -0
- desdeo/api/__init__.py +15 -0
- desdeo/api/app.py +40 -0
- desdeo/api/config.py +69 -0
- desdeo/api/config.toml +53 -0
- desdeo/api/db.py +25 -0
- desdeo/api/db_init.py +79 -0
- desdeo/api/db_models.py +164 -0
- desdeo/api/malaga_db_init.py +27 -0
- desdeo/api/models/__init__.py +66 -0
- desdeo/api/models/archive.py +34 -0
- desdeo/api/models/preference.py +90 -0
- desdeo/api/models/problem.py +507 -0
- desdeo/api/models/reference_point_method.py +18 -0
- desdeo/api/models/session.py +46 -0
- desdeo/api/models/state.py +96 -0
- desdeo/api/models/user.py +51 -0
- desdeo/api/routers/_NAUTILUS.py +245 -0
- desdeo/api/routers/_NAUTILUS_navigator.py +233 -0
- desdeo/api/routers/_NIMBUS.py +762 -0
- desdeo/api/routers/__init__.py +5 -0
- desdeo/api/routers/problem.py +110 -0
- desdeo/api/routers/reference_point_method.py +117 -0
- desdeo/api/routers/session.py +76 -0
- desdeo/api/routers/test.py +16 -0
- desdeo/api/routers/user_authentication.py +366 -0
- desdeo/api/schema.py +94 -0
- desdeo/api/tests/__init__.py +0 -0
- desdeo/api/tests/conftest.py +59 -0
- desdeo/api/tests/test_models.py +701 -0
- desdeo/api/tests/test_routes.py +216 -0
- desdeo/api/utils/database.py +274 -0
- desdeo/api/utils/logger.py +29 -0
- desdeo/core.py +27 -0
- desdeo/emo/__init__.py +29 -0
- desdeo/emo/hooks/archivers.py +172 -0
- desdeo/emo/methods/EAs.py +418 -0
- desdeo/emo/methods/__init__.py +0 -0
- desdeo/emo/methods/bases.py +59 -0
- desdeo/emo/operators/__init__.py +1 -0
- desdeo/emo/operators/crossover.py +780 -0
- desdeo/emo/operators/evaluator.py +118 -0
- desdeo/emo/operators/generator.py +356 -0
- desdeo/emo/operators/mutation.py +1053 -0
- desdeo/emo/operators/selection.py +1036 -0
- desdeo/emo/operators/termination.py +178 -0
- desdeo/explanations/__init__.py +6 -0
- desdeo/explanations/explainer.py +100 -0
- desdeo/explanations/utils.py +90 -0
- desdeo/mcdm/__init__.py +19 -0
- desdeo/mcdm/nautili.py +345 -0
- desdeo/mcdm/nautilus.py +477 -0
- desdeo/mcdm/nautilus_navigator.py +655 -0
- desdeo/mcdm/nimbus.py +417 -0
- desdeo/mcdm/pareto_navigator.py +269 -0
- desdeo/mcdm/reference_point_method.py +116 -0
- desdeo/problem/__init__.py +79 -0
- desdeo/problem/evaluator.py +561 -0
- desdeo/problem/gurobipy_evaluator.py +562 -0
- desdeo/problem/infix_parser.py +341 -0
- desdeo/problem/json_parser.py +944 -0
- desdeo/problem/pyomo_evaluator.py +468 -0
- desdeo/problem/schema.py +1808 -0
- desdeo/problem/simulator_evaluator.py +298 -0
- desdeo/problem/sympy_evaluator.py +244 -0
- desdeo/problem/testproblems/__init__.py +73 -0
- desdeo/problem/testproblems/binh_and_korn_problem.py +88 -0
- desdeo/problem/testproblems/dtlz2_problem.py +102 -0
- desdeo/problem/testproblems/forest_problem.py +275 -0
- desdeo/problem/testproblems/knapsack_problem.py +163 -0
- desdeo/problem/testproblems/mcwb_problem.py +831 -0
- desdeo/problem/testproblems/mixed_variable_dimenrions_problem.py +83 -0
- desdeo/problem/testproblems/momip_problem.py +172 -0
- desdeo/problem/testproblems/nimbus_problem.py +143 -0
- desdeo/problem/testproblems/pareto_navigator_problem.py +89 -0
- desdeo/problem/testproblems/re_problem.py +492 -0
- desdeo/problem/testproblems/river_pollution_problem.py +434 -0
- desdeo/problem/testproblems/rocket_injector_design_problem.py +140 -0
- desdeo/problem/testproblems/simple_problem.py +351 -0
- desdeo/problem/testproblems/simulator_problem.py +92 -0
- desdeo/problem/testproblems/spanish_sustainability_problem.py +945 -0
- desdeo/problem/testproblems/zdt_problem.py +271 -0
- desdeo/problem/utils.py +245 -0
- desdeo/tools/GenerateReferencePoints.py +181 -0
- desdeo/tools/__init__.py +102 -0
- desdeo/tools/generics.py +145 -0
- desdeo/tools/gurobipy_solver_interfaces.py +258 -0
- desdeo/tools/indicators_binary.py +11 -0
- desdeo/tools/indicators_unary.py +375 -0
- desdeo/tools/interaction_schema.py +38 -0
- desdeo/tools/intersection.py +54 -0
- desdeo/tools/iterative_pareto_representer.py +99 -0
- desdeo/tools/message.py +234 -0
- desdeo/tools/ng_solver_interfaces.py +199 -0
- desdeo/tools/non_dominated_sorting.py +133 -0
- desdeo/tools/patterns.py +281 -0
- desdeo/tools/proximal_solver.py +99 -0
- desdeo/tools/pyomo_solver_interfaces.py +464 -0
- desdeo/tools/reference_vectors.py +462 -0
- desdeo/tools/scalarization.py +3138 -0
- desdeo/tools/scipy_solver_interfaces.py +454 -0
- desdeo/tools/score_bands.py +464 -0
- desdeo/tools/utils.py +320 -0
- desdeo/utopia_stuff/__init__.py +0 -0
- desdeo/utopia_stuff/data/1.json +15 -0
- desdeo/utopia_stuff/data/2.json +13 -0
- desdeo/utopia_stuff/data/3.json +15 -0
- desdeo/utopia_stuff/data/4.json +17 -0
- desdeo/utopia_stuff/data/5.json +15 -0
- desdeo/utopia_stuff/from_json.py +40 -0
- desdeo/utopia_stuff/reinit_user.py +38 -0
- desdeo/utopia_stuff/utopia_db_init.py +212 -0
- desdeo/utopia_stuff/utopia_problem.py +403 -0
- desdeo/utopia_stuff/utopia_problem_old.py +415 -0
- desdeo/utopia_stuff/utopia_reference_solutions.py +79 -0
- desdeo-2.0.0.dist-info/LICENSE +21 -0
- desdeo-2.0.0.dist-info/METADATA +168 -0
- desdeo-2.0.0.dist-info/RECORD +120 -0
- {desdeo-1.2.dist-info → desdeo-2.0.0.dist-info}/WHEEL +1 -1
- desdeo-1.2.dist-info/METADATA +0 -16
- 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
|
+
)
|