forked from opencobra/cobratoolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enumerateOptimalSolutions.m
134 lines (114 loc) · 3.23 KB
/
enumerateOptimalSolutions.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
function [solution] = enumerateOptimalSolutions(model)
%enumerateOptimalSolution returns a set of optimal flux distributions
%spanning the optimal set
%
%[solution] enumerateOptimalSolution(model)
%
%INPUT
% model COBRA model structure
%
%OUTPUT
% solution solution strcture
% fluxes Flux distribution for each iteration
% nonzero Boolean matrix denoting which fluxes are nonzero for each
% iteration
%
% Author: Jan Schellenberger, August 2008
% Based on code by Jennie Reed
% Reed, J.L. and Palsson, B.O., "Genome-scale in silico models of ''E. coli'' have multiple equivalent phenotypic states: assessment of correlated reaction subsets that comprise network states" , Genome Research, 14:1797-1805(2004).
[m,n] = size(model.S);
solution.fluxes = zeros(n,0);
solution.nonzero = zeros(n,0);
sol = optimizeCbModel(model);
maxObjective = sol.f;
prevNZ = abs(sol.x) > .0001;
NZ = prevNZ;
solution.fluxes = sol.x;
solution.nonzero = prevNZ;
while 1
% variables:
% v's (n), y's (n) w's (n) 3n total variables
% constriants:
% m mass balance constraints
A = [model.S, zeros(m,2*n)];
b = zeros(m,1);
csense = '';
for i = 1:m
csense(end+1) = 'E';
end
% constrain UB fluxes w/ integer constraints
A = [A;
[eye(n,2*n), -diag(model.ub)] ];
b = [b;
zeros(n,1)];
for i = 1:n
csense(end+1) = 'L';
end
% constrain LB fluxes w/ integer constraints
A = [A;
eye(n,2*n), -diag(model.lb) ];
b = [b;
zeros(n,1)];
for i = 1:n
csense(end+1) = 'G';
end
% constrain w+y <=1
A = [A;
zeros(n,n), eye(n,n), eye(n,n) ];
b = [b;
ones(n,1)];
for i = 1:n
csense(end+1) = 'L';
end
% constrain with previous zero results
A = [A;
zeros(1,n), prevNZ', zeros(1,n) ];
b = [b;
1];
csense(end+1) = 'G';
% constrain with previous results (altbases)
for i = 1:size(NZ,2)
A = [A;
[zeros(1,n), zeros(1,n) NZ(:,i)']];
b(end+1) = sum(NZ(:,i))-1;
csense(end+1) = 'L';
end
% vartype
vartype = [];
for i = 1:n
vartype(i) = 'C';
end
for i = 1:2*n
vartype(end+1) = 'B';
end
% lb,ub
lb = [model.lb; zeros(2*n,1)];
ub = [model.ub; ones(2*n,1)];
% c
c = [model.c; zeros(2*n,1)];
% create structure
MILPproblem.A = A;
MILPproblem.b = b;
MILPproblem.c = c;
MILPproblem.csense = csense;
MILPproblem.lb = lb;
MILPproblem.ub = ub;
MILPproblem.osense = -1;
MILPproblem.vartype = vartype;
MILPproblem.x0 = [];%zeros(2*n,1);
%MILPproblem.intSolInd = [];
%MILPproblem.contSolInd = [];
% pause;
MILPsol = solveCobraMILP(MILPproblem)
% MILPsol.full
NZ(:,end+1) = abs(MILPsol.full(1:n))>.000000001;
PrevNZ = NZ(:,end);
if (abs(MILPsol.full - maxObjective) > .001)
'done';
return;
end
solution.fluxes = [solution.fluxes,MILPsol.full(1:n)];
solution.nonzero = [solution.nonzero, NZ(:,end)];
solution
end
return;