opencobra / optlang

optlang - sympy based mathematical programming language
http://optlang.readthedocs.org/
Apache License 2.0
244 stars 51 forks source link

constraint.problem is not always being reset in _remove_constraints of Model #271

Open axelvonkamp opened 3 weeks ago

axelvonkamp commented 3 weeks ago

In _remove_constraints there is a branch when the number of constraints to be removed is > 350 (line 1578 in interface.py). When this is the case the constraints are removed but their problem attribute is not being set to None (as is being done in the else branch). This leads to an error when a list of more than 350 constraints is being added, then removed, and then being added again. Adding a simple loop

for c in constraints:
    c.problem = None

to the if branch will resolve this bug.

cdiener commented 3 weeks ago

Good catch! I will send in a fix.