Skip to content

Commit

Permalink
Fix flux and reduced_cost retrieval in Reaction.
Browse files Browse the repository at this point in the history
# Kristian reported the following problem
model.reactions.get_by_id("EX_glc_lp_e_rp_").lower_bound = -10
model.reactions.get_by_id("EX_glc_lp_e_rp_").upper_bound = -9

cameo.fba(model)["EX_glc_lp_e_rp_"]
# returns 0

cameo.fba(model)["Ec_biomass_iJO1366_core_53p95M"]
# returns 0.98...
  • Loading branch information
phantomas1234 committed May 26, 2015
1 parent 12fbf40 commit 74c1544
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions cameo/core/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def objective_coefficient(self, value):
model = self.model
if model is not None:
model.solver._set_linear_objective_term(self.forward_variable, value)

model.solver._set_linear_objective_term(self.reverse_variable, -1*value)
self._objective_coefficient = value

@property
Expand All @@ -281,23 +281,15 @@ def effective_upper_bound(self):

@property
def flux(self):
if self.forward_variable is not None:
primal = self.forward_variable.primal
if self.reversibility:
primal -= self.reverse_variable.primal
return primal
if self.model is not None:
return self.forward_variable.primal - self.reverse_variable.primal
else:
return None

@property
def reduced_cost(self):
if self.forward_variable is not None:
dual = self.forward_variable.dual
if dual is None: # cplex cannot determine reduced costs for MILP problems
return None
if self.reversibility:
dual -= self.reverse_variable.dual
return dual
if self.model is not None:
return self.forward_variable.dual - self.reverse_variable.dual
else:
return None

Expand Down

0 comments on commit 74c1544

Please sign in to comment.