rbatools.rba_lp module
Classes
class LinearProblem (ancestors: ProblemMatrix)-
Attributes
A:scipy.sparse.coo_matrix- Lefthandside of constraint Matrix (aka Constraint Matrix)
b:numpy.array- Righthandside of Constraint Matrix
row_signs:list- Type of constraints ('E' for equality 'L' for lower-or-equal inequality) –> Ax=b or Ax<=b
f:numyp.array- Objective function linear get_coefficients
LB:numpy.array- Lower bounds of decision-variables
UB:numpy.array- Upper bounds of decision-variables
row_names:list- Names of constraints
col_names:list- Names of decision-variables
rowIndicesMap:dict- Dictionary mapping constraint names to their numeric index (generated automatically)
colIndicesMap:dict- Dictionary mapping variable names to their numeric index (generated automatically)
lp_solver:str- Selected linear problem solver.
_lp_solver:rbatools.rba_lp._Solver(anydescendentclass)object
Methods
def __init__(self, *matrix, lp_solver='cplex')-
Initiates LP object. If provided with an rbatools.rba_problem_matrix.ProblemMatrix object as argument, assumes its attributes. If not provided with an ProblemMatrix object, initiates as empty LP object. Parameters
matrix:ProblemMatrix- Optional
lp_solver:str- Specifies which LP-solver should be used ('cplex' or 'swiglpk') Default: 'cplex'
def add_matrix(self, matrix)-
Merges the Problem with the one provided as input-argument to this method.
Matrix elements unique to input-matrix are added. Elements occuring in both matrices are overwritten with the value from new matrix. Generates CPLEX problem from merged problem.
Parameters
matrix:ProblemMatrix- The matrix with elements to be added
def build_lp(self)-
Constructs an LP-object, based on solver attribute
Returns
bool:Boolean,indicatingwhetherLP-objectcouldbeconstructed
def get_constraint_types(self, constraints=[])-
Returns constraint types for specified rows. (E: = ; L: <= ; G:>=)
Parameters
constraints : list of row names.
Returns
dict- Dictionary with constraint-IDs as keys and type identification-characters as values.
def get_lb(self, variables)-
Returns lower bounds for specified columns.
Parameters
variables : list of column names.
Returns
dict- Dictionary with variable-IDs as keys and lower bounds as values.
def get_objective(self, variables=[])-
Returns objective coefficients for specified columns.
Parameters
variables : list of column names.
Returns
dict- Dictionary with variable-IDs as keys and objective coefficients as values.
def get_problem_coefficients(self, inputTuples=[])-
Returns problem coefficints of constraint matrix.
Parameters
inputTuples : list of coordinate tuples of coefficients (row,col).
Returns
dict- Dictionary with index tuples as keys and matrix coefficients as values.
def get_right_hand_side(self, constraints=[])-
Returns RHS values for specified rows.
Parameters
constraints : list of row names.
Returns
dict- Dictionary with constraint-IDs as keys and RHS-values as values.
def get_ub(self, variables)-
Returns upper bounds for specified columns.
Parameters
variables : list of column names.
Returns
dict- Dictionary with variable-IDs as keys and upper bounds as values.
def initiate_lp_solver(self)def return_dual_values(self)-
Returns (dual) solution vector.
Returns
dict : Problem constraints as keys and dual values (shadow prices) as values.
def return_objective_value(self)-
Returns objective value, after solving the problem.
Returns
float:objectivevalue
def return_primal_values(self)-
Returns (primal)solution vector.
Returns
dict : Problem variables as keys and solution values as values.
def return_solution_status(self)-
Returns solution status, after solving the problem.
Returns
str:solutionstatus- optimal, feasible or infeasible solution stati returned by solvers: optimal: swiglpk -> GLP_OPT cplex -> 1 feasible: swiglpk -> GLP_FEAS feasible_only_before_unscaling: cplex -> 5
def set_constraint_types(self, inputDict)-
Sets the type of specified constraints. (E: = ; L: <= ; G:>=)
Parameters
inputDict:dict- Constraint IDs as keys and constraint type as values
def set_lb(self, inputDict)-
Sets variable lower bounds to specified values.
Parameters
inputDict:dict- Variable IDs as keys and lower bounds as values
def set_objective(self, inputDict)-
Sets coefficients in objective function to specified values.
Parameters
inputDict:dict- Variable IDs as keys and objective coefficient as values
def set_problem_coefficients(self, input)-
Sets coefficients in constraint matrix.
Parameters
inputDict:dict- Dictionary with index tuples as keys and matrix coefficients as values.
def set_right_hand_side(self, inputDict)-
Sets the rhs-value of specified constraints.
Parameters
inputDict:dict- Constraint IDs as keys and rhs-values as values.
def set_ub(self, inputDict)-
Sets variable upper bounds to specified values.
Parameters
inputDict:dict- Variable IDs as keys and upper bounds as values
def solve_lp(self)-
solves linear problem
def unscale_lp(self)-
Unscale LP
def update_matrix(self, matrix, Ainds=None, Binds=None, CTinds=None, LBinds=None, UBinds=None, ModifiedProblem=True)-
Overwrites coefficients with new values from argument 'matrix'.
Parameters
matrix:ProblemMatrix- The matrix with elements to be added
Ainds:listoftuples- List of index-pair tuples [(row_coeff1,col_coeff1),(row_coeff2,col_coeff2),…], specifying which elements are updated. Default is None (then all elements of argument matrix (present in both matrices) are taken to update)
Binds:list- List of constraint-IDs for indices of the RHS, specifying which RHS Values are updated. Default is None (then all constraints (present in both matrices) are taken to update)
CTinds:list- List of constraint-IDs, specifying which row_signs are updated. Default is None (then all constraint types (present in both matrices) are taken to update)
LBinds:list- List of variable-IDs, specifying which lower-bounds values are updated. Default is None (then all variables (present in both matrices) are taken to update)
UBinds:list- List of variable-IDs, specifying which upper-bounds values are updated. Default is None (then all variables (present in both matrices) are taken to update)
ModifiedProblem:boolean- Whether problem has been modifed. If false own lp components are fully replaced by input, if rows and col names are identical .
Inherited members