forked from opencobra/cobratoolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
initCobraToolbox.m
106 lines (99 loc) · 3.42 KB
/
initCobraToolbox.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
function initCobraToolbox
%initCobraToolbox Initialize COnstraint-Based Reconstruction and Analysis Toolbox
%
% Define default solvers and paths
% Function only needs to be called once. Save paths afer script terminates.
%
% In addition add either of the following into startup.m (generally in MATLAB_DIRECTORY/toolbox/local/startup.m)
% initCobraToolbox
% -or-
% changeCobraSolver('gurobi');
% changeCobraSolver('gurobi', 'MILP');
% changeCobraSolver('tomlab_cplex', 'QP');
% changeCobraSolver('tomlab_cplex', 'MIQP');
% changeCbMapOutput('svg');
%
% Markus Herrgard 8/30/06
%
% Rewritten to utilize addpath_recurse. Richard Que (11/19/09)
%% add cobra toolbox paths
pth=which('initCobraToolbox.m');
CBTDIR = pth(1:end-(length('initCobraToolbox.m')+1));
path(path,[CBTDIR, filesep, 'external']);
addpath_recurse(CBTDIR,{'.svn','obsolete','m2html','docs','src','stow'});
%% Define Solvers
% Define the default linear programming solver to be used by the toolbox
% Available solver options:
% 'lindo_new','lindo_old','glpk','lp_solve','mosek','tomlab_cplex',
% 'cplex_direct','gurobi'
% Note that you must install the solver separately and make sure Matlab can
% access the solver
CobraLPSolver = 'tomlab_cplex';
% CobraLPSolver = 'glpk';
%CobraLPSolver = 'mosek';
% CobraLPSolver = 'cplx';
if isunix
addpath('/usr/local/lib/');
end
CobraLPSolvers = { 'gurobi5', 'gurobi', 'tomlab_cplex', 'glpk', 'mosek', 'cplx' };
for CobraLPSolver = CobraLPSolvers
LPsolverOK = changeCobraSolver(char(CobraLPSolver));
if LPsolverOK
fprintf('LP solver set to %s successful\n',char(CobraLPSolver));
break;
end
end
if ~LPsolverOK
fprintf('LP solver set failed\n');
end
% Define default MILP solver
%CobraMILPSolver = 'tomlab_cplex';
%CobraMILPSolver = 'glpk';
for CobraMILPSolver = { 'gurobi5', 'gurobi', 'tomlab_cplex', 'glpk' }
MILPsolverOK = changeCobraSolver(char(CobraMILPSolver),'MILP');
if MILPsolverOK
fprintf('MILP solver set to %s successful\n',char(CobraMILPSolver));
break;
end
end
if ~MILPsolverOK
fprintf('MILP solver set failed\n');
end
% Define default QP solver
%CobraQPSolver = 'tomlab_cplex';
for CobraQPSolver = {'gurobi5', 'gurobi', 'tomlab_cplex', 'qpng' }
QPsolverOK = changeCobraSolver(char(CobraQPSolver),'QP');
if QPsolverOK
fprintf('QP solver set to %s successful\n',char(CobraQPSolver));
break;
end
end
if ~QPsolverOK
fprintf('QP solver set failed\n');
end
% Define default MIQP solver
for CobraMIQPSolver = {'gurobi5', 'gurobi' 'tomlab_cplex'}
MIQPsolverOK = changeCobraSolver(char(CobraMIQPSolver),'MIQP');
if MIQPsolverOK
fprintf('MIQP solver set to %s successful\n',char(CobraMIQPSolver));
break;
end
end
if ~MIQPsolverOK
fprintf('MIQP solver set failed\n');
end
% Define default CB map output
% CbMapOutput = 'matlab';
CbMapOutput = 'svg';
CbMapOutputOK = changeCbMapOutput(CbMapOutput);
if CbMapOutputOK
fprintf('CB map output set to %s successful\n',CbMapOutput);
else
fprintf('Cb map output set failed\n');
end
% Set global LP solution accuracy tolerance
changeOK = changeCobraSolverParams('LP','objTol',1e-6);
% Check that SBML toolbox is installed and accessible
if (~exist('TranslateSBML'))
warning('SBML Toolbox not in Matlab path: COBRA Toolbox will be unable to read SBML files');
end