Engine
class¶
Bases: ABC
Abstract base class for optimization engines.
The Engine
class is a base class that provides a common interface for interacting with different solvers. It
serves as a foundation for representing and utilizing various solver implementations, such as Gurobi, CPLEX,
and others.
By inheriting from this base class, specific engine classes can be developed to implement solver-specific
functionality while adhering to the common interface defined by the Engine
class.
This decoupling from the specific solvers allows for greater flexibility and interchangeability of solver implementations within an optimization model. It promotes code reuse and simplifies the process of integrating different solvers into an application.
The Engine
class defines a set of abstract methods that must be implemented by concrete engine classes. These
methods include solving the optimization model, adding variables and constraints, setting the objective function,
and configuring solver-specific parameters.
Source code in pyorlib/engines/engine.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
Attributes¶
name
abstractmethod
property
¶
Get the name of the concrete solver.
RETURNS | DESCRIPTION |
---|---|
str
|
The name of the concrete solver implementation. |
constraints
abstractmethod
property
¶
constraints: List[Element]
Get the list of constraints in the model.
RETURNS | DESCRIPTION |
---|---|
List[Element]
|
The list of constraint objects. |
objective_value
abstractmethod
property
¶
Get the objective value for the current solution.
RETURNS | DESCRIPTION |
---|---|
float | None
|
The objective value, or None if no solution exists. |
objective_expr
abstractmethod
property
¶
objective_expr: Element | None
Get the objective expression object.
RETURNS | DESCRIPTION |
---|---|
Element | None
|
The objective expression, or None if not set. |
solution_status
abstractmethod
property
¶
solution_status: SolutionStatus
Get the solution status.
RETURNS | DESCRIPTION |
---|---|
SolutionStatus
|
The status of the current solution. |
Functions¶
add_variable
abstractmethod
¶
add_variable(name: str, value_type: ValueType, lower_bound: float = 0, upper_bound: float = inf) -> Variable
Add a new variable to the engine.
PARAMETER | DESCRIPTION |
---|---|
name |
The name of the variable.
TYPE:
|
value_type |
The value type of the variable.
TYPE:
|
lower_bound |
The lower bound of the variable. Default is 0.
TYPE:
|
upper_bound |
The upper bound of the variable. Default is infinity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Variable
|
The created variable object. |
Source code in pyorlib/engines/engine.py
add_constraint
abstractmethod
¶
set_objective
abstractmethod
¶
set_objective(opt_type: OptimizationType, expression: Element) -> Element
Defines the objective function.
PARAMETER | DESCRIPTION |
---|---|
opt_type |
The type of optimization to be performed.
TYPE:
|
expression |
The objective expression.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Element
|
The objective function. |