@@ -30,7 +30,7 @@ def find_active_reactions(model, bigM=10000, zero_cutoff=None,
30
30
a large constant for bounding the optimization problem, default 1e4.
31
31
zero_cutoff: float, optional
32
32
The cutoff to consider for zero flux
33
- (default 1e-5 if relax_bounds is True, else model.tolerance) .
33
+ Default model.tolerance.
34
34
relax_bounds: True or False
35
35
Whether to relax the model bounds.
36
36
All +ve LB set as 0, all -ve UB set as 0, all -ve LB set as -bigM,
@@ -150,14 +150,14 @@ def find_active_reactions(model, bigM=10000, zero_cutoff=None,
150
150
active_rxns += [r .id for r in new_active_rxns ]
151
151
152
152
# loop to find any hidden forward active reactions
153
- constr_min_flux , n_lp_solved = loop_to_find_fwd_active_rxns (
153
+ constr_min_flux , n_lp_solved , min_flux = loop_to_find_fwd_active_rxns (
154
154
model , z_pos , z_neg , active_rxns , new_active_rxns , rxns_to_check ,
155
155
eps , max_iterations )
156
156
157
157
# loop to find any hidden reverse active reactions
158
158
loop_to_find_rev_active_rxns (model , active_rxns , rxns_to_check ,
159
159
constr_min_flux , n_lp_solved ,
160
- eps , max_iterations )
160
+ eps , min_flux , max_iterations )
161
161
162
162
return active_rxns
163
163
@@ -243,15 +243,11 @@ def build_opt_problem(model, bigM=10000, zero_cutoff=None, relax_bounds=True,
243
243
if max_bound < float ("inf" ):
244
244
bigM = max (bigM , max_bound )
245
245
246
- # at least 10x >= model. tolerance
247
- eps = model .tolerance * 1e2
246
+ # ensure bigM*z << eps at tolerance limit
247
+ eps = model .tolerance * bigM * 10
248
248
if zero_cutoff is not None :
249
249
eps = max (zero_cutoff , eps )
250
250
251
- # ensure bigM*z << eps at integrality tolerance limit
252
- if solve == "milp" :
253
- eps = max (eps , model .tolerance * bigM * 10 )
254
-
255
251
LOGGER .debug ("parameters:\n bigM\t %.f\n eps\t %.2e\n feas_tol\t %.2e" ,
256
252
bigM , eps , model .tolerance )
257
253
@@ -410,9 +406,12 @@ def loop_to_find_fwd_active_rxns(model, z_pos, z_neg, active_rxns,
410
406
411
407
weight_random = {r : np .round (np .random .random (), 6 ) for r in
412
408
rxns_to_check }
409
+ min_flux = sum (w for w in weight_random .values ()) * model .tolerance * 10
410
+ min_flux = max (eps , min_flux )
411
+ LOGGER .debug ("min_flux: %.4e" % min_flux )
413
412
constr_min_flux = model .problem .Constraint (
414
- sum ([ weight_random [ r ] * ( r .flux_expression ) for r in
415
- rxns_to_check ]) , lb = eps )
413
+ sum (w * r .flux_expression for r , w in
414
+ weight_random . items ()) , lb = min_flux )
416
415
model .add_cons_vars (constr_min_flux )
417
416
418
417
n_lp_solved = 3
@@ -442,12 +441,12 @@ def loop_to_find_fwd_active_rxns(model, z_pos, z_neg, active_rxns,
442
441
constr_min_flux .set_linear_coefficients (
443
442
{r .forward_variable : 0 , r .reverse_variable : 0 })
444
443
445
- return (constr_min_flux , n_lp_solved )
444
+ return (constr_min_flux , n_lp_solved , min_flux )
446
445
447
446
448
447
def loop_to_find_rev_active_rxns (model , active_rxns , rxns_to_check ,
449
448
constr_min_flux , n_lp_solved ,
450
- eps , max_iterations ):
449
+ eps , min_flux , max_iterations ):
451
450
"""
452
451
Subroutine of `find_active_reactions`.
453
452
Find flux distributions with >=1 negative flux until infeasibility.
@@ -458,8 +457,8 @@ def loop_to_find_rev_active_rxns(model, active_rxns, rxns_to_check,
458
457
" reactions are found:" )
459
458
460
459
# change the constraint into minimum negative flux
461
- constr_min_flux .lb = - eps
462
- constr_min_flux .ub = - eps
460
+ constr_min_flux .lb = - min_flux
461
+ constr_min_flux .ub = - min_flux
463
462
constr_min_flux .lb = None
464
463
feas_tol = model .tolerance
465
464
0 commit comments