rbatools.rba_problem
module
Classes
class ProblemRBA
-
Class holding RBA-problem as mathematical manifestation of the RBA-model.
Attributes
classicRBA
:boolean
- Indicates that the problem is a classic RBA-problem (as defined in RBApy)
ClassicRBAmatrix
:rba.ConstraintMatrix.matrix
object
Mu
:float
- Current Growth rate as numeric value
LP
:LinearProblem
object
Enzyme_FWcapacities
:list
- List of constraint IDs, which represent forward efficiencies of enzymes Created by method 'extract_constraint_types'
Enzyme_BWcapacities
:list
- List of constraint IDs, which represent backward efficiencies of enzymes Created by method 'extract_constraint_types'
ProcessCapacities
:list
- List of constraint IDs, which represent net efficiencies of processes Created by method 'extract_constraint_types'
Metabolites
:list
- List of constraint IDs, which represent mass balances of metabolites Created by method 'extract_constraint_types'
CompartmentDensities
:list
- List of constraint IDs, which represent compartment capacities Created by method 'extract_constraint_types'
Reactions
:list
- List of constraint IDs, which represent metabolic reactions Created by method 'extract_variable_types'
Enzymes
:list
- List of constraint IDs, which represent enzymes, associated with metabolic reactions Created by method 'extract_variable_types'
Processes
:list
- List of constraint IDs, which represent process machineries Created by method 'extract_variable_types'
MuDepIndices_A
:list
- List of tuples holding rows (constraint IDs) and columns (variable IDs) of constraint-matrix coefficients (LHS), which depend on the growth rate. Created by method 'find_growth_rate_dependencies'
MuDepIndices_b
:list
- List of constraint IDs, whos RHS depend on the growth rate Created by method 'find_growth_rate_dependencies'
MuDepIndices_LB
:list
- List of variable IDs, whos lower-bounds depend on the growth rate Created by method 'find_growth_rate_dependencies'
MuDepIndices_UB
:list
- List of variable IDs, whos upper-bounds depend on the growth rate Created by method 'find_growth_rate_dependencies'
Solved
:bool
- Booelean indicating wheter Problem has been successfully solved, according to the acceptable solution statuses provided to the solve_lp-method. Created by method 'solve_lp'
SolutionStatus
:int
- Numerical value indicating the solution-status of the problem. Consult CPLEX documentation for their meaning. Created by method 'solve_lp'
ObjectiveValue
:float
- Numeric value of the objective function after optimisation by CPLEX. Created by method 'solve_lp'
SolutionValues
:dict
- Solution vector after optimisation by CPLEX. (Dictionary with variable IDs as keys and numeric values as values) Created by method 'solve_lp'
DualValues
:dict
- Vector of dual-values after optimisation by CPLEX. (Dictionary with constraint IDs as keys and numeric values as values) Created by method 'solve_lp'
Methods
def __init__(self, matrix, ModelStructure, lp_solver='cplex')
-
Initiates rbatools.rba_problem.ProblemRBA from supplied rba.ConstraintMatrix object.
Makes sure the problem is consistent and optimisable.
Parameters
matrix
:rba.ConstraintMatrix
- ModelStructure rbatools.rba_model_structure.ModelStructureRBA
lp_solver
:str
- Specifies which LP-solver should be used ('cplex' or 'swiglpk') Default: 'cplex'
def build_classic_matrix(self, Mu)
-
Builds standard RBA-matrix according to growth-rate
Parameters
Mu
:float
- Growth rate
def calculate_left_hand_side(self, constraints=[])
-
Calculates value of problem's lefthand side (after multiplying with solution-vector).
Parameters
constraints
:str
orlist
ofstr
- Constraints to retreive the LHS-value for. Either constraint ID or list of constraint IDs to specify the LHS-value of which constraint to look up. This is an optional input; if not provided all constraint are looked up.
Returns
dict
- Dictionary with constraint-IDs as keys and LHS-value as values.
def clear_objective(self)
-
Sets all coefficients of the objective function to zero.
def evaluate_parameter(self, definition)
def extract_constraint_types(self, ModelStructure)
-
Extracts information on the different constraint types in the standard RBA-matrix.
AddsAttributes
:Enzyme_FWcapacities
,Enzyme_BWcapacities
,ProcessCapacities
,- Metabolites and CompartmentDensities
def extract_variable_types(self, ModelStructure)
-
Extracts information on the different variable types in the standard RBA-matrix.
AddsAttributes
:Enzymes
,Reactions
and
Processes
def find_growth_rate_dependencies(self, ModelStructure)
-
Extracts information on the growth-rate dependent LP-coefficients.
AddsAttributes
:MuDepIndices_A
,MuDepIndices_b
,MuDepIndices_LB
- and MuDepIndices_UB
def get_constraint_types(self, constraints=[])
-
Extracts type of constraints.
Parameters
constraints
:str
orlist
ofstr
- Constraints to retreive the type for. Either constraint ID or list of constraint IDs to specify the type of which constraint to look up. This is an optional input; if not provided all constraint are looked up.
Returns
dict
- Dictionary with constraint-IDs as keys and type identification-characters as values.
def get_lb(self, variables=[])
-
Returns lower bounds of problem variables.
Parameters
variables
:str
list
ofstr
- Variables to retreive the objective coefficients for. Either variable ID or list of variable IDs to specify the coefficients of which variables to look up. This is an optional input; if not provided all variables are looked up.
Returns
dict
- Dictionary with variable-IDs as keys and lower bounds as values.
def get_objective(self, variables=[])
-
Returns objective coefficient of variables in problem.
Parameters
variables
:str
orlist
ofstr
- Variables to retreive the objective coefficients for. Either variable ID or list of variable IDs to specify the coefficients of which variables to look up. This is an optional input; if not provided all variables are looked up.
Returns
dict
- Dictionary with variable-IDs as keys and objective coefficients as values.
def get_problem_coefficients(self, inputTuples=[])
-
Returns coefficients of LHS of problem.
Parameters
inputTuples : tuple or list of tuples. Tuples hold row and column indices. [('row1','col1'),('row2','col2'),…] or ('row1','col1').
Returns
dict
- Dictionary with index tuples as keys and matrix coefficients as values.
def get_right_hand_side(self, constraints=[])
-
Extracts coefficients of problem's righthand side (B-vector).
Parameters
constraints
:str
orlist
ofstr
- Constraints to retreive the objective coefficients for. Either constraint ID or list of constraint IDs to specify the RHS of which constraint to look up. This is an optional input; if not provided all constraint are looked up.
Returns
dict
- Dictionary with constraint-IDs as keys and RHS-values as values.
def get_ub(self, variables=[])
-
Returns upper bounds of problem variables.
Parameters
variables
:str
list
ofstr
- Variables to retreive the objective coefficients for. Either variable ID or list of variable IDs to specify the coefficients of which variables to look up. This is an optional input; if not provided all variables are looked up.
Returns
dict
- Dictionary with variable-IDs as keys and upper bounds as values.
def invert_objective(self)
-
Changes sign (optimisation-sense) of objective function.
def set_constraint_types(self, inputDict)
-
Sets type of constraints.
E
: = ;L
: <= ;G
: >=
Parameters
inputDict
:dict
- Dictionary with constraint-IDs as keys and type identification-character as values. ({'col1':'E','col2':'L', …}).
def set_growth_rate(self, Mu, ModelStructure, keepParameters={})
-
Changes growth-rate of problem and sets all associated coefficients.
Can be provided with 'keepParameters' argument to define problem coefficients which should remain unchanged.
Parameters
Mu
:float
- Growth rate
- ModelStructure : RBA_ModellStructure object.
keepParameters
:dict
- Dictionary indicating which elements of the linear problem should not be affected when setting growth-rate. Possible keys of dictionary: 'LHS': List of index-tuples (constraint-ID,variable-ID), indicating elements of the lefthandside (constraint-matrix). 'RHS': List of constraint IDs, indicating elements of the righthandside (b-vector). 'LB': List of variable-IDs, indicating elements of the lower-bound vector. 'UB': List of variable-IDs, indicating elements of the upper-bound vector. Default: keepParameters=None
def set_lb(self, inputDict)
-
Set lower-bounds of the problem variables.
Parameters
inputDict
:dict
- Dictionary with variable-IDs as keys and new numeric values as values. ({'col1':42,'col2':9000, …}).
def set_objective(self, inputDict)
-
Sets objective function coefficients.
Parameters
inputDict
:dict
- Dictionary with variable-IDs as keys and new numeric values as values. ({'col1':42,'col2':9000, …}).
def set_problem_coefficients(self, inputDict)
-
Set coefficients of the problems' LHS (constraint matrix).
Parameters
inputDict
:dict
- Dict with index-tuples ('row1','col1') as keys and new numeric values as values. ({('row1','col1'):42,('row2','col2'):9000, …}).
def set_right_hand_side(self, inputDict)
-
Set coefficients of the problems' RHS (b-vector). Parameters
inputDict
:dict
- Dictionary with constraint-IDs as keys and new numeric values as values. ({'row1':42,'row2':9000, …}).
def set_ub(self, inputDict)
-
Set upper-bounds of the problem variables.
Parameters
inputDict
:dict
- Dictionary with variable-IDs as keys and new numeric values as values. ({'col1':42,'col2':9000, …}).
def solve_lp(self, feasible_stati=['optimal', 'feasible'], try_unscaling_if_sol_status_is_feasible_only_before_unscaling=True)
-
Solves Linear RBA problem.
When solution-status is amongst the user-defined feasible statuses; boolean 'Solved' is set to True and 'ObjectiveValue', 'SolutionValues' and 'DualValues' are stored as attributes.
Parameters
feasible_stati
:list
ofint
- List with identifiers of acceptable solution statuses. (consult ILOG-CPLEX documentation for information on them). Default: feasible_stati=["optimal","feasible"]
try_unscaling_if_sol_status_is_feasible_only_before_unscaling :bool Try re-solving problem with less aggressive scaling, when solution status is infeasible after unscaling Default: True
def update_growth_rate(self, Mu, keepParameters={}, ModifiedProblem=False)
-
Changes growth-rate of problem and sets all associated coefficients.
Can be provided with 'keepParameters' argument to define problem coefficients which should remain unchanged.
Parameters
Mu
:float
- Growth rate
keepParameters
:dict
- Dictionary indicating which elements of the linear problem should not be affected when setting growth-rate. Possible keys of dictionary: 'LHS': List of index-tuples (constraint-ID,variable-ID), indicating elements of the lefthandside (constraint-matrix). 'RHS': List of constraint IDs, indicating elements of the righthandside (b-vector). 'LB': List of variable-IDs, indicating elements of the lower-bound vector. 'UB': List of variable-IDs, indicating elements of the upper-bound vector. Default: keepParameters=None
ModifiedProblem
:bool
- Default: False