"""This modules implement abstract base classes of user-defined input models.
"""
from abc import ABC, abstractmethod
from numpy import ndarray
from decogo.solver.results import Results
from decogo.problem.decomposed_problem import DecomposedProblem
[docs]class OriginalProblemBase(ABC):
"""An abstract base class for original_problem with user-defined solver
"""
[docs] def __init__(self):
"""Constructor method"""
super().__init__()
[docs] @abstractmethod
def local_solve(self, start_point, result, problem, iter=None):
""" Abstract method for solving original problem
non-optimal/heuristically/locally
:param start_point: Starting point for the solver, defaults to ``None``
:type start_point: ndarray
:param result: stores and makes some manipulations with the CG results
:type result: Results
:param problem: stores all problem objects
:type problem: DecomposedProblem
:param iter: index of iterations in main algorithm
:type iter: int
"""
pass
[docs] @abstractmethod
def local_solve_fast(self, start_point, result, problem, iter=None):
""" Abstract method for fast solving original problem
non-optimal/heuristically/locally
:param start_point: Starting point for the solver, defaults to ``None``
:type start_point: ndarray
:param result: stores and makes some manipulations with the CG results
:type result: Results
:param problem: stores all problem objects
:type problem: DecomposedProblem
:param iter: index of iterations in main algorithm
:type iter: int
"""
pass
[docs]class SubModelBase(ABC):
"""An abstract base class which stores the variables from the single
block and local nonlinear constraints.
:param vars_in_block: List of original variable names from the model
:type vars_in_block: list
:param block_id: Identifier for block
:type block_id: int
:param variables: List of all variables with all necessary properties
:type variables: list
:param block_size: Number of variables in the sub-model
:type block_size: int
:param integer: Indicates if the current sub-model contains variable of \
integer type
:type integer: bool
:param nonlin_constr: List of local nonlinear constraints
:type nonlin_constr: list
"""
[docs] def __init__(self, vars_in_block, block_id):
"""Constructor method"""
super().__init__()
# stores original names of the variables in the block
self.vars_in_block = vars_in_block
self.block_id = block_id
self.variables = []
self.nonlin_constr = []
self.block_size = len(vars_in_block)
self.integer = False
self.linear = False
[docs]class SubProblemsBase(ABC):
"""An abstract base class for constructing a generalised model of
sub-problems with user-defined solvers.
:param block_id: Block identifier
:type block_id: int
"""
[docs] def __init__(self, block_id):
"""Constructor method"""
super().__init__()
self.block_id = block_id
[docs] @abstractmethod
def local_solve(self, result, direction, start_point=None):
"""An abstract method for solving sub-problem
non-optimal/heuristically/locally
:param result: stores and makes some manipulations with the CG results
:type result: Results
:param direction: Given vector
:type direction: ndarray
:param start_point: Starting point for the solver, defaults to ``None``
:type start_point: ndarray or None
:return: Solution point (ndarray), primal bound, dual bound,\
flag if the primal bound is feasible
:rtype: tuple
"""
pass
[docs] @abstractmethod
def global_solve(self, result, direction, start_point=None):
"""An abstract method for solving
sub-problem globally/near-optimal or calling an exact solver
:param result: stores and makes some manipulations with the CG results
:type result: Results
:param direction: Given vector
:type direction: ndarray
:param start_point: Starting point for the solver, defaults to ``None``
:type start_point: ndaray or None
:return: Solution point (ndarray), primal bound, dual bound,\
flag if the primal bound is feasible
:rtype: tuple
"""
pass