Cplex¶
- CPLEXParamSet(interface)[source]¶
This is a function which returns user specified CPLEX control parameters. It is not necessary to use a file like this if you want to use CPLEX default control parameters. It is intended to be a template for individual users to save with their own problem specific settings for CPLEX.
- USAGE
cpxControl = CPLEXParamSet (solver)
- INPUT
interface – ‘tomlab_cplex’(default) or ‘ILOGcomplex’
- OUTPUT
cpxControl – user specified CPLEX control parameters
Example
% (1) Paddy saves this file as CPLEXParamSetPaddyLPJob1 % (2) Paddy edits CPLEXParamSetPaddyLPJob1 in a problem specific way % (3) Paddy then passes the name of this file to solveCobraLP_CPLEX using something like:
[solution, LPProblem] = solveCobraLP_CPLEX(LPProblem, [], [], [], ‘CPLEXParamSetPaddyLPJob1’);
Note
CPLEX consists of 4 different LP solvers which can be used to solve LP problems you can control which of the solvers, e.g. simplex or interior point solve using the CPLEX control parameter cpxControl.LPMETHOD
- buildCplexProblemFromCOBRAStruct(Problem)[source]¶
Build a cplex object from the given LP problem in COBRA Format :USAGE: cplexProblem = buildCplexProblemFromCOBRAStruct (LPproblem)
- INPUT
LPproblem –
- A COBRA style Problem with the following fields:
.A - The equality and in equality matrix
.b - The right hand side values of the constraints
.ub - the upper bounds of the variables
.lb - the lower bounds of the variables
.osense - The objective sense (-1 for max, 1 for min)
.c - the objective coefficient vector for the linear part
- OPTIONAL:
.F - The objective coefficient matrix for the quadratic part.
.varType - The variable types for mixed integer problems (‘I’, integer, ‘C’, continous,’B’ binary)
.b_L - left hand sides of the constraints (will only be used if csense is empty)
.csense - The constraint senses, Default assumption is all ‘E’
.x0 - Basis to use
- checkSolFeas(LP, sol, maxInfeas, tol, internal)[source]¶
Returns the infeasibility of solutions given a COBRA model or LP structure, or a IBM-ILOG CPLEX class
- USAGE
[infeas, sol] = checkSolFeas (LP, sol, maxInfeas, tol)
- INPUTS
LP – COBRA model or LP structure, or a IBM-ILOG CPLEX class
sol – solution structure or columns of solution vectors. If LP is a CPLEX class with. Solution property sol can be omitted or empty.
- OPTIONAL INPUTS
maxInfeas – if true (defaulted), infeas = maximum infeasiblity if false, infeas = struct of vectors of infeasibility with the following fields:
.con for infeasibility of constraints
.lb for infeasibility of lower bounds
.ub for infeasibility of upper bounds
.ind for infeasibility of indicator constraints. = -Inf if an indicator is not active. (CPLEX class only)
tol – feasibility tolerance (defaulted at the Cobra solver feasTol value). For determining if the input solution is indeed feasible. Used only if the input solution is a structure.
- OUTPUT
infeas – maximum infeasibility (maxInfeas = true) or struct of vectors of infeasibility (maxInfeas = false)
sol – solution structure. Only available if the input solution is a structure. If \(infeas \leq tol\), sol.stat = 1. Otherwise no change.
- getParamList(param, bottomFlag)[source]¶
Get all the end parameters and their paths for matching CPLEX parameters appropriately (e.g., if param.simplex.display is a parameter, then we will have ‘display’ in paramList and ‘param.simplex’ in paramPath)
- USAGE
[paramList, paramPath, addCur] = getParamList (param, bottomFlag)
- INPUTS
param – existing structure with parameters for Cplex
bottomFlag – boolean switch to extract parameters based on ‘Cur’ at the bottom level in the user-supplied parameter structure
- OUTPUTS
paramList – Cell with proper parameter names
paramPath – Cell with superseeding parameter structure
addCur – Structure with booleans whether or not .Cur has been added to the paramPath for user-supplied parameters
- setCplexParam(LP, solverParams, verbFlag)[source]¶
Sets the parameters of the IBM ILOG CPLEX object according to the structure solverParams The solverParams structure has to contain the same structure as the Cplex.Param structue in a Cplex object. But values can be set by directly setting the respective parameter instead of the Cur value which would be necessary if directly modifying the Cplex.Param structure. :USAGE: LP = setCplexParam (LP, solverParams, verbFlag)
- INPUTS
LP – IBM-ILOG Cplex object
solverParams – parameter structure for Cplex. Check LP.Param. For example, [solverParams.simplex.display, solverParams.tune.display, solverParams.barrier.display, solverParams.sifting.display, solverParams.conflict.display] = deal(0); [solverParams.simplex.tolerances.optimality, solverParams.simplex.tolerances.feasibility] = deal(1e-9,1e-8);
The full set of parameters can be obtained by calling ‘Cplex().Param’
verbFlag – true to show which parameter input is problematic if any (optional, default true)
- setCplexParametersForProblem(cplexProblem, problemTypeParams, solverParams, problemType)[source]¶
Set the parameters for a specific problem from the COBRA Parameter structure and a solver specific parameter structure (latter has precedence). The cobra parameters structure contains fields as specified in getCobraSolverParamsOptionsForType, while solverParams needs to contain a structure compatible with setCplexParam. :USAGE: cplexProblem = setCplexParametersForProblem (cplexProblem, problemTypeParams, solverParams, ProblemType)
- INPUTS
cplexProblem – the Cplex() object to set the parameters
problemTypeParams – problem type parameters as defined in getCobraSolverParamsOptionsForType
solverParams – the solver specific parameter structure has to be compatible with setCplexParam
problemType – The type of Problem (‘LP’,’MILP’,’QP’,’MIQP’).
see https://www.ibm.com/docs/en/icos/12.10.0?topic=cplex-list-parameters see https://www.ibm.com/docs/en/icos/12.10.0
- solveCobraCPLEX(model, printLevel, basisReuse, conflictResolve, contFunctName, minNorm)[source]¶
Calls CPLEX to solve an LP or QP problem using the matlab API to cplex written by ILOG
- USAGE
[solution, model] = solveCobraCPLEX (model, printLevel, basisReuse, conflictResolve, contFunctName, minNorm)
- INPUT
model – structure with mandatory and optional fields:
.A or .S: - m x n LHS matrix
.b - m x 1 RHS vector
.c - n x 1 Objective coeff vector
.lb - n x 1 Lower bound vector
.ub - n x 1 Upper bound vector
.osense - scalar Objective sense (-1 max, +1 min)
.rxns - (optional) cell array of reaction abbreviations (necessary for making a readable confilict resolution file).
.csense - (optional) Constraint senses, a string containting the constraint sense for each row in A (‘E’, equality, ‘G’ greater than, ‘L’ less than).
.LPBasis - (optional) Basis from previous solution of similar LP problem. See basisReuse
- OPTIONAL INPUTS
printLevel – Printing level in the CPLEX m-file and CPLEX C-interface.
0 - Silent
1 - Warnings and Errors
2 - Summary information (Default)
3 - More detailed information
> 10 - Pause statements, and maximal printing (debug mode)
basisReuse – 0 - Use this for one of solution of an LP (Default); 1 - Returns a basis for reuse in the next LP i.e. outputs model.LPBasis
conflictResolve – 0 (Default); 1 If LP problem is proven to be infeasible by CPLEX, it will print out a ‘conflict resolution file’, which indicates the irreducible infeasible set of equaltiy & inequality constraints that together, combine to make the problem infeasible. This is useful for debugging an LP problem if you want to try to resolve a constraint conflict
contFunctName –
contFunctName = [] Use all default CLPEX control parameters, (Default);
2. contFunctName = someString e.g. ‘someFunctionName’ uses the user specified control parameters defined in someFunctionName.m; (see template function CPLEXParamSet for details). 3. contFunctName = cpxControl structure (output from a file like CPLEXParamSet.m)
minNorm – {(0), 1 , n x 1 vector} If not zero then, minimise the Euclidean length of the solution to the LP problem. Gives the same objective, but minimises the square of flux. minNorm ~1e-6 should be high enough for regularisation yet keep the same objective
- OUTPUT
solution – Structure containing the following fields describing a LP solution:
.full: Full LP solution vector
.obj: Objective value
.rcost: Lagrangian multipliers to the simple inequalties (Reduced costs)
.dual: Lagrangian multipliers to the equalities
.nInfeas: Number of infeasible constraints
.sumInfeas: Sum of constraint violation
.stat: COBRA Standardized solver status code:
1 - Optimal solution
2 - Unbounded solution
0 - Infeasible
-1 - No solution reported (timelimit, numerical problem etc)
.origStat: CPLEX status code. Use cplexStatus(solution.origStat) for more information from the CPLEX solver
.solver solver used by cplex
.time time taken to solve the optimization problem
- OPTIONAL OUTPUT:
model: with field:
.LPBasis - When input basisReuse=1, we return a basis for reuse in the next LP
CPLEX consists of 4 different LP solvers which can be used to solve sysbio optimization problems you can control which of the solvers, e.g. simplex vs interior point solver using the CPLEX control parameter cpxControl.LPMETHOD. At the moment, the solver is automatically chosen for you.
- solveCobraLPCPLEX(LPProblem, printLevel, basisReuse, conflictResolve, contFunctName, minNorm, interface)[source]¶
Calls CPLEX to solve an LP problem By default, use the matlab interface to cplex written by TOMLAB, in preference to the one written by ILOG.
- USAGE
[solution, LPProblem] = solveCobraLPCPLEX (LPProblem, printLevel, basisReuse, conflictResolve, contFunctName, minNorm, interface)
- INPUT
LPProblem – Structure containing the following fields describing the LP problem to be solved
.A - LHS matrix
.b - RHS vector
.c - Objective coeff vector
.lb - Lower bound vector
.ub - Upper bound vector
.osense - Objective sense (-1 maximise (default), +1 minimise)
.rxns - (optional) cell array of reaction abbreviations (necessary for making a readable confilict resolution file).
.csense - (optional) Constraint senses, a string containting the constraint sense for each row in A (‘E’, equality, ‘G’ greater than, ‘L’ less than).
.LPBasis - (optional) Basis from previous solution of similar LP problem. See basisReuse
- OPTIONAL INPUTS
printLevel – Printing level in the CPLEX m-file and CPLEX C-interface.
0 - Silent
1 - Warnings and Errors
2 - Summary information (Default)
3 - More detailed information
> 10 - Pause statements, and maximal printing (debug mode)
basisReuse – 0 - Use this for one of solution of an LP (Default); 1 - Returns a basis for reuse in the next LP i.e. outputs model.LPBasis
conflictResolve – 0 (Default); 1 If LP problem is proven to be infeasible by CPLEX, it will, for…
tomlab_cplex print out a ‘conflict resolution file’ ILOGcomplex return the ILOGcplex class with ILOGcplex.Conflict
… which indicate the irreducible infeasible set of equaltiy & inequality constraints that together, combine to make the problem infeasible. This is useful for debugging an LP problem if you want to try to resolve a constraint conflict
contFunctName – structure or function with parameters (only for tomlab_cplex or ILOGcomplex)
when using the tomlab_cplex interface
contFunctName = [] Use all default CLPEX control parameters, (Default);
contFunctName = someString e.g. ‘someFunctionName’ uses the user specified control parameters defined in someFunctionName.m (see template function CPLEXParamSet for details).
contFunctName = cpxControl structure (output from a file like CPLEXParamSet.m)
when using the ILOGcomplex interface (parameter structure for Cplex). The full set of parameters can be obtained by calling Cplex().Param. For example:
[solverParams.simplex.display, solverParams.tune.display, solverParams.barrier.display, solverParams.sifting.display, solverParams.conflict.display] = deal(0);
[solverParams.simplex.tolerances.optimality, solverParams.simplex.tolerances.feasibility] = deal(1e-9, 1e-8);
minNorm – {(0), 1 , n x 1 vector} If not zero then, minimise the Euclidean length of the solution to the LP problem. Gives the same objective, but minimises the square of flux. minNorm ~1e-6 should be high enough for regularisation yet keep the same objective
interface – {‘ILOGcomplex’, ‘ILOGsimple’, ‘tomlab_cplex’} Default is the tomlab_cplex interface
- OUTPUT
solution – Structure containing the following fields describing a LP solution:
.full: Full LP solution vector
.obj: Objective value
.rcost: Lagrangian multipliers to the simple inequalties (Reduced costs)
.dual: Lagrangian multipliers to the equalities
.nInfeas: Number of infeasible constraints
.sumInfeas: Sum of constraint violation
.stat: COBRA Standardized solver status code:
1 - Optimal solution
2 - Unbounded solution
0 - Infeasible
-1 - No solution reported (timelimit, numerical problem etc)
.origStat: CPLEX status code
.origStatText: CPLEX status text from `cplexStatus(solution.origStat)
.solver solver used by cplex
.time time taken to solve the optimization problemtime taken to solve the optimization problem
- OPTIONAL OUTPUT:
LPProblem: with field:
.LPBasis: When input basisReuse = 1, we return a basis for reuse in the next LP
ILOGcplex Class Cplex for the optimisation problem
- solveCobraLPCPLEX_2018(LPProblem, printLevel, basisReuse, conflictResolve, contFunctName, minNorm, interface)[source]¶
Calls CPLEX to solve an LP problem By default, use the matlab interface to cplex written by TOMLAB, in preference to the one written by ILOG.
- USAGE
[solution, LPProblem] = solveCobraLPCPLEX (LPProblem, printLevel, basisReuse, conflictResolve, contFunctName, minNorm, interface)
- INPUT
LPProblem – Structure containing the following fields describing the LP problem to be solved
.A - LHS matrix
.b - RHS vector
.c - Objective coeff vector
.lb - Lower bound vector
.ub - Upper bound vector
.osense - Objective sense (-1 max, +1 min)
.rxns - (optional) cell array of reaction abbreviations (necessary for making a readable confilict resolution file).
.csense - (optional) Constraint senses, a string containting the constraint sense for each row in A (‘E’, equality, ‘G’ greater than, ‘L’ less than).
.LPBasis - (optional) Basis from previous solution of similar LP problem. See basisReuse
- OPTIONAL INPUTS
printLevel – Printing level in the CPLEX m-file and CPLEX C-interface.
0 - Silent
1 - Warnings and Errors
2 - Summary information (Default)
3 - More detailed information
> 10 - Pause statements, and maximal printing (debug mode)
basisReuse – 0 - Use this for one of solution of an LP (Default); 1 - Returns a basis for reuse in the next LP i.e. outputs model.LPBasis
conflictResolve – 0 (Default); 1 If LP problem is proven to be infeasible by CPLEX, it will print out a ‘conflict resolution file’, which indicates the irreducible infeasible set of equaltiy & inequality constraints that together, combine to make the problem infeasible. This is useful for debugging an LP problem if you want to try to resolve a constraint conflict
contFunctName – structure or function with parameters (only for tomlab_cplex or ILOGcomplex)
when using the tomlab_cplex interface
contFunctName = [] Use all default CLPEX control parameters, (Default);
contFunctName = someString e.g. ‘someFunctionName’ uses the user specified control parameters defined in someFunctionName.m (see template function CPLEXParamSet for details).
contFunctName = cpxControl structure (output from a file like CPLEXParamSet.m)
when using the ILOGcomplex interface (parameter structure for Cplex). The full set of parameters can be obtained by calling Cplex().Param. For example:
[solverParams.simplex.display, solverParams.tune.display, solverParams.barrier.display, solverParams.sifting.display, solverParams.conflict.display] = deal(0);
[solverParams.simplex.tolerances.optimality, solverParams.simplex.tolerances.feasibility] = deal(1e-9, 1e-8);
minNorm – {(0), 1 , n x 1 vector} If not zero then, minimise the Euclidean length of the solution to the LP problem. Gives the same objective, but minimises the square of flux. minNorm ~1e-6 should be high enough for regularisation yet keep the same objective
interface – {‘ILOGcomplex’, ‘ILOGsimple’, ‘tomlab_cplex’} Default is the tomlab_cplex interface
- OUTPUT
solution – Structure containing the following fields describing a LP solution:
.full: Full LP solution vector
.obj: Objective value
.rcost: Lagrangian multipliers to the simple inequalties (Reduced costs)
.dual: Lagrangian multipliers to the equalities
.nInfeas: Number of infeasible constraints
.sumInfeas: Sum of constraint violation
.stat: COBRA Standardized solver status code:
1 - Optimal solution
2 - Unbounded solution
0 - Infeasible
-1 - No solution reported (timelimit, numerical problem etc)
.origStat: CPLEX status code. Use cplexStatus(solution.origStat) for more information from the CPLEX solver
.solver solver used by cplex
.time time taken to solve the optimization problemtime taken to solve the optimization problem
- OPTIONAL OUTPUT:
LPProblem: with field:
.LPBasis: When input basisReuse = 1, we return a basis for reuse in the next LP
CPLEX consists of 4 different LP solvers which can be used to solve sysbio optimization problems you can control which of the solvers, e.g. simplex vs interior point solver using the CPLEX control parameter cpxControl.LPMETHOD. At the moment, the solver is automatically chosen for you
- solveCobraLPCPLEXcard(LPProblem, printLevel, basisReuse, conflictResolve, contFunctName, minNorm, theNorm)[source]¶
Calls CPLEX to solve an LP problem By default, use the matlab interface to cplex written by TOMLAB, in preference to the one written by ILOG.
- USAGE
solveCobraLPCPLEXcard (LPProblem, printLevel, basisReuse, conflictResolve, contFunctName, minNorm, theNorm)
- INPUT
model – structure with mandatory and optional fields:
.A or .S: - m x n LHS matrix
.b - m x 1 RHS vector
.c - n x 1 Objective coeff vector
.lb - n x 1 Lower bound vector
.ub - n x 1 Upper bound vector
.osense - scalar Objective sense (-1 max, +1 min)
.rxns - (optional) cell array of reaction abbreviations (necessary for making a readable confilict resolution file).
.csense - (optional) Constraint senses, a string containting the constraint sense for each row in A (‘E’, equality, ‘G’ greater than, ‘L’ less than).
.LPBasis - (optional) Basis from previous solution of similar LP problem. See basisReuse
- OPTIONAL INPUTS
printLevel – Printing level in the CPLEX m-file and CPLEX C-interface.
0 - Silent
1 - Warnings and Errors
2 - Summary information (Default)
3 - More detailed information
> 10 - Pause statements, and maximal printing (debug mode)
basisReuse – 0 - Use this for one of solution of an LP (Default); 1 - Returns a basis for reuse in the next LP i.e. outputs model.LPBasis
conflictResolve – 0 (Default); 1 If LP problem is proven to be infeasible by CPLEX, it will print out a ‘conflict resolution file’, which indicates the irreducible infeasible set of equaltiy & inequality constraints that together, combine to make the problem infeasible. This is useful for debugging an LP problem if you want to try to resolve a constraint conflict
contFunctName – = [] Use all default CLPEX control parameters, (Default); = someString e.g. ‘someFunctionName’ uses the user specified control parameters defined in someFunctionName.m (see template function CPLEXParamSet for details). = cpxControl structure (output from a file like CPLEXParamSet.m)
minNorm – {(0), 1 , n x 1 vector} If not zero then, minimise the Euclidean length of the solution to the LP problem. Gives the same objective, but minimises the square of flux. minNorm ~1e-6 should be high enough for regularisation yet keep the same objective
theNorm – {‘zero’, ‘one’, (‘two’)} Controls which norm is minimized. ‘zero’ minimizes cardinality for nonzero entries in minNorm, ‘one’ minimizes taxicab norm for nonzero entries in minNorm (not implemented), ‘two’ minimizes Euclidean norm for nonzero entries in minNorm (default)
- OUTPUT
solution – Structure containing the following fields describing a LP solution:
.full: Full LP solution vector
.obj: Objective value
.rcost: Lagrangian multipliers to the simple inequalties (Reduced costs)
.dual: Lagrangian multipliers to the equalities
.nInfeas: Number of infeasible constraints
.sumInfeas: Sum of constraint violation
.stat: COBRA Standardized solver status code:
1 - Optimal solution
2 - Unbounded solution
0 - Infeasible
-1 - No solution reported (timelimit, numerical problem etc)
.origStat: CPLEX status code. Use cplexStatus(solution.origStat) for more information from the CPLEX solver
.solver solver used by cplex
.time time taken to solve the optimization problem
- OPTIONAL OUTPUT:
LPProblem: with field:
.LPBasis: When input basisReuse = 1, we return a basis for reuse in the next LP
CPLEX consists of 4 different LP solvers which can be used to solve sysbio optimization problems you can control which of the solvers, e.g. simplex vs interior point solver using the CPLEX control parameter cpxControl.LPMETHOD. At the moment, the solver is automatically chosen for you.
- tuneParam(LPProblem, contFunctName, timelimit, nrepeat, printLevel)[source]¶
Optimizes cplex parameters to make model resolution faster. Particularly interetsing for large-scale MILP models and repeated runs of optimisation. While, it won’t optimize memory space nor model constraints for numerical infeasibilities, tuneParam will provide the optimal set of solver parameters for feasbile models. It requires IBM ILOG cplex (for now).
- USAGE
optimalParameters = tuneParam (LPProblem,contFunctName,timelimit,nrepeat,printLevel)
- INPUT
LPProblem – MILP as COBRA LP problem structure
contFunctName – Parameters structure containing the name and value. A set of routine parameters will be added by the solver but won’t be reported.
timelimit – default is 10000 second
nrepeat – number of row/column permutation of the original problem, reports robust results. sets the CPX_PARAM_TUNINGREPEAT parameter High values of nrepeat would require consequent memory and swap.
printLevel – 0/(1)/2/3
- OUTPUT
optimParam – structure of optimal parameter values directly usable as contFunctName argument in solveCobraLP function
- tuneParamForModel(model, varargin)[source]¶
Optimizes cplex parameters to make model resolution faster. Particularly interetsing for large-scale MILP models and repeated runs of optimisation. While, it won’t optimize memory space nor model constraints for numerical infeasibilities, tuneParam will provide the optimal set of solver parameters for feasbile models. It requires IBM ILOG cplex (for now).
- USAGE
optimalParameters = tuneParam (model,contFunctName,1000,1000,0)
- INPUT
model – A COBRA model struct.
contFunctName – Parameters structure containing the name and value. A set of routine parameters will be added by the solver but won’t be reported.
timelimit – default is 10000 second
nrepeat – number of row/column permutation of the original problem, reports robust results. sets the CPX_PARAM_TUNINGREPEAT parameter High values of nrepeat would require consequent memory and swap.
printLevel – 0/1/2/3
- OUTPUT
optimParam – structure of optimal parameter values directly usable as contFunctName argument in solveCobraLP function
Note
This is just a wrapper function that calls the tuneParam function using a Cobra model structure converted to a LP problem.