VeraGridEngine.Utils.MIP package

Subpackages

Submodules

VeraGridEngine.Utils.MIP.gslv_interface module

VeraGridEngine.Utils.MIP.mip_interface_template module

This module abstracts the synthax of PuLP out so that in the future it can be exchanged with some other solver interface easily

class VeraGridEngine.Utils.MIP.mip_interface_template.AbstractLpModel(solver_type: MIPSolvers, name: str)[source]

Bases: ABC

Abstract base class for LP/MIP models.

INFINITY: float = 1e+20
OPTIMAL: Any
abstractmethod add_bin(name: str = '') Any[source]

add binary variable.

abstractmethod add_cst(cst: Any, name: str = '') Any[source]

Add a constraint.

abstractmethod add_int(lb: int, ub: int, name: str = '') Any[source]

Add an integer variable.

abstractmethod add_var(lb: float, ub: float, name: str = '') Any[source]

Add a continuous variable.

abstractmethod fobj_value() float[source]

Get the objective value.

abstractmethod static get_dual_value(x: Any) float[source]

Return the dual value of a constraint.

abstractmethod static get_value(x: Any) float[source]

Return the numerical value of a variable/expression.

abstractmethod is_mip() bool[source]

Return True if model has integer variables.

logger
abstractmethod minimize(obj_function: Any)[source]

Define minimization objective.

abstractmethod model_as_string() str[source]

Return model string representation (LP)

name
originally_infeasible: bool
relaxed_slacks: List[Tuple[int, Any, float]]
abstractmethod save_model(file_name: str)[source]

Export the model to LP/MPS for debugging.

abstractmethod static set_var_bounds(var: Any, lb: float, ub: float)[source]

Modify variable bounds.

abstractmethod solve(robust: bool = False, show_logs: bool = False, progress_text: Callable[[str], None] | None = None) int[source]

Solve the optimization problem.

solver_type
abstractmethod status2string(stat: Any) str[source]

Convert solver status to readable string.

abstractmethod static sum(exprs: Iterable) Any[source]

Sum of expressions.

VeraGridEngine.Utils.MIP.ortools_interface module

VeraGridEngine.Utils.MIP.pulp_interface module

This module abstracts the synthax of PuLP out so that in the future it can be exchanged with some other solver interface easily

class VeraGridEngine.Utils.MIP.pulp_interface.PulpLpModel(solver_type: MIPSolvers)[source]

Bases: AbstractLpModel

LPModel implementation for PuLP

INFINITY: float = 1e+20
OPTIMAL: Any = 1
add_bin(name: str = '') LpVariable[source]

Make integer LP var :param name: name (optional) :return: LpVar

add_cst(cst: LpConstraint | bool, name: str = '') LpConstraint | int[source]

Add constraint to the model :param cst: constraint object (or general expression) :param name: name of the constraint (optional) :return: Constraint object

add_int(lb: int, ub: int, name: str = '') LpVariable[source]

Make integer LP var :param lb: lower bound :param ub: upper bound :param name: name (optional) :return: LpVar

add_var(lb: float, ub: float, name: str = '') LpVariable[source]

Make floating point LP var :param lb: lower bound :param ub: upper bound :param name: name (optional) :return: LpVar

fobj_value() float[source]

Get the objective function value :return:

static get_dual_value(x: LpConstraint) float[source]

Get the dual value of a variable stored in a numpy array of objects :param x: constraint :return: result or zero

get_solver(show_logs: bool = False)[source]
Parameters:

show_logs

Returns:

static get_value(x: float | int | LpVariable | LpAffineExpression | LpConstraint | Any) float[source]

Get the value of a variable stored in a numpy array of objects :param x: solver object (it may be a LP var or a number) :return: result or zero

is_mip()[source]

Is this odel a MIP? :return:

minimize(obj_function: LpAffineExpression)[source]

Set the objective function with minimization sense :param obj_function: expression to minimize

model
model_as_string() str[source]

Return the LP representation :return: string

save_model(file_name: str = 'ntc_opf_problem.lp') None[source]

Save problem in LP format :param file_name: name of the file (.lp or .mps supported)

static set_var_bounds(var: LpVariable, lb: float, ub: float)[source]

Modify the bounds of a variable :param var: LpVar instance to modify :param lb: lower bound value :param ub: upper bound value

solve(robust: bool = False, show_logs: bool = False, progress_text: Callable[[str], None] | None = None) int[source]

Solve the model :param robust: In this interface, this is useless :param show_logs: In this interface, this is useless :param progress_text: progress function pointer :return:

status2string(stat: int) str[source]

Convert the PuLP status to a string :param stat: :return:

static sum(cst) LpAffineExpression[source]

Add sum of the constraints to the model :param cst: constraint object (or general expression) :return: Constraint object

VeraGridEngine.Utils.MIP.pulp_interface.get_lp_var_value(x: float | LpVariable) float[source]

Get the value of a variable stored in a numpy array of objects :param x: soe object (it may be a LP var or a number) :return: result or previous numeric value

VeraGridEngine.Utils.MIP.pulp_interface.get_pulp_available_mip_solvers() List[str][source]

Get a list of candidate solvers :return:

VeraGridEngine.Utils.MIP.selected_interface module

Uncomment the appropriate interface imports to use: Pulp or OrTools

VeraGridEngine.Utils.MIP.selected_interface.get_available_mip_frameworks() List[MIPFramework][source]

Get list of available frameworks :return: List[MIPFramework]

VeraGridEngine.Utils.MIP.selected_interface.get_available_mip_solvers(tpe: MIPFramework) List[str][source]

Get the solvers available in the selected interface :param tpe: :return:

VeraGridEngine.Utils.MIP.selected_interface.get_model_instance(tpe: MIPFramework, solver_type: MIPSolvers) PulpLpModel | None[source]

Get an instance of the solver framework and the selected solver :param tpe: MIPInterface framework :param solver_type: MIPSolvers :return: OrToolsLpModel or PulpLpModel

VeraGridEngine.Utils.MIP.selected_interface.join(init: str, vals: List[int], sep='_')[source]

Generate naming string :param init: initial string :param vals: concatenation of indices :param sep: separator :return: naming string

VeraGridEngine.Utils.MIP.selected_interface.lpDot(mat: csc_matrix, arr: ndarray[tuple[Any, ...], dtype[object_]]) ndarray[tuple[Any, ...], dtype[object_]][source]

CSC matrix-vector or CSC matrix-matrix dot product (A x b) :param mat: CSC sparse matrix (A) :param arr: dense vector or matrix of object type (b) :return: vector or matrix result of the product

VeraGridEngine.Utils.MIP.selected_interface.lpDot1D_changes(mat: csc_matrix, arr: ndarray[tuple[Any, ...], dtype[object_]]) Tuple[ndarray[tuple[Any, ...], dtype[object_]], List[int]][source]

CSC matrix-vector or CSC matrix-matrix dot product (A x b) :param mat: CSC sparse matrix (A) :param arr: dense vector or matrix of object type (b) :return: vector or matrix result of the product

Module contents