Coverage for moptipy / api / mo_algorithm.py: 91%
11 statements
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-24 08:49 +0000
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-24 08:49 +0000
1"""
2The base classes for multi-objective optimization algorithms.
4A multi-objective optimization algorithm is an optimization algorithm that can
5optimize multiple, possibly conflicting, objective functions at once. All such
6algorithms inherit from :class:`~moptipy.api.mo_algorithm.MOAlgorithm`. When
7developing or implementing new algorithms, you would still follow the concepts
8discussed in module :mod:`~moptipy.api.algorithm`.
10If you implement a new multi-objective algorithm, you can test it via the
11pre-defined unit test routine
12:func:`~moptipy.tests.mo_algorithm.validate_mo_algorithm`.
13"""
14from typing import cast
16from pycommons.types import type_error
18from moptipy.api.algorithm import Algorithm
19from moptipy.api.mo_process import MOProcess
20from moptipy.api.process import Process
23class MOAlgorithm(Algorithm):
24 """A base class for multi-objective optimization algorithms."""
26 def solve(self, process: Process) -> None:
27 """
28 Forward to :meth:`solve_mo` and cast `process` to `MOProcess`.
30 :param process: the process to solve. Must be an instance of
31 :class:`~moptipy.api.mo_process.MOProcess`.
32 """
33 if not isinstance(process, MOProcess):
34 raise type_error(process, "process", MOProcess)
35 self.solve_mo(cast("MOProcess", process))
37 def solve_mo(self, process: MOProcess) -> None:
38 """
39 Apply the multi-objective optimization algorithm to the given process.
41 :param process: the multi-objective process which provides methods to
42 access the search space, the termination criterion, and a source
43 of randomness. It also wraps the objective function, remembers the
44 best-so-far solution, and takes care of creating log files (if
45 this is wanted).
46 """