Merge pull request #96 from ryanjoneil/silent-objective-overwrite

pulp.LpProblem issues a warning on implicit overwrite of previously set objective function.
This commit is contained in:
Stuart Mitchell 2017-02-06 23:05:47 +13:00 committed by GitHub
commit a9ff0aca84
1 changed files with 5 additions and 0 deletions

View File

@ -96,6 +96,7 @@ References:
import types
import string
import itertools
import warnings
from .constants import *
from .solvers import *
@ -1330,9 +1331,13 @@ class LpProblem(object):
elif isinstance(other, LpConstraint):
self.addConstraint(other, name)
elif isinstance(other, LpAffineExpression):
if self.objective is not None:
warnings.warn("Overwriting previously set objective.")
self.objective = other
self.objective.name = name
elif isinstance(other, LpVariable) or isinstance(other, (int, float)):
if self.objective is not None:
warnings.warn("Overwriting previously set objective.")
self.objective = LpAffineExpression(other)
self.objective.name = name
else: