@@ -12,21 +12,21 @@ def __init__(self,model):
12
12
BaseFBAPkg .__init__ (self ,model ,"reaction use" ,{"dualconst" :"string" ,"dualub" :"string" ,"duallb" :"string" },{"dualvar" :"string" ,"objective" :"string" })
13
13
14
14
def build_package (self ,filter = None ,binary_variable_count = 0 ):
15
- self .validate_parameters (parameters , [], {
15
+ self .validate_parameters ({} , [], {
16
16
"binary_variable_count" :binary_variable_count
17
17
});
18
+ print ("binary_variable_count:" ,binary_variable_count )
18
19
coefficients = {}
19
20
obj_coef = {}
20
21
obj = self .model .solver .objective
21
- #Using the JSON calls because get_linear_coefficients is REALLY slow
22
22
#Creating new objective coefficient and bound variables
23
23
bound_variables = {}
24
24
reactions = self .model .reactions
25
- if binary_variable_count > 0 :
25
+ if self . parameters [ " binary_variable_count" ] > 0 :
26
26
for reaction in self .model .reactions :
27
- var = self .build_variable ("fluxcomp" ,reaction ,None )
28
- const = self .build_constraint ("fluxcomp" ,reaction ,None ,None ,None )
27
+ var = self .build_variable ("flxcmp" ,reaction ,None )
29
28
#Retreiving model data with componenent flux variables
29
+ #Using the JSON calls because get_linear_coefficients is REALLY slow
30
30
mdldata = self .model .solver .to_json ()
31
31
consthash = {}
32
32
for const in mdldata ["constraints" ]:
@@ -35,10 +35,10 @@ def build_package(self,filter = None,binary_variable_count = 0):
35
35
variables = list (self .model .solver .variables )
36
36
objterms = obj .get_linear_coefficients (variables )
37
37
#Adding binary variables and constraints which should not be included in dual formulation
38
- if binary_variable_count > 0 :
39
- for variable in self .variables [ "fluxcomp" ] :
40
- var = self .build_variable ("bfluxcomp" , variable ,None )
41
- const = self .build_constraint ("bfluxcomp" , variable ,None ,None ,None )
38
+ if self . parameters [ " binary_variable_count" ] > 0 :
39
+ for reaction in self .model . reactions :
40
+ var = self .build_variable ("bflxcmp" , reaction ,None )
41
+ const = self .build_constraint ("bflxcmp" , reaction ,None ,None ,None )
42
42
#Now implementing dual variables and constraints
43
43
varhash = {}
44
44
for var in variables :
@@ -65,7 +65,6 @@ def build_package(self,filter = None,binary_variable_count = 0):
65
65
coefficients [var ][dvar ] = 1
66
66
self .build_constraint ("dualvar" ,var ,obj ,objterms ,coefficients )
67
67
self .build_constraint ("objective" ,None ,obj ,objterms ,obj_coef )
68
- #Add binary variables and constaints which should not be part of the formulation
69
68
70
69
def build_variable (self ,type ,object ,obj_coef ):
71
70
if type == "dualconst" :
@@ -95,30 +94,38 @@ def build_variable(self,type,object,obj_coef):
95
94
for i in range (0 ,self .parameters ["binary_variable_count" ]):
96
95
value = 2 ** i
97
96
if object .lower_bound < 0 :
98
- var = BaseFBAPkg .build_variable (self ,"rflxcmp" + str (i ),0 ,- 1 * value * object .lower_bound / denominator ,"continuous" ,object .id )
97
+ self .add_variable_type ("rflxcmp" + str (i ),"reaction" )
98
+ var = BaseFBAPkg .build_variable (self ,"rflxcmp" + str (i ),0 ,- 1 * value * object .lower_bound / denominator ,"continuous" ,object )
99
99
coefs [0 ][var ] = - 1
100
100
if object .upper_bound > 0 :
101
- var = BaseFBAPkg .build_variable (self ,"fflxcmp" + str (i ),0 ,value * object .upper_bound / denominator ,"continuous" ,object .id )
101
+ self .add_variable_type ("fflxcmp" + str (i ),"reaction" )
102
+ var = BaseFBAPkg .build_variable (self ,"fflxcmp" + str (i ),0 ,value * object .upper_bound / denominator ,"continuous" ,object )
102
103
coefs [1 ][var ] = - 1
103
104
if object .lower_bound < 0 :
104
105
#flux - flux_comp_0 - flux_comp_n = 0 - restriction of reverse fluxes by component fluxes
106
+ self .add_constraint_type ("rflxcmpc" ,"reaction" )
105
107
coefs [0 ][object .reverse_variable ] = 1
106
- BaseFBAPkg .build_constraint (self ,"rflxcmpc" ,0 ,0 ,coefs [0 ],object . id )
108
+ BaseFBAPkg .build_constraint (self ,"rflxcmpc" ,0 ,0 ,coefs [0 ],object )
107
109
if object .upper_bound > 0 :
108
110
#flux - flux_comp_0 - flux_comp_n = 0 - restriction of forward fluxes by component fluxes
111
+ self .add_constraint_type ("fflxcmpc" ,"reaction" )
109
112
coefs [1 ][object .forward_variable ] = 1
110
- BaseFBAPkg .build_constraint (self ,"fflxcmpc" ,0 ,0 ,coefs [1 ],object . id )
113
+ BaseFBAPkg .build_constraint (self ,"fflxcmpc" ,0 ,0 ,coefs [1 ],object )
111
114
return None
112
115
if type == "bflxcmp" and self .parameters ["binary_variable_count" ] > 0 :
113
116
for i in range (0 ,self .parameters ["binary_variable_count" ]):
114
117
if object .lower_bound < 0 :
115
- var = BaseFBAPkg .build_variable (self ,"brflxcmp" + str (i ),0 ,1 ,"binary" ,object .id )
118
+ self .add_variable_type ("brflxcmp" + str (i ),"reaction" )
119
+ var = BaseFBAPkg .build_variable (self ,"brflxcmp" + str (i ),0 ,1 ,"binary" ,object )
116
120
othervar = self .variables ["rflxcmp" + str (i )][object .id ]
117
- BaseFBAPkg .build_constraint (self ,"brflxcmpc" + str (i ),None ,0 ,{othervar :1 ,var :- 1000 },object .id )
121
+ self .add_constraint_type ("brflxcmpc" + str (i ),"reaction" )
122
+ BaseFBAPkg .build_constraint (self ,"brflxcmpc" + str (i ),None ,0 ,{othervar :1 ,var :- 1000 },object )
118
123
if object .upper_bound > 0 :
119
- var = BaseFBAPkg .build_variable (self ,"bfflxcmp" + str (i ),0 ,1 ,"binary" ,object .id )
124
+ self .add_variable_type ("bfflxcmp" + str (i ),"reaction" )
125
+ var = BaseFBAPkg .build_variable (self ,"bfflxcmp" + str (i ),0 ,1 ,"binary" ,object )
120
126
othervar = self .variables ["fflxcmp" + str (i )][object .id ]
121
- BaseFBAPkg .build_constraint (self ,"bfflxcmpc" + str (i ),None ,0 ,{othervar :1 ,var :- 1000 },object .id )
127
+ self .add_constraint_type ("bfflxcmpc" + str (i ),"reaction" )
128
+ BaseFBAPkg .build_constraint (self ,"bfflxcmpc" + str (i ),None ,0 ,{othervar :1 ,var :- 1000 },object )
122
129
return None
123
130
124
131
def build_constraint (self ,type ,object ,objective ,objterms ,coefficients ):
0 commit comments