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.
- desdeo/__init__.py +8 -8
- desdeo/adm/ADMAfsar.py +551 -0
- desdeo/adm/ADMChen.py +414 -0
- desdeo/adm/BaseADM.py +119 -0
- desdeo/adm/__init__.py +11 -0
- desdeo/api/README.md +73 -0
- desdeo/api/__init__.py +15 -0
- desdeo/api/app.py +50 -0
- desdeo/api/config.py +90 -0
- desdeo/api/config.toml +64 -0
- desdeo/api/db.py +27 -0
- desdeo/api/db_init.py +85 -0
- desdeo/api/db_models.py +164 -0
- desdeo/api/malaga_db_init.py +27 -0
- desdeo/api/models/__init__.py +266 -0
- desdeo/api/models/archive.py +23 -0
- desdeo/api/models/emo.py +128 -0
- desdeo/api/models/enautilus.py +69 -0
- desdeo/api/models/gdm/gdm_aggregate.py +139 -0
- desdeo/api/models/gdm/gdm_base.py +69 -0
- desdeo/api/models/gdm/gdm_score_bands.py +114 -0
- desdeo/api/models/gdm/gnimbus.py +138 -0
- desdeo/api/models/generic.py +104 -0
- desdeo/api/models/generic_states.py +401 -0
- desdeo/api/models/nimbus.py +158 -0
- desdeo/api/models/preference.py +128 -0
- desdeo/api/models/problem.py +717 -0
- desdeo/api/models/reference_point_method.py +18 -0
- desdeo/api/models/session.py +49 -0
- desdeo/api/models/state.py +463 -0
- desdeo/api/models/user.py +52 -0
- desdeo/api/models/utopia.py +25 -0
- desdeo/api/routers/_EMO.backup +309 -0
- desdeo/api/routers/_NAUTILUS.py +245 -0
- desdeo/api/routers/_NAUTILUS_navigator.py +233 -0
- desdeo/api/routers/_NIMBUS.py +765 -0
- desdeo/api/routers/__init__.py +5 -0
- desdeo/api/routers/emo.py +497 -0
- desdeo/api/routers/enautilus.py +237 -0
- desdeo/api/routers/gdm/gdm_aggregate.py +234 -0
- desdeo/api/routers/gdm/gdm_base.py +420 -0
- desdeo/api/routers/gdm/gdm_score_bands/gdm_score_bands_manager.py +398 -0
- desdeo/api/routers/gdm/gdm_score_bands/gdm_score_bands_routers.py +377 -0
- desdeo/api/routers/gdm/gnimbus/gnimbus_manager.py +698 -0
- desdeo/api/routers/gdm/gnimbus/gnimbus_routers.py +591 -0
- desdeo/api/routers/generic.py +233 -0
- desdeo/api/routers/nimbus.py +705 -0
- desdeo/api/routers/problem.py +307 -0
- desdeo/api/routers/reference_point_method.py +93 -0
- desdeo/api/routers/session.py +100 -0
- desdeo/api/routers/test.py +16 -0
- desdeo/api/routers/user_authentication.py +520 -0
- desdeo/api/routers/utils.py +187 -0
- desdeo/api/routers/utopia.py +230 -0
- desdeo/api/schema.py +100 -0
- desdeo/api/tests/__init__.py +0 -0
- desdeo/api/tests/conftest.py +151 -0
- desdeo/api/tests/test_enautilus.py +330 -0
- desdeo/api/tests/test_models.py +1179 -0
- desdeo/api/tests/test_routes.py +1075 -0
- desdeo/api/utils/_database.py +263 -0
- desdeo/api/utils/_logger.py +29 -0
- desdeo/api/utils/database.py +36 -0
- desdeo/api/utils/emo_database.py +40 -0
- desdeo/core.py +34 -0
- desdeo/emo/__init__.py +159 -0
- desdeo/emo/hooks/archivers.py +188 -0
- desdeo/emo/methods/EAs.py +541 -0
- desdeo/emo/methods/__init__.py +0 -0
- desdeo/emo/methods/bases.py +12 -0
- desdeo/emo/methods/templates.py +111 -0
- desdeo/emo/operators/__init__.py +1 -0
- desdeo/emo/operators/crossover.py +1282 -0
- desdeo/emo/operators/evaluator.py +114 -0
- desdeo/emo/operators/generator.py +459 -0
- desdeo/emo/operators/mutation.py +1224 -0
- desdeo/emo/operators/scalar_selection.py +202 -0
- desdeo/emo/operators/selection.py +1778 -0
- desdeo/emo/operators/termination.py +286 -0
- desdeo/emo/options/__init__.py +108 -0
- desdeo/emo/options/algorithms.py +435 -0
- desdeo/emo/options/crossover.py +164 -0
- desdeo/emo/options/generator.py +131 -0
- desdeo/emo/options/mutation.py +260 -0
- desdeo/emo/options/repair.py +61 -0
- desdeo/emo/options/scalar_selection.py +66 -0
- desdeo/emo/options/selection.py +127 -0
- desdeo/emo/options/templates.py +383 -0
- desdeo/emo/options/termination.py +143 -0
- desdeo/explanations/__init__.py +6 -0
- desdeo/explanations/explainer.py +100 -0
- desdeo/explanations/utils.py +90 -0
- desdeo/gdm/__init__.py +22 -0
- desdeo/gdm/gdmtools.py +45 -0
- desdeo/gdm/score_bands.py +114 -0
- desdeo/gdm/voting_rules.py +50 -0
- desdeo/mcdm/__init__.py +41 -0
- desdeo/mcdm/enautilus.py +338 -0
- desdeo/mcdm/gnimbus.py +484 -0
- desdeo/mcdm/nautili.py +345 -0
- desdeo/mcdm/nautilus.py +477 -0
- desdeo/mcdm/nautilus_navigator.py +656 -0
- desdeo/mcdm/nimbus.py +417 -0
- desdeo/mcdm/pareto_navigator.py +269 -0
- desdeo/mcdm/reference_point_method.py +186 -0
- desdeo/problem/__init__.py +83 -0
- desdeo/problem/evaluator.py +561 -0
- desdeo/problem/external/__init__.py +18 -0
- desdeo/problem/external/core.py +356 -0
- desdeo/problem/external/pymoo_provider.py +266 -0
- desdeo/problem/external/runtime.py +44 -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 +487 -0
- desdeo/problem/schema.py +1829 -0
- desdeo/problem/simulator_evaluator.py +348 -0
- desdeo/problem/sympy_evaluator.py +244 -0
- desdeo/problem/testproblems/__init__.py +88 -0
- desdeo/problem/testproblems/benchmarks_server.py +120 -0
- desdeo/problem/testproblems/binh_and_korn_problem.py +88 -0
- desdeo/problem/testproblems/cake_problem.py +185 -0
- desdeo/problem/testproblems/dmitry_forest_problem_discrete.py +71 -0
- desdeo/problem/testproblems/dtlz2_problem.py +102 -0
- desdeo/problem/testproblems/forest_problem.py +283 -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/multi_valued_constraints.py +119 -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_problems.py +440 -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/single_objective.py +289 -0
- desdeo/problem/testproblems/spanish_sustainability_problem.py +945 -0
- desdeo/problem/testproblems/zdt_problem.py +274 -0
- desdeo/problem/utils.py +245 -0
- desdeo/tools/GenerateReferencePoints.py +181 -0
- desdeo/tools/__init__.py +120 -0
- desdeo/tools/desc_gen.py +22 -0
- desdeo/tools/generics.py +165 -0
- desdeo/tools/group_scalarization.py +3090 -0
- desdeo/tools/gurobipy_solver_interfaces.py +258 -0
- desdeo/tools/indicators_binary.py +117 -0
- desdeo/tools/indicators_unary.py +362 -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 +265 -0
- desdeo/tools/ng_solver_interfaces.py +199 -0
- desdeo/tools/non_dominated_sorting.py +134 -0
- desdeo/tools/patterns.py +283 -0
- desdeo/tools/proximal_solver.py +99 -0
- desdeo/tools/pyomo_solver_interfaces.py +477 -0
- desdeo/tools/reference_vectors.py +229 -0
- desdeo/tools/scalarization.py +2065 -0
- desdeo/tools/scipy_solver_interfaces.py +454 -0
- desdeo/tools/score_bands.py +627 -0
- desdeo/tools/utils.py +388 -0
- desdeo/tools/visualizations.py +67 -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.1.0.dist-info/METADATA +186 -0
- desdeo-2.1.0.dist-info/RECORD +180 -0
- {desdeo-1.2.dist-info → desdeo-2.1.0.dist-info}/WHEEL +1 -1
- desdeo-2.1.0.dist-info/licenses/LICENSE +21 -0
- desdeo-1.2.dist-info/METADATA +0 -16
- desdeo-1.2.dist-info/RECORD +0 -4
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"""The base class for termination criteria.
|
|
2
|
+
|
|
3
|
+
The termination criterion is used to determine when the optimization process should stop. In this implementation, it
|
|
4
|
+
also includes a simple counter for the number of elapsed generations. This counter is increased by one each time the
|
|
5
|
+
termination criterion is called. The simplest termination criterion is reaching the maximum number of generations.
|
|
6
|
+
The implementation also contains a counter for the number of evaluations. This counter is updated by the Evaluator
|
|
7
|
+
and Generator classes. The termination criterion can be based on the number of evaluations as well.
|
|
8
|
+
|
|
9
|
+
Warning:
|
|
10
|
+
Each subclass of BaseTerminator must implement the do method. The do method should always call the
|
|
11
|
+
super().do method to increment the generation counter _before_ conducting the termination check.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import time
|
|
15
|
+
from abc import abstractmethod
|
|
16
|
+
from collections.abc import Sequence
|
|
17
|
+
|
|
18
|
+
from desdeo.tools.message import (
|
|
19
|
+
EvaluatorMessageTopics,
|
|
20
|
+
GeneratorMessageTopics,
|
|
21
|
+
IntMessage,
|
|
22
|
+
Message,
|
|
23
|
+
TerminatorMessageTopics,
|
|
24
|
+
)
|
|
25
|
+
from desdeo.tools.patterns import Publisher, Subscriber
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class BaseTerminator(Subscriber):
|
|
29
|
+
"""The base class for the termination criteria.
|
|
30
|
+
|
|
31
|
+
Also includes a simple counter for number of elapsed generations. This counter is increased by one each time the
|
|
32
|
+
termination criterion is called.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def provided_topics(self) -> dict[int, Sequence[TerminatorMessageTopics]]:
|
|
37
|
+
"""Return the topics provided by the terminator.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
dict[int, Sequence[TerminatorMessageTopics]]: The topics provided by the terminator.
|
|
41
|
+
"""
|
|
42
|
+
return {
|
|
43
|
+
0: [],
|
|
44
|
+
1: [
|
|
45
|
+
TerminatorMessageTopics.GENERATION,
|
|
46
|
+
TerminatorMessageTopics.EVALUATION,
|
|
47
|
+
TerminatorMessageTopics.MAX_GENERATIONS,
|
|
48
|
+
TerminatorMessageTopics.MAX_EVALUATIONS,
|
|
49
|
+
],
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def interested_topics(self):
|
|
54
|
+
"""Return the message topics that the terminator is interested in."""
|
|
55
|
+
return [EvaluatorMessageTopics.NEW_EVALUATIONS, GeneratorMessageTopics.NEW_EVALUATIONS]
|
|
56
|
+
|
|
57
|
+
def __init__(self, publisher: Publisher):
|
|
58
|
+
"""Initialize a termination criterion."""
|
|
59
|
+
super().__init__(publisher=publisher, verbosity=1)
|
|
60
|
+
self.current_generation: int = 1
|
|
61
|
+
self.current_evaluations: int = 0
|
|
62
|
+
self.max_generations: int = 0
|
|
63
|
+
self.max_evaluations: int = 0
|
|
64
|
+
|
|
65
|
+
def check(self) -> bool:
|
|
66
|
+
"""Check if the termination criterion is reached.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
bool: True if the termination criterion is reached, False otherwise.
|
|
70
|
+
"""
|
|
71
|
+
self.current_generation += 1
|
|
72
|
+
self.notify()
|
|
73
|
+
|
|
74
|
+
def state(self) -> Sequence[Message]:
|
|
75
|
+
"""Return the state of the termination criterion."""
|
|
76
|
+
state = [
|
|
77
|
+
IntMessage(
|
|
78
|
+
topic=TerminatorMessageTopics.GENERATION,
|
|
79
|
+
value=self.current_generation,
|
|
80
|
+
source=self.__class__.__name__,
|
|
81
|
+
),
|
|
82
|
+
IntMessage(
|
|
83
|
+
topic=TerminatorMessageTopics.EVALUATION, value=self.current_evaluations, source=self.__class__.__name__
|
|
84
|
+
),
|
|
85
|
+
]
|
|
86
|
+
if self.max_evaluations != 0:
|
|
87
|
+
state.append(
|
|
88
|
+
IntMessage(
|
|
89
|
+
topic=TerminatorMessageTopics.MAX_EVALUATIONS,
|
|
90
|
+
value=self.max_evaluations,
|
|
91
|
+
source=self.__class__.__name__,
|
|
92
|
+
)
|
|
93
|
+
)
|
|
94
|
+
if self.max_generations != 0:
|
|
95
|
+
state.append(
|
|
96
|
+
IntMessage(
|
|
97
|
+
topic=TerminatorMessageTopics.MAX_GENERATIONS,
|
|
98
|
+
value=self.max_generations,
|
|
99
|
+
source=self.__class__.__name__,
|
|
100
|
+
)
|
|
101
|
+
)
|
|
102
|
+
return state
|
|
103
|
+
|
|
104
|
+
def update(self, message: Message) -> None:
|
|
105
|
+
"""Update the number of evaluations.
|
|
106
|
+
|
|
107
|
+
Note that for this method to work, this class must be registered as an observer of a subject that sends
|
|
108
|
+
messages with the key "num_evaluations". The Evaluator class does this.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
message (dict): the message from the subject, must contain the key "num_evaluations".
|
|
112
|
+
"""
|
|
113
|
+
if not isinstance(message, IntMessage):
|
|
114
|
+
return
|
|
115
|
+
if not (isinstance(message.topic, EvaluatorMessageTopics) or isinstance(message.topic, GeneratorMessageTopics)):
|
|
116
|
+
return
|
|
117
|
+
if (
|
|
118
|
+
message.topic == EvaluatorMessageTopics.NEW_EVALUATIONS # NOQA: PLR1714
|
|
119
|
+
or message.topic == GeneratorMessageTopics.NEW_EVALUATIONS
|
|
120
|
+
):
|
|
121
|
+
self.current_evaluations += message.value
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class MaxGenerationsTerminator(BaseTerminator):
|
|
125
|
+
"""A class for a termination criterion based on the number of generations."""
|
|
126
|
+
|
|
127
|
+
def __init__(self, max_generations: int, publisher: Publisher):
|
|
128
|
+
"""Initialize a termination criterion based on the number of generations.
|
|
129
|
+
|
|
130
|
+
Args:
|
|
131
|
+
max_generations (int): the maximum number of generations.
|
|
132
|
+
publisher (Publisher): The publisher to which the terminator will publish its state.
|
|
133
|
+
"""
|
|
134
|
+
super().__init__(publisher=publisher)
|
|
135
|
+
self.max_generations = max_generations
|
|
136
|
+
|
|
137
|
+
def check(self) -> bool:
|
|
138
|
+
"""Check if the termination criterion based on the number of generations is reached.
|
|
139
|
+
|
|
140
|
+
Returns:
|
|
141
|
+
bool: True if the termination criterion is reached, False otherwise.
|
|
142
|
+
"""
|
|
143
|
+
super().check()
|
|
144
|
+
self.notify()
|
|
145
|
+
return self.current_generation > self.max_generations
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
# TODO (@light-weaver): This check is done _after_ the evaluations have taken place.
|
|
149
|
+
# This means that the algorithm will run for one more generation than it should.
|
|
150
|
+
class MaxEvaluationsTerminator(BaseTerminator):
|
|
151
|
+
"""A class for a termination criterion based on the number of evaluations."""
|
|
152
|
+
|
|
153
|
+
def __init__(self, max_evaluations: int, publisher: Publisher):
|
|
154
|
+
"""Initialize a termination criterion based on the number of evaluations.
|
|
155
|
+
|
|
156
|
+
Looks for messages with key "num_evaluations" to update the number of evaluations.
|
|
157
|
+
|
|
158
|
+
Args:
|
|
159
|
+
max_evaluations (int): the maximum number of evaluations.
|
|
160
|
+
publisher (Publisher): The publisher to which the terminator will publish its state.
|
|
161
|
+
publisher must be passed. See the Subscriber class for more information.
|
|
162
|
+
"""
|
|
163
|
+
super().__init__(publisher=publisher)
|
|
164
|
+
if not isinstance(max_evaluations, int) or max_evaluations < 0:
|
|
165
|
+
raise ValueError("max_evaluations must be a non-negative integer")
|
|
166
|
+
self.max_evaluations = max_evaluations
|
|
167
|
+
self.current_evaluations = 0
|
|
168
|
+
|
|
169
|
+
def check(self) -> bool:
|
|
170
|
+
"""Check if the termination criterion based on the number of generations is reached.
|
|
171
|
+
|
|
172
|
+
Returns:
|
|
173
|
+
bool: True if the termination criterion is reached, False otherwise.
|
|
174
|
+
"""
|
|
175
|
+
super().check()
|
|
176
|
+
self.notify()
|
|
177
|
+
return self.current_evaluations >= self.max_evaluations
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
class CompositeTerminator(BaseTerminator):
|
|
181
|
+
"""Combines multiple terminators using logical AND or OR."""
|
|
182
|
+
|
|
183
|
+
def __init__(self, terminators: list[BaseTerminator], publisher: Publisher, mode: str = "any"):
|
|
184
|
+
"""Initialize a composite termination criterion.
|
|
185
|
+
|
|
186
|
+
Args:
|
|
187
|
+
terminators (list[BaseTerminator]): List of BaseTerminator instances.
|
|
188
|
+
publisher (Publisher): Publisher for passing messages.
|
|
189
|
+
mode (str): "any" (terminate if any) or "all" (terminate if all). By default, "any".
|
|
190
|
+
"""
|
|
191
|
+
super().__init__(publisher=publisher)
|
|
192
|
+
self.terminators = terminators
|
|
193
|
+
for t in self.terminators:
|
|
194
|
+
t.notify = lambda: None # Reset the notify method so that individual terminators do not send notifications
|
|
195
|
+
types = [type(t) for t in self.terminators]
|
|
196
|
+
# Assert that all terminators are unique
|
|
197
|
+
if len(types) != len(set(types)):
|
|
198
|
+
raise ValueError("All terminators must be unique.")
|
|
199
|
+
max_generations = [t.max_generations for t in self.terminators if isinstance(t, MaxGenerationsTerminator)]
|
|
200
|
+
if max_generations:
|
|
201
|
+
self.max_generations = max(max_generations)
|
|
202
|
+
max_evaluations = [t.max_evaluations for t in self.terminators if isinstance(t, MaxEvaluationsTerminator)]
|
|
203
|
+
if max_evaluations:
|
|
204
|
+
self.max_evaluations = max(max_evaluations)
|
|
205
|
+
self.mode = mode
|
|
206
|
+
|
|
207
|
+
def check(self) -> bool:
|
|
208
|
+
"""Check if the termination criterion is reached.
|
|
209
|
+
|
|
210
|
+
Returns:
|
|
211
|
+
bool: True if the termination criterion is reached, False otherwise.
|
|
212
|
+
"""
|
|
213
|
+
super().check()
|
|
214
|
+
results = [t.check() for t in self.terminators]
|
|
215
|
+
if self.mode == "all":
|
|
216
|
+
return all(results)
|
|
217
|
+
return any(results)
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
class ExternalCheckTerminator(BaseTerminator):
|
|
221
|
+
"""A termination criterion that checks an external condition."""
|
|
222
|
+
|
|
223
|
+
def __init__(self, check_function, publisher: Publisher):
|
|
224
|
+
"""Initialize the external check terminator.
|
|
225
|
+
|
|
226
|
+
Args:
|
|
227
|
+
check_function (callable): A function that returns True if the termination condition is met.
|
|
228
|
+
publisher (Publisher): The publisher to send messages to.
|
|
229
|
+
"""
|
|
230
|
+
super().__init__(publisher=publisher)
|
|
231
|
+
self.check_function = check_function
|
|
232
|
+
|
|
233
|
+
def check(self) -> bool:
|
|
234
|
+
"""Check if the termination condition is met.
|
|
235
|
+
|
|
236
|
+
Returns:
|
|
237
|
+
bool: True if the termination condition is met, False otherwise.
|
|
238
|
+
"""
|
|
239
|
+
super().check()
|
|
240
|
+
self.notify()
|
|
241
|
+
return self.check_function()
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
class MaxTimeTerminator(BaseTerminator):
|
|
245
|
+
"""A termination criterion based on the maximum elapsed time."""
|
|
246
|
+
|
|
247
|
+
@property
|
|
248
|
+
def provided_topics(self) -> dict[int, Sequence[TerminatorMessageTopics]]:
|
|
249
|
+
"""Return the topics provided by the terminator.
|
|
250
|
+
|
|
251
|
+
Returns:
|
|
252
|
+
dict[int, Sequence[TerminatorMessageTopics]]: The topics provided by the terminator.
|
|
253
|
+
"""
|
|
254
|
+
return {
|
|
255
|
+
0: [],
|
|
256
|
+
1: [
|
|
257
|
+
TerminatorMessageTopics.GENERATION,
|
|
258
|
+
TerminatorMessageTopics.EVALUATION,
|
|
259
|
+
],
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
def __init__(self, max_time_in_seconds: float, publisher: Publisher):
|
|
263
|
+
"""Initialize the maximum time terminator.
|
|
264
|
+
|
|
265
|
+
Args:
|
|
266
|
+
max_time_in_seconds (float): The maximum elapsed time in seconds.
|
|
267
|
+
publisher (Publisher): The publisher to which the terminator will publish its state.
|
|
268
|
+
"""
|
|
269
|
+
super().__init__(publisher=publisher)
|
|
270
|
+
if not isinstance(max_time_in_seconds, float) or max_time_in_seconds < 0:
|
|
271
|
+
raise ValueError("max_time must be a non-negative float")
|
|
272
|
+
self.max_time = max_time_in_seconds
|
|
273
|
+
self.start_time = None
|
|
274
|
+
|
|
275
|
+
def check(self) -> bool:
|
|
276
|
+
"""Check if the termination criterion based on the maximum elapsed time is reached.
|
|
277
|
+
|
|
278
|
+
Returns:
|
|
279
|
+
bool: True if the termination criterion is reached, False otherwise.
|
|
280
|
+
"""
|
|
281
|
+
super().check()
|
|
282
|
+
self.notify()
|
|
283
|
+
if self.start_time is None:
|
|
284
|
+
self.start_time = time.perf_counter()
|
|
285
|
+
elapsed_time = time.perf_counter() - self.start_time
|
|
286
|
+
return elapsed_time >= self.max_time
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
from .crossover import (
|
|
2
|
+
BlendAlphaCrossoverOptions,
|
|
3
|
+
BoundedExponentialCrossoverOptions,
|
|
4
|
+
CrossoverOptions,
|
|
5
|
+
LocalCrossoverOptions,
|
|
6
|
+
SimulatedBinaryCrossoverOptions,
|
|
7
|
+
SingleArithmeticCrossoverOptions,
|
|
8
|
+
SinglePointBinaryCrossoverOptions,
|
|
9
|
+
UniformIntegerCrossoverOptions,
|
|
10
|
+
UniformMixedIntegerCrossoverOptions,
|
|
11
|
+
crossover_constructor,
|
|
12
|
+
)
|
|
13
|
+
from .generator import (
|
|
14
|
+
GeneratorOptions,
|
|
15
|
+
LHSGeneratorOptions,
|
|
16
|
+
RandomBinaryGeneratorOptions,
|
|
17
|
+
RandomGeneratorOptions,
|
|
18
|
+
RandomIntegerGeneratorOptions,
|
|
19
|
+
RandomMixedIntegerGeneratorOptions,
|
|
20
|
+
generator_constructor,
|
|
21
|
+
)
|
|
22
|
+
from .mutation import (
|
|
23
|
+
BinaryFlipMutationOptions,
|
|
24
|
+
BoundedPolynomialMutationOptions,
|
|
25
|
+
IntegerRandomMutationOptions,
|
|
26
|
+
MixedIntegerRandomMutationOptions,
|
|
27
|
+
MPTMutationOptions,
|
|
28
|
+
MutationOptions,
|
|
29
|
+
NonUniformMutationOptions,
|
|
30
|
+
PowerMutationOptions,
|
|
31
|
+
SelfAdaptiveGaussianMutationOptions,
|
|
32
|
+
mutation_constructor,
|
|
33
|
+
)
|
|
34
|
+
from .repair import RepairOptions, repair_constructor
|
|
35
|
+
from .scalar_selection import (
|
|
36
|
+
RouletteWheelSelectionOptions,
|
|
37
|
+
ScalarSelectionOptions,
|
|
38
|
+
TournamentSelectionOptions,
|
|
39
|
+
scalar_selector_constructor,
|
|
40
|
+
)
|
|
41
|
+
from .selection import (
|
|
42
|
+
IBEASelectorOptions,
|
|
43
|
+
NSGA2SelectorOptions,
|
|
44
|
+
NSGA3SelectorOptions,
|
|
45
|
+
ReferenceVectorOptions,
|
|
46
|
+
RVEASelectorOptions,
|
|
47
|
+
SelectorOptions,
|
|
48
|
+
selection_constructor,
|
|
49
|
+
)
|
|
50
|
+
from .termination import (
|
|
51
|
+
CompositeTerminatorOptions,
|
|
52
|
+
ExternalCheckTerminatorOptions,
|
|
53
|
+
MaxEvaluationsTerminatorOptions,
|
|
54
|
+
MaxGenerationsTerminatorOptions,
|
|
55
|
+
MaxTimeTerminatorOptions,
|
|
56
|
+
TerminatorOptions,
|
|
57
|
+
terminator_constructor,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
__all__ = [ # noqa: RUF022
|
|
61
|
+
"BinaryFlipMutationOptions",
|
|
62
|
+
"BlendAlphaCrossoverOptions",
|
|
63
|
+
"BoundedExponentialCrossoverOptions",
|
|
64
|
+
"BoundedPolynomialMutationOptions",
|
|
65
|
+
"CompositeTerminatorOptions",
|
|
66
|
+
"CrossoverOptions",
|
|
67
|
+
"ExternalCheckTerminatorOptions",
|
|
68
|
+
"GeneratorOptions",
|
|
69
|
+
"IBEASelectorOptions",
|
|
70
|
+
"IntegerRandomMutationOptions",
|
|
71
|
+
"LHSGeneratorOptions",
|
|
72
|
+
"LocalCrossoverOptions",
|
|
73
|
+
"MaxEvaluationsTerminatorOptions",
|
|
74
|
+
"MaxGenerationsTerminatorOptions",
|
|
75
|
+
"MaxTimeTerminatorOptions",
|
|
76
|
+
"MixedIntegerRandomMutationOptions",
|
|
77
|
+
"MPTMutationOptions",
|
|
78
|
+
"MutationOptions",
|
|
79
|
+
"NSGA2SelectorOptions",
|
|
80
|
+
"NSGA3SelectorOptions",
|
|
81
|
+
"NonUniformMutationOptions",
|
|
82
|
+
"PowerMutationOptions",
|
|
83
|
+
"RandomBinaryGeneratorOptions",
|
|
84
|
+
"RandomGeneratorOptions",
|
|
85
|
+
"RandomIntegerGeneratorOptions",
|
|
86
|
+
"RandomMixedIntegerGeneratorOptions",
|
|
87
|
+
"ReferenceVectorOptions",
|
|
88
|
+
"RouletteWheelSelectionOptions",
|
|
89
|
+
"RVEASelectorOptions",
|
|
90
|
+
"ScalarSelectionOptions",
|
|
91
|
+
"scalar_selector_constructor",
|
|
92
|
+
"SelfAdaptiveGaussianMutationOptions",
|
|
93
|
+
"SelectorOptions",
|
|
94
|
+
"SimulatedBinaryCrossoverOptions",
|
|
95
|
+
"SingleArithmeticCrossoverOptions",
|
|
96
|
+
"SinglePointBinaryCrossoverOptions",
|
|
97
|
+
"TerminatorOptions",
|
|
98
|
+
"terminator_constructor",
|
|
99
|
+
"TournamentSelectionOptions",
|
|
100
|
+
"UniformIntegerCrossoverOptions",
|
|
101
|
+
"UniformMixedIntegerCrossoverOptions",
|
|
102
|
+
"crossover_constructor",
|
|
103
|
+
"generator_constructor",
|
|
104
|
+
"mutation_constructor",
|
|
105
|
+
"selection_constructor",
|
|
106
|
+
"RepairOptions",
|
|
107
|
+
"repair_constructor",
|
|
108
|
+
]
|