VeraGridEngine.Utils.MIP.SimpleMip packageο
Submodulesο
VeraGridEngine.Utils.MIP.SimpleMip.highs moduleο
VeraGridEngine.Utils.MIP.SimpleMip.lpmodel moduleο
- class VeraGridEngine.Utils.MIP.SimpleMip.lpmodel.LpModel(solver_type: MIPSolvers = HIGHS)[source]ο
Bases:
objectSimpleMIP
- INFINITY = 1e+20ο
- OPTIMAL = 100ο
- add_cst(cst: LpCst | bool, name: str = '') LpCst | 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 = '') LpVar[source]ο
Make integer LP var :param lb: lower bound :param ub: upper bound :param name: name (optional) :return: LpVar
- add_var(lb: float = 0.0, ub: float = 1e+20, name: str = '') LpVar[source]ο
Make floating point LP var :param lb: lower bound :param ub: upper bound :param name: name (optional) :return: LpVar
- add_vars(size: int, lb: float = 0.0, ub: float = 1e+20, name: str = '', is_int=False) List[LpVar][source]ο
Make array of LP vars :param size: number of variables :param lb: lower bound :param ub: upper bound :param name: name (optional) :param is_int: create integer variables :return: LpVar
- copy(copy_results: bool = False) LpModel[source]ο
Deep copy of this :param copy_results: copy the results too? :return: LpModel
- get_array_value(arr: List[LpVar]) ndarray[source]ο
Get the array of var values :param arr: array of variables :return:
- get_coefficients_data() Tuple[ndarray, csc_matrix, ndarray][source]ο
Returns the coefficient matrix :return:
- get_dual_value(var: LpVar | LpCst | LpExp | float | int) float[source]ο
Get the dual value of a variable :param var: LpVar object :return: float
- get_obj_coefficient(var: LpVar) float[source]ο
Get the coefficient of a variable, if not found, return 0.0
- get_value(var: LpVar | LpCst | LpExp | float | int) float[source]ο
Get the value of a variable :param var: LpVar object :return: float
- get_var_data() Tuple[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]], List[int]][source]ο
Get arrays related to the variable bounds and the objective function coefficients :return: lower bounds, f obj coefficients, upper bounds, list of integer varsβ indices
- loggerο
- maximize(obj_function: LpExp)[source]ο
Set the objective to maximize :param obj_function: Expression
- minimize(obj_function: LpExp)[source]ο
Set the objective to minimize :param obj_function: Expression
- originally_infeasibleο
- save_model(file_name='ntc_opf_problem.lp')[source]ο
Save model in lp or mps format :param file_name: name of the file
- set_solution(col_values: ndarray[tuple[Any, ...], dtype[float64]], col_duals: ndarray[tuple[Any, ...], dtype[float64]], row_values: ndarray[tuple[Any, ...], dtype[float64]], row_duals: ndarray[tuple[Any, ...], dtype[float64]], f_obj: float, is_optimal: bool)[source]ο
Set solution from the MIP solver :param col_values: array of variablesβ values :param col_duals: array of variable dual values :param row_values: array of constraint values :param row_duals: array of constraint dual values :param f_obj: value of the objective function :param is_optimal: is optimal
- solve(robust=True, show_logs=False, progress_text: Callable[[str], None] | None = None) int[source]ο
Solve the model :param robust: Relax the problem if infeasible :param show_logs: Show logs :param progress_text: Function pointer to print the status :return: integer value matching OPTIMAL or not
- solver_typeο
VeraGridEngine.Utils.MIP.SimpleMip.lpobjects moduleο
- class VeraGridEngine.Utils.MIP.SimpleMip.lpobjects.LpCst(linear_expression: LpExp, sense: str, coefficient: float, name='', internal_index: int = 0)[source]ο
Bases:
objectConstraint
- add_term(var: LpVar, coeff: float)[source]ο
Add a term to the constraint :param var: Variable :param coeff: coefficient
- coefficientο
- get_bounds() Tuple[float, float][source]ο
Get the constraint bounds :return: lhs <= constraint <= rhs
- get_rhs() float[source]ο
get the final right-hand side :return: coefficient minus the expression offset
- linear_expressionο
- nameο
- senseο
- set_index(index: int) None[source]ο
Set the internal indexing :param index: constraint index in the solver
- property termsο
Terms property of the linear expression :return:
- class VeraGridEngine.Utils.MIP.SimpleMip.lpobjects.LpExp(variable: LpVar = None, coefficient: float = 1.0, offset: float = 0.0)[source]ο
Bases:
objectExpression
- offsetο
- class VeraGridEngine.Utils.MIP.SimpleMip.lpobjects.LpVar(name: str, lower_bound: float = 0.0, upper_bound: float = 1e+20, is_integer: bool = False, internal_idx: int = 0, hash_id: int | None = None)[source]ο
Bases:
objectVariable
- is_integer: boolο
- lower_bound: floatο
- nameο
- set_index(index: int) None[source]ο
Set the internal indexing :param index: var index in the solver
- upper_bound: floatο