Solvers#
MATLAB functions in RAVEN/src/solver of the RAVEN toolbox.
Functions#
Function |
Summary |
|---|---|
Check if a solver result is feasible and optimal. |
|
Find the minimal set of fluxes that satisfy the model. |
|
Optimize an LP or MILP formulated in COBRA terms. |
|
Set the solver for RAVEN. |
|
Solve a linear programming problem. |
|
Improve LP conditioning by splitting wide columns. |
Reference#
checkSolution#
function [isFeasible, isOptimal]=checkSolution(res)
Check if a solver result is feasible and optimal.
Parameters
res: structthe output structure from optimizeProb.
Returns
isFeasible: logicaltrue if the solution is feasible.
isOptimal: logicaltrue if the solution is optimal.
Examples
[isFeasible, isOptimal] = checkSolution(res);
getMinNrFluxes#
function [x,I,exitFlag]=getMinNrFluxes(model, varargin)
Find the minimal set of fluxes that satisfy the model.
Uses mixed integer linear programming to find the minimal set of fluxes that satisfy the model.
Parameters
model: structa model structure.
Name-Value Arguments
toMinimize: cell or logical or doubleeither a cell array of reaction IDs, a logical vector with the same number of elements as reactions in the model, or a vector of indexes for the reactions that should be minimized (default model.rxns).
params: structobsolete option.
scores: doublevector of weights for the reactions. Negative scores should not have flux. Positive scores are not possible in this implementation, and they are changed to max(scores(scores<0)), or to 0 if scores has no negative entry at all. Must have the same dimension as toMinimize (find(toMinimize) if it is a logical vector) (default -1 for all reactions).
formulation: charwhich MILP formulation to build (default 'irrev'):
'irrev' : convert the model to irreversible format and use one binary per irreversible reaction, so a reversible reaction that is minimized costs two binaries. The magnitude of the fluxes is estimated with an LP first, which also provides a start solution.
'reversible' : keep the model reversible and use one binary per reaction, at the cost of a larger constraint matrix. Fewer binaries makes this the faster formulation on large problems, but it needs a solver that handles MILPs well and no LP estimate of the flux magnitudes is made, so an arbitrary large flux is assumed.
verbose: logicalif true, the MILP progression will be shown (default false).
resolveTies: logicalif true, pin the MILP's degenerate optimum to a canonical answer instead of relying on Seed alone: hold the primary (scores) objective at its optimum, then minimize the count of "on" reactions, then, among the sparsest, minimize their summed reaction-id rank (lowest ids preferred). Two extra MILP solves; best-effort, so a phase that does not converge within TimeLimit is dropped with a warning rather than changing the result. Only implemented for formulation='reversible' -- errors if combined with 'irrev'. Matches raven-toolbox's resolve_ties (raven-gecko-parity#104) (default false).
Returns
x: doublethe corresponding fluxes for the full model.
I: doublethe indexes of the reactions in toMinimize that were used in the solution.
exitFlag: doubleexit status:
1 : optimal solution found
-1 : no solution found, either because the problem is infeasible or because the solver reached its time limit before finding one
-2 : a solution was found but is not proven optimal, because the solver stopped before reaching optimality. It is returned, but it may use more fluxes than the minimum
Examples
[x, I, exitFlag] = getMinNrFluxes(model, toMinimize, params, scores);
Notes
Uses 1000 mmol/gDW/h as an arbitary large flux. Could possibly cause problems if the fluxes in the model are larger than that.
optimizeProb#
function res = optimizeProb(prob,varargin)
Optimize an LP or MILP formulated in COBRA terms.
Parameters
prob: structCOBRA-style LP/MILP problem struct to be optimised.
Name-Value Arguments
params: structsolver-specific parameters. In addition to solver parameters, the field "maxRatio" can be set to a number > 1 to improve numerical conditioning: before solving (LP only) any column whose coefficients span more than maxRatio is split via auxiliary metabolites/variables, preserving the feasible region. See splitProbForConditioning. The field is consumed here and not forwarded to the solver.
verbose: logicalif true MILP progress is shown (default true).
Returns
res: structthe output structure from the selected solver RAVENSOLVER (COBRA style). In addition to the fields set by the solver, the logical field "hitTimeLimit" is true if the solver stopped because it reached its time limit. Whatever solution is in res is then either absent or not proven optimal.
Notes
MILPs can be solved with GLPK, either RAVEN's bundled GLPK ('glpk') or the COBRA Toolbox's GLPK interface ('cobra' with GLPK as its MILP solver). A RAVEN:glpkMILP warning then recommends Gurobi, which is much faster and more reliable on larger MILPs (such as ftINIT or getMinNrFluxes on genome-scale models).
See also
splitProbForConditioning
setRavenSolver#
function setRavenSolver(solver)
Set the solver for RAVEN.
Sets the solver for RAVEN and optionally saves a default value to MATLAB startup.
Parameters
solver: charstring with solver name. The following options are available:
glpk : uses RAVEN-provided binaries. Solves LPs and MILPs; for MILPs a RAVEN:glpkMILP warning recommends Gurobi, which is much faster and more reliable on larger problems.
gurobi : requires a working Gurobi installation.
scip : requires a SCIP MEX interface. RAVEN provides a precompiled binary for Windows only.
cobra : requires a working COBRA Toolbox installation. RAVEN parses the problem to COBRA and uses the solver that is set by changeCobraSolver. MILPs are refused when COBRA's MILP solver is GLPK.
Examples
setRavenSolver(solver);
solveLP#
function [solution, hsSolOut]=solveLP(model,varargin)
Solve a linear programming problem.
Parameters
model: structa model structure.
Name-Value Arguments
minFlux: doubledetermines if a second optimization should be performed in order to get rid of loops in the flux distribution (default 0):
0 : no such optimization is performed
1 : the sum of abs(fluxes) is minimized. This is the fastest way of getting rid of loops
2 : option is deprecated
3 : the number of fluxes is minimized. This can result in the flux distributions that are the easiest to interpret. Note that this optimization can be very slow
params: structsolver parameters, forwarded to optimizeProb. Mostly obsolete, but the field "maxRatio" (a number > 1) can be set to improve numerical conditioning of ill-scaled models: any reaction whose stoichiometric coefficients span more than maxRatio is transiently split via auxiliary metabolites before solving, which preserves the feasible region (and thus the flux distribution of the original reactions). A common value is 1e6 (no splitting by default).
hsSol: structhot-start solution for the LP solver. This can significantly speed up the process if many similar optimization problems are solved iteratively. Only used if minFlux is 0 or 1.
Returns
solution: structLP solution with fields:
f : objective value
x : primal (flux distribution)
stat : exit flag (1 = optimization terminated successfully, 0 = solution is feasible but not necessarily optimal, -1 = no feasible solution found, -2 = solution found but flux minimization failed)
msg : string describing the status of the optimization
sPrice : shadow price (only reported if minFlux was 0)
rCost : reduced cost (only reported if minFlux was 0)
hsSolOut: structsolution to be used as hot-start solution (see the input parameters). Only used if minFlux is 0 or 1.
Examples
[solution, hsSolOut] = solveLP(model, minFlux, params, hsSol);
splitProbForConditioning#
function [prob, condInfo] = splitProbForConditioning(prob, maxRatio)
Improve LP conditioning by splitting wide columns.
Reformulates an LP problem to improve its numerical conditioning by splitting columns whose coefficients span more than a given ratio. In a metabolic model a column corresponds to a reaction, and a wide spread of stoichiometric coefficients within one reaction (e.g. a biomass reaction with both major substrates and trace cofactors) cannot be removed by the diagonal row/column scaling that LP solvers apply, and may lead to unreliable solutions or spurious infeasibility.
Splitting is done via auxiliary metabolites and variables that preserve the feasible region of the original problem exactly, so the values of all original variables are unchanged.
The function is meant to be called inside optimizeProb, on the COBRA-style problem struct, immediately before the problem is passed to the solver. Auxiliary rows/columns are appended after the original ones, so the augmentation can be stripped from the solver output afterwards (see condInfo).
Parameters
prob: structCOBRA-style LP problem struct, with at least the fields A, b, c, lb, ub, csense and vartype.
maxRatio: doublemaximum allowed ratio between the largest and smallest absolute coefficient within any single column.
Returns
prob: structthe (possibly) augmented problem struct. Identical to the input if no column needed splitting.
condInfo: structstruct describing the augmentation, with fields:
applied : true if any column was split
nSplits : number of auxiliary metabolite/conversion pairs added
nOrigRows : number of constraint rows before augmentation
nOrigCols : number of variables (columns) before augmentation
Examples
[prob, condInfo] = splitProbForConditioning(prob, maxRatio);
See also
optimizeProb