VeraGridEngine.Utils.MIP packageο
Subpackagesο
- VeraGridEngine.Utils.MIP.SimpleMip package
- Submodules
- VeraGridEngine.Utils.MIP.SimpleMip.highs module
- VeraGridEngine.Utils.MIP.SimpleMip.lpmodel module
LpModelLpModel.INFINITYLpModel.OPTIMALLpModel.add_cst()LpModel.add_int()LpModel.add_var()LpModel.add_vars()LpModel.constraintsLpModel.copy()LpModel.fobj_value()LpModel.get_array_value()LpModel.get_coefficients_data()LpModel.get_dual_value()LpModel.get_obj_coefficient()LpModel.get_objective_value()LpModel.get_value()LpModel.get_var_data()LpModel.is_minimize()LpModel.is_mip()LpModel.is_optimal()LpModel.loggerLpModel.maximize()LpModel.minimize()LpModel.objectiveLpModel.originally_infeasibleLpModel.print_solution()LpModel.relaxed_slacksLpModel.save_model()LpModel.save_model_to_lp()LpModel.save_model_to_mps()LpModel.set_solution()LpModel.solution_available()LpModel.solve()LpModel.solver_typeLpModel.status2string()LpModel.sum()LpModel.variables
get_available_mip_solvers()set_var_bounds()
- VeraGridEngine.Utils.MIP.SimpleMip.lpobjects module
- Module contents
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:
ABCAbstract base class for LP/MIP models.
- INFINITY: float = 1e+20ο
- OPTIMAL: Anyο
- abstractmethod add_var(lb: float, ub: float, name: str = '') Any[source]ο
Add a continuous variable.
- 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.
- loggerο
- nameο
- originally_infeasible: boolο
- relaxed_slacks: List[Tuple[int, Any, float]]ο
- 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ο
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:
AbstractLpModelLPModel 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
- 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
- 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
- minimize(obj_function: LpAffineExpression)[source]ο
Set the objective function with minimization sense :param obj_function: expression to minimize
- modelο
- 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
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