changeCobraSolver

PURPOSE ^

changeCobraSolver Changes the Cobra Toolbox optimization solver(s)

SYNOPSIS ^

function solverOK = changeCobraSolver(solverName,solverType)

DESCRIPTION ^

changeCobraSolver Changes the Cobra Toolbox optimization solver(s)

 solverOK = changeCobraSolver(solverName,solverType)

INPUTS
 solverName    Solver name
 solverType    Solver type, 'LP', 'MILP', 'QP', 'MIQP' (opt, default
               'LP', 'all').  'all' attempts to change all applicable
               solvers to solverName.  This is purely a shorthand
               convenience.

OUTPUT
 solverOK      true if solver can be accessed, false if not

 Currently allowed LP solvers:
   lindo_new       Lindo API >v2.0
   lindo_old       Lindo API <v2.0
   glpk            GLPK solver with Matlab mex interface (glpkmex)
   lp_solve        lp_solve with Matlab API
   tomlab_cplex    CPLEX accessed through Tomlab environment (default)
   cplex_direct    CPLEX accessed direct to Tomlab cplex.m. This gives
                   the user more control of solver parameters. e.g.
                   minimising the Euclidean norm of the internal flux to
                   get rid of net flux around loops
   mosek           Mosek LP solver with Matlab API (using linprog.m included in Mosek
                   package)
   gurobi          Gurobi accessed through Matlab mex interface (Gurobi mex)
   gurobi5         Gurobi 5.0 accessed through built-in Matlab mex interface
   matlab          Matlab's own linprog.m (currently unsupported, may not
                   work on COBRA-type LP problems)
   mps             Outputs a MPS matrix string. Does not solve LP problem

 Currently allowed MILP solvers:
   tomlab_cplex    CPLEX MILP solver accessed through Tomlab environment
   glpk            glpk MILP solver with Matlab mex interface (glpkmex)
   gurobi          Gurobi accessed through Matlab mex interface (Gurobi mex)
   gurobi5         Gurobi 5.0 accessed through built-in Matlab mex interface
   mps             Outputs a MPS matrix string. Does not solve MILP
                   problem

 Currently allowed QP solvers:
   tomlab_cplex    CPLEX QP solver accessed through Tomlab environment
   qpng            qpng QP solver with Matlab mex interface (in glpkmex
                   package, only limited support for small problems)
   gurobi5         Gurobi 5.0 accessed through built-in Matlab mex interface

 Currently allowed MIQP solvers:
   tomlab_cplex    CPLEX MIQP solver accessed through Tomlab environment
   gurobi5         Gurobi 5.0 accessed through built-in Matlab mex interface

 Currently allowed NLP solvers
   matlab          MATLAB's fmincon.m
   tomlab_snopt    SNOPT solver accessed through Tomlab environment

 it is a good idea to put this function call into your startup.m file
 (usually matlabinstall/toolboxes/local/startup.m)
 Markus Herrgard 1/19/07

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function solverOK = changeCobraSolver(solverName,solverType)
0002 %changeCobraSolver Changes the Cobra Toolbox optimization solver(s)
0003 %
0004 % solverOK = changeCobraSolver(solverName,solverType)
0005 %
0006 %INPUTS
0007 % solverName    Solver name
0008 % solverType    Solver type, 'LP', 'MILP', 'QP', 'MIQP' (opt, default
0009 %               'LP', 'all').  'all' attempts to change all applicable
0010 %               solvers to solverName.  This is purely a shorthand
0011 %               convenience.
0012 %
0013 %OUTPUT
0014 % solverOK      true if solver can be accessed, false if not
0015 %
0016 % Currently allowed LP solvers:
0017 %   lindo_new       Lindo API >v2.0
0018 %   lindo_old       Lindo API <v2.0
0019 %   glpk            GLPK solver with Matlab mex interface (glpkmex)
0020 %   lp_solve        lp_solve with Matlab API
0021 %   tomlab_cplex    CPLEX accessed through Tomlab environment (default)
0022 %   cplex_direct    CPLEX accessed direct to Tomlab cplex.m. This gives
0023 %                   the user more control of solver parameters. e.g.
0024 %                   minimising the Euclidean norm of the internal flux to
0025 %                   get rid of net flux around loops
0026 %   mosek           Mosek LP solver with Matlab API (using linprog.m included in Mosek
0027 %                   package)
0028 %   gurobi          Gurobi accessed through Matlab mex interface (Gurobi mex)
0029 %   gurobi5         Gurobi 5.0 accessed through built-in Matlab mex interface
0030 %   matlab          Matlab's own linprog.m (currently unsupported, may not
0031 %                   work on COBRA-type LP problems)
0032 %   mps             Outputs a MPS matrix string. Does not solve LP problem
0033 %
0034 % Currently allowed MILP solvers:
0035 %   tomlab_cplex    CPLEX MILP solver accessed through Tomlab environment
0036 %   glpk            glpk MILP solver with Matlab mex interface (glpkmex)
0037 %   gurobi          Gurobi accessed through Matlab mex interface (Gurobi mex)
0038 %   gurobi5         Gurobi 5.0 accessed through built-in Matlab mex interface
0039 %   mps             Outputs a MPS matrix string. Does not solve MILP
0040 %                   problem
0041 %
0042 % Currently allowed QP solvers:
0043 %   tomlab_cplex    CPLEX QP solver accessed through Tomlab environment
0044 %   qpng            qpng QP solver with Matlab mex interface (in glpkmex
0045 %                   package, only limited support for small problems)
0046 %   gurobi5         Gurobi 5.0 accessed through built-in Matlab mex interface
0047 %
0048 % Currently allowed MIQP solvers:
0049 %   tomlab_cplex    CPLEX MIQP solver accessed through Tomlab environment
0050 %   gurobi5         Gurobi 5.0 accessed through built-in Matlab mex interface
0051 %
0052 % Currently allowed NLP solvers
0053 %   matlab          MATLAB's fmincon.m
0054 %   tomlab_snopt    SNOPT solver accessed through Tomlab environment
0055 %
0056 % it is a good idea to put this function call into your startup.m file
0057 % (usually matlabinstall/toolboxes/local/startup.m)
0058 % Markus Herrgard 1/19/07
0059 global CBTLPSOLVER;
0060 global CBT_MILP_SOLVER;
0061 global CBT_QP_SOLVER;
0062 global CBT_MIQP_SOLVER;
0063 global CBT_NLP_SOLVER;
0064 
0065 if (nargin < 1)
0066     display('The solvers defined are: ');
0067     display(CBTLPSOLVER);
0068     if ~isempty(CBT_MILP_SOLVER), display(CBT_MILP_SOLVER); end
0069     if ~isempty(CBT_QP_SOLVER), display(CBT_QP_SOLVER); end
0070     if ~isempty(CBT_MIQP_SOLVER), display(CBT_MIQP_SOLVER); end
0071     if ~isempty(CBT_NLP_SOLVER), display(CBT_NLP_SOLVER); end
0072     solverOK = false;
0073     return;
0074 end
0075 
0076 if (nargin < 2)
0077     solverType = 'LP';
0078 end
0079 
0080 solverOK = false;
0081 solverType = upper(solverType);
0082 
0083 if (strcmp(solverType, 'ALL'))
0084     changeCobraSolver(solverName,'LP');
0085     changeCobraSolver(solverName,'MILP');
0086     changeCobraSolver(solverName,'QP');
0087     changeCobraSolver(solverName,'MIQP');
0088 end
0089 
0090 % Only LP is currently included
0091 if (strcmp(solverType,'LP'))
0092     %% LP solver
0093     solverOK = true;
0094     % Check that the LP solver is installed and accessible
0095     switch solverName
0096         case {'lindo_old','lindo_new'}
0097             if (~exist('mxlindo'))
0098                 warning('LP solver Lindo not usable: mxlindo.dll not in Matlab path');
0099                 solverOK = false;
0100             end
0101         case 'glpk'
0102             if (~exist('glpkmex'))
0103                 warning('LP solver glpk not usable: glpkmex not in Matlab path');
0104                 solverOK = false;
0105             end
0106         case 'mosek'
0107             if (~exist('mosekopt'))
0108                 warning('LP solver Mosek not usable: mosekopt.m not in Matlab path');
0109                 solverOK = false;
0110             end
0111         case 'tomlab_cplex'
0112             if (~exist('tomRun'))
0113                 warning('LP solver CPLEX through Tomlab not usable: tomRun.m not in Matlab path');
0114                 solverOK = false;
0115             end
0116         case 'cplex_direct'
0117             if (~exist('solveCobraLPCPLEX'))
0118                 warning('LP solver CPLEX through Tomlab not usable: tomRun.m not in Matlab path');
0119                 solverOK = false;
0120             end
0121         case 'lp_solve'
0122             if (~exist('lp_solve'))
0123                 warning('LP solver lp_solve not usable: lp_solve.m not in Matlab path');
0124                 solverOK = false;
0125             end
0126         case 'pdco'
0127             if (~exist('pdco'))
0128                 warning('LP solver pdco not usable: pdco.m not in Matlab path');
0129                 solverOK = false;
0130             end
0131         case 'gurobi'
0132             if (~exist('gurobi_mex'))
0133                 warning('LP solver Gurobi not useable: gurobi_mex not in Matlab path');
0134                 solverOK=false;
0135             end
0136         case 'gurobi5'
0137             if (~exist('gurobi'))
0138                 warning('LP solver Gurobi not useable: gurobi.m not in Matlab path');
0139                 solverOK=false;
0140             end
0141         case 'mps'
0142             if (~exist('BuildMPS'))
0143                 warning('MPS not usable: BuildMPS.m not in Matlab path');
0144                 solverOK = false;
0145             end
0146         otherwise
0147             warning(['LP solver ' solverName ' not supported by COBRA Toolbox']);
0148             solverOK = false;
0149     end
0150     if solverOK
0151         CBTLPSOLVER = solverName;
0152     end
0153 elseif (strcmp(solverType,'MILP'))
0154     %% MILP solver
0155     solverOK = true;  
0156     % Check that the LP solver is installed and accessible
0157     switch solverName
0158         case 'tomlab_cplex'
0159             if (~exist('tomRun'))
0160                 warning('MILP solver CPLEX through Tomlab not usable: tomRun.m not in Matlab path');
0161                 solverOK = false;
0162             end
0163         case 'glpk'
0164             if (~exist('glpkmex'))
0165                 warning('MILP solver glpk not usable: glpkmex not in Matlab path');
0166                 solverOK = false;
0167             end
0168         case 'gurobi'
0169             if (~exist('gurobi_mex'))
0170                 warning('MILP solver Gurobi not useable: gurobi_mex not in Matlab path');
0171                 solverOK=false;
0172             end
0173         case 'gurobi5'
0174             if (~exist('gurobi'))
0175                 warning('MILP solver Gurobi not useable: gurobi.m not in Matlab path');
0176                 solverOK=false;
0177             end
0178         case 'mps'
0179             if (~exist('BuildMPS'))
0180                 warning('MPS not usable: BuildMPS.m not in Matlab path');
0181                 solverOK = false;
0182             end
0183         otherwise
0184             warning(['MILP solver ' solverName ' not supported by COBRA Toolbox']);
0185             solverOK = false;
0186     end
0187     if solverOK
0188         CBT_MILP_SOLVER = solverName;
0189     end
0190 elseif (strcmp(solverType,'QP'))
0191     %% QP solver
0192     switch solverName
0193         case 'tomlab_cplex'
0194             if (~exist('tomRun'))
0195                 warning('QP solver CPLEX through Tomlab not usable: tomRun.m not in Matlab path');
0196                 solverOK = false;
0197             else
0198                 solverOK = true;
0199             end
0200         case 'qpng'
0201             if (~exist('qpng'))
0202                 warning('QP solver qpng not usable: qpng.m not in Matlab path');
0203                 solverOK = false;
0204             else
0205                 warning('qpng solver has not been fully tested - results may not be correct');
0206                 solverOK = true;
0207             end
0208         case 'mosek'
0209             if (~exist('mskqpopt'))
0210                 warning('QP solver mskqpopt not usable: mskqpopt.m not in Matlab path');
0211                 solverOK = false;
0212             else
0213                 solverOK = true;
0214             end
0215         case 'pdco'
0216             if (~exist('pdco'))
0217                 warning('QP solver pdco not usable: pdco.m not in Matlab path');
0218                 solverOK = false;
0219             else
0220                 solverOK = true;
0221             end
0222         case 'gurobi'
0223             if (~exist('gurobi_mex'))
0224                 warning('QP solver Gurobi not useable: gurobi_mex not in Matlab path');
0225                 solverOK=false;
0226             else
0227                 solverOK=true;
0228             end
0229         case 'gurobi5'
0230             if (~exist('gurobi'))
0231                 warning('QP solver Gurobi not useable: gurobi.m not in Matlab path');
0232                 solverOK=false;
0233             else
0234                 solverOK=true;
0235             end
0236         otherwise
0237             warning(['QP solver ' solverName ' not supported by COBRA Toolbox']);
0238             solverOK = false;
0239     end
0240     if solverOK
0241         CBT_QP_SOLVER = solverName;
0242     end
0243 elseif (strcmp(solverType, 'MIQP'))
0244     %MIQP solver
0245     switch solverName
0246         case 'tomlab_cplex'
0247             if(~exist('tomRun'))
0248                 warning('MIQP solver CPLEX through Tomlab not usable: tomRun.m not in Matlab path');
0249                 solverOK = false;
0250             else
0251                 solverOK = true;
0252             end
0253         case 'gurobi'
0254             if(~exist('gurobi_mex'))
0255                 warning('MIQP solver gurobi not usable: gurobi_mex not in Matlab path');
0256                 solverOK = false;
0257             else
0258                 solverOK = true;
0259             end
0260         case 'gurobi5'
0261             if(~exist('gurobi'))
0262                 warning('MIQP solver gurobi not usable: gurobi.m not in Matlab path');
0263                 solverOK = false;
0264             else
0265                 solverOK = true;
0266             end
0267         otherwise
0268             warning(['MIQP solver ' solverName ' not supported by COBRA Toolbox']);
0269             solverOK = false;
0270     end
0271     if solverOK
0272         CBT_MIQP_SOLVER = solverName;
0273     end
0274 elseif (strcmp(solverType, 'NLP'))
0275     %NLP solver
0276     switch solverName
0277         case 'matlab'
0278             solverOK = true;
0279         case 'tomlab_snopt'
0280             if(~exist('tomRun'))
0281                 warning('MIQP solver CPLEX through Tomlab not usable: tomRun.m not in Matlab path');
0282                 solverOK = false;
0283             else
0284                 solverOK = true;
0285             end
0286         otherwise
0287             warning(['NLP solver ' solverName ' not supported by COBRA Toolbox']);
0288             solverOK = false;
0289     end
0290     if solverOK
0291         CBT_NLP_SOLVER = solverName;
0292     end
0293 end

Generated on Thu 21-Jun-2012 15:39:23 by m2html © 2003