0001
0002
0003 function tests = solverTests
0004 tests = functiontests(localfunctions);
0005 end
0006
0007 function testGlpk(testCase)
0008 sourceDir = fileparts(which(mfilename));
0009 load([sourceDir,'/test_data/ecoli_textbook.mat'], 'model');
0010 try
0011 oldSolver=getpref('RAVEN','solver');
0012 catch
0013 end
0014 setRavenSolver('glpk');
0015
0016 try
0017 evalc('sol=solveLP(model,0);');
0018 catch
0019 try
0020 setRavenSolver(oldSolver);
0021 catch
0022 rmpref('RAVEN','solver');
0023 end
0024 error('Solver not working')
0025 end
0026 try
0027 setRavenSolver(oldSolver);
0028 catch
0029 rmpref('RAVEN','solver');
0030 end
0031
0032 load([sourceDir,'/test_data/solverTestOutput.mat'], 'solOut');
0033
0034 verifyEqual(testCase,sol,solOut,'AbsTol',0.1)
0035 end
0036
0037 function testGurobi(testCase)
0038 sourceDir = fileparts(which(mfilename));
0039 load([sourceDir,'/test_data/ecoli_textbook.mat'], 'model');
0040 try
0041 oldSolver=getpref('RAVEN','solver');
0042 catch
0043 end
0044
0045 setRavenSolver('gurobi');
0046
0047 if exist('gurobi','file')~=3
0048 error('Gurobi not installed or cannot be found in MATLAB path.')
0049 else
0050 try
0051
0052 evalc('sol=solveLP(model,3);');
0053 evalc('sol=solveLP(model,1);');
0054 evalc('sol=solveLP(model,0);');
0055 catch ME
0056 try
0057 setRavenSolver(oldSolver);
0058 catch
0059 rmpref('RAVEN','solver');
0060 end
0061 error(ME.message)
0062 end
0063 end
0064 try
0065 setRavenSolver(oldSolver);
0066 catch
0067 rmpref('RAVEN','solver');
0068 end
0069
0070 load([sourceDir,'/test_data/solverTestOutput.mat'], 'solOut');
0071
0072 verifyEqual(testCase,sol,solOut,'AbsTol',0.1)
0073 end
0074
0075 function testSCIP(testCase)
0076 if exist('scip','file')~=3
0077 error('SCIP MEX binary not installed or not functional.')
0078 end
0079 sourceDir = fileparts(which(mfilename));
0080 load([sourceDir,'/test_data/ecoli_textbook.mat'], 'model');
0081 try
0082 oldSolver=getpref('RAVEN','solver');
0083 catch
0084 end
0085 setRavenSolver('scip');
0086 try
0087 evalc('sol=solveLP(model,0);');
0088 catch
0089 try
0090 setRavenSolver(oldSolver);
0091 catch
0092 rmpref('RAVEN','solver');
0093 end
0094 error('Solver not working')
0095 end
0096 try
0097 setRavenSolver(oldSolver);
0098 catch
0099 rmpref('RAVEN','solver');
0100 end
0101
0102 load([sourceDir,'/test_data/solverTestOutput.mat'], 'solOutSCIP');
0103
0104 verifyEqual(testCase,sol,solOutSCIP,'AbsTol',0.1)
0105 end
0106
0107 function testCobra(testCase)
0108 if exist('initCobraToolbox.m','file')~=2
0109 error('COBRA Toolbox not installed or cannot be found in MATLAB path.')
0110 end
0111 sourceDir = fileparts(which(mfilename));
0112 load([sourceDir,'/test_data/ecoli_textbook.mat'], 'model');
0113 try
0114 oldSolver=getpref('RAVEN','solver');
0115 catch
0116 end
0117 global CBT_LP_SOLVER
0118 global CBT_MILP_SOLVER
0119 CBT_LP_SOLVER = 'glpk';
0120 CBT_MILP_SOLVER = 'glpk';
0121 setRavenSolver('cobra');
0122
0123 try
0124 evalc('sol=solveLP(model,0);');
0125 catch
0126 try
0127 setRavenSolver(oldSolver);
0128 catch
0129 rmpref('RAVEN','solver');
0130 end
0131 error('Solver not working')
0132 end
0133 try
0134 setRavenSolver(oldSolver);
0135 catch
0136 rmpref('RAVEN','solver');
0137 end
0138
0139 load([sourceDir,'/test_data/solverTestOutput.mat'], 'solOut');
0140
0141 verifyEqual(testCase,sol,solOut,'AbsTol',0.1)
0142 end