Skip to content

Commit

Permalink
Improve python-mip performance building models
Browse files Browse the repository at this point in the history
  • Loading branch information
pablormier committed Mar 22, 2022
1 parent 881c208 commit 59f7b4a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions miom/miom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,10 +1175,11 @@ def _add_constraint(self, constraint, **kwargs):

def _steady_state(self, **kwargs):
V = [self.problem.add_var(lb=rxn['lb'], ub=rxn['ub'], name=f"V_{i}") for i, rxn in enumerate(self.network.R)]
# (Python-MIP does not allow matrix operations like CyLP or CXVOPT)
for i in range(self.network.S.shape[0]):
self.problem += mip.xsum(self.network.S[i, j] * V[j]
for j in range(self.network.R.shape[0]) if self.network.S[i, j] != 0) == 0
non_zero_cols = np.flatnonzero(self.network.S[i, :] != 0)
if len(non_zero_cols) > 0:
self.problem += mip.xsum(self.network.S[i, j] * V[j]
for j in non_zero_cols) == 0
self.variables._flux_vars = V
return True

Expand Down

0 comments on commit 59f7b4a

Please sign in to comment.