@File : solver.py @Time : 2024/06/07 14:10:11 @Author : Alejandro Marrero @Version : 1.0 @Contact : amarrerd@ull.edu.es @License : (C)Copyright 2024, Alejandro Marrero @Desc : None

Solver

Bases: ABC, SupportsSolve[P]

Solver is any callable type that receives a OptProblem as its argument and returns a tuple with the solution found

Source code in digneapy/_core/_solver.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class Solver(ABC, SupportsSolve[P]):
    """Solver is any callable type that receives a OptProblem
    as its argument and returns a tuple with the solution found
    """

    @abstractmethod
    def __call__(self, problem: P, *args, **kwargs) -> list[Solution]:
        """Solves a optimisation problem

        Args:
            problem (OptProblem): Any optimisation problem or callablle that receives a Sequence and returns a Tuple[float]

        Raises:
            NotImplementedError: Must be implemented by subclasses

        Returns:
            List[Solution]: Returns a sequence of olutions
        """
        msg = "__call__ method not implemented in Solver"
        raise NotImplementedError(msg)

__call__(problem, *args, **kwargs) abstractmethod

Solves a optimisation problem

Parameters:
  • problem (OptProblem) –

    Any optimisation problem or callablle that receives a Sequence and returns a Tuple[float]

Raises:
  • NotImplementedError

    Must be implemented by subclasses

Returns:
  • list[Solution]

    List[Solution]: Returns a sequence of olutions

Source code in digneapy/_core/_solver.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
@abstractmethod
def __call__(self, problem: P, *args, **kwargs) -> list[Solution]:
    """Solves a optimisation problem

    Args:
        problem (OptProblem): Any optimisation problem or callablle that receives a Sequence and returns a Tuple[float]

    Raises:
        NotImplementedError: Must be implemented by subclasses

    Returns:
        List[Solution]: Returns a sequence of olutions
    """
    msg = "__call__ method not implemented in Solver"
    raise NotImplementedError(msg)

SupportsSolve

Bases: Protocol[P]

Protocol to type check all the solver types in digneapy. A solver is any callable type that receives at least a problem (Problem) and returns a list of object of the Solution class.

Source code in digneapy/_core/_solver.py
20
21
22
23
24
25
26
class SupportsSolve(Protocol[P]):
    """Protocol to type check all the solver types in digneapy.
    A solver is any callable type that receives at least a problem (Problem) and
    returns a list of object of the Solution  class.
    """

    def __call__(self, problem: P, *args, **kwargs) -> list[Solution]: ...