Commit 5cc2cda3 authored by Peter Schubert's avatar Peter Schubert
Browse files

Support of protected functions with single constraint

parent ae1017ca
......@@ -338,8 +338,13 @@ class ReduceModel:
self._remove_constraints()
logging.warning('Something went wrong! Previous constraint was not removed explicitely')
df_constrs = self._protect_funcs.loc[k]
if type(df_constrs) == pd.Series:
df_constrs = pd.DataFrame([df_constrs.values],
columns=df_constrs.index,
index=[df_constrs.name])
self._active_constraints = []
for sub_i, (idx, row) in enumerate(self._protect_funcs.loc[k].iterrows()):
for sub_i, (idx, row) in enumerate(df_constrs.iterrows()):
# multiple reactions supported in one constraint
invalid_constr = False
expr = Add()
......@@ -354,7 +359,8 @@ class ReduceModel:
invalid_constr = True
break
if invalid_constr is False:
constr = self._red_model.problem.Constraint(expr, name='constr_' + str(k) + '_' + str(sub_i))
constr_name = 'constr_' + str(k) + '_' + str(sub_i)
constr = self._red_model.problem.Constraint(expr, name=constr_name)
if ~np.isnan(row['lb']):
constr.lb = row['lb']
if ~np.isnan(row['ub']):
......@@ -647,7 +653,7 @@ class ReduceModel:
free_rids = model_rids.difference(self._essential_rids)
flux_ranges = pd.DataFrame(dtype=float, index=list(free_rids))
if self._protect_funcs is not None:
for k in set(self._protect_funcs .index):
for k in set(self._protect_funcs.index):
self._add_constraints(k)
solution = self._red_model.optimize()
logging.info(' FBA status: %s, objective value: %8.3f', solution.status, solution.objective_value)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment