Home > testing > unit_tests > solverTests.m

solverTests

PURPOSE ^

run this test case with the command

SYNOPSIS ^

function tests = solverTests

DESCRIPTION ^

run this test case with the command
results = runtests('solverTests.m')

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 %run this test case with the command
0002 %results = runtests('solverTests.m')
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 %Check that the actual model is the same as the expected model
0034 verifyEqual(testCase,sol,solOut,'AbsTol',0.1) %Quite generous tolerance, as shadow price calculations fluctuate quite a bit between solvers
0035 end
0036 
0037 function testGurobi(testCase)
0038 if exist('gurobi','file')~=3
0039     error('Gurobi not installed or cannot be found in MATLAB path, test skipped')
0040 end
0041 sourceDir = fileparts(which(mfilename));
0042 load([sourceDir,'/test_data/ecoli_textbook.mat'], 'model');
0043 try
0044     oldSolver=getpref('RAVEN','solver');
0045 catch
0046 end
0047 setRavenSolver('gurobi');
0048 
0049 try
0050     % Try all three types of flux minimization
0051     evalc('sol=solveLP(model,3);');    
0052     evalc('sol=solveLP(model,1);');
0053     evalc('sol=solveLP(model,0);');
0054 catch
0055     try
0056         setRavenSolver(oldSolver);
0057     catch
0058         rmpref('RAVEN','solver');
0059     end
0060     error('Solver not working')
0061 end
0062 try
0063     setRavenSolver(oldSolver);
0064 catch
0065     rmpref('RAVEN','solver');
0066 end
0067 
0068 load([sourceDir,'/test_data/solverTestOutput.mat'], 'solOut');
0069 %Check that the actual model is the same as the expected model
0070 verifyEqual(testCase,sol,solOut,'AbsTol',0.1)
0071 end
0072 
0073 function testSCIP(testCase)
0074 try
0075     scip;
0076 catch
0077     error('SCIP MEX binary not installed or not functional, test skipped')
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 %Check that the actual model is the same as the expected model
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, test skipped')
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 %Check that the actual model is the same as the expected model
0141 verifyEqual(testCase,sol,solOut,'AbsTol',0.1)
0142 end

Generated by m2html © 2005