0001 function solverOK = changeCobraSolver(solverName,solverType)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
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
0091 if (strcmp(solverType,'LP'))
0092
0093 solverOK = true;
0094
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
0155 solverOK = true;
0156
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
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
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
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