VeraGridEngine.Utils.MIP.SimpleMip package

Submodules

VeraGridEngine.Utils.MIP.SimpleMip.highs module

VeraGridEngine.Utils.MIP.SimpleMip.highs.solve_with_highs(problem: LpModel, verbose: int = 0)[source]

Solve MIP using Highs via its python interface :param problem: Problem to be solved (results are inserted in-place) :param verbose: print info? for values > 0

VeraGridEngine.Utils.MIP.SimpleMip.lpmodel module

class VeraGridEngine.Utils.MIP.SimpleMip.lpmodel.LpModel(solver_type: MIPSolvers = HIGHS)[source]

Bases: object

SimpleMIP

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

constraints: List[LpCst]
copy(copy_results: bool = False) LpModel[source]

Deep copy of this :param copy_results: copy the results too? :return: LpModel

fobj_value() float[source]

Get the objective function value :return:

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_objective_value() float[source]

Get the objective function value :return: float

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

is_minimize() bool[source]

Minimize? :return: bool

is_mip()[source]

Is this model a MIP? :return:

is_optimal() bool[source]
Returns:

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

objective: LpExp
originally_infeasible
print_solution()[source]

Print available solution

relaxed_slacks: List[Tuple[int, LpVar, float]]
save_model(file_name='ntc_opf_problem.lp')[source]

Save model in lp or mps format :param file_name: name of the file

save_model_to_lp(filename: str)[source]

Save model to LP file :param filename: LP file path

save_model_to_mps(filename)[source]

Save the model to MPS :param filename: MPS file path

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

solution_available() bool[source]

Is there a solution loaded? :return: true / false

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
status2string(status: int) str[source]
static sum(expr: LpExp | Iterable) LpExp[source]

create sum of the expression :param expr: LpExp object (or general expression) :return: LpExp object

variables: List[LpVar]
VeraGridEngine.Utils.MIP.SimpleMip.lpmodel.get_available_mip_solvers() List[str][source]

Get a list of candidate solvers :return: list of solver names

VeraGridEngine.Utils.MIP.SimpleMip.lpmodel.set_var_bounds(var: LpVar, 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.SimpleMip.lpobjects module

class VeraGridEngine.Utils.MIP.SimpleMip.lpobjects.LpCst(linear_expression: LpExp, sense: str, coefficient: float, name='', internal_index: int = 0)[source]

Bases: object

Constraint

add_term(var: LpVar, coeff: float)[source]

Add a term to the constraint :param var: Variable :param coeff: coefficient

add_var(var: LpVar)[source]

Add a term to the constraint :param var: Variable

coefficient
copy() LpCst[source]

Make a deep copy of this constraint :return: Constraint

get_bounds() Tuple[float, float][source]

Get the constraint bounds :return: lhs <= constraint <= rhs

get_index() int[source]

Get internal index :return: int

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: object

Expression

copy() LpExp[source]

Make a deep copy of this expression :return: LpExp

offset
terms: Dict[LpVar, float]
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: object

Variable

copy() LpVar[source]

Make a deep copy of this variable :return:

get_index() int[source]

Get the internal indexing :return: int

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

Module contents