fixed problem with lp files making constraints with no lhs feasible

This commit is contained in:
Stuart Mitchell
2015-03-17 23:46:09 +13:00
parent 5617527818
commit 045a0ce53e
2 changed files with 26 additions and 1 deletions

View File

@@ -1499,7 +1499,10 @@ class LpProblem(object):
constraint = self.constraints[k]
if not list(constraint.keys()):
#empty constraint add the dummyVar
constraint += self.get_dummyVar()
dummyVar = self.get_dummyVar()
constraint += dummyVar
#set this dummyvar to zero so infeasible problems are not made feasible
f.write((dummyVar == 0.0).asCplexLpConstraint(k))
f.write(constraint.asCplexLpConstraint(k))
vs = self.variables()
# check if any names are longer than 100 characters

View File

@@ -64,6 +64,27 @@ def pulpTest001(solver):
print("\t Testing zero subtraction")
assert str(c2) #will raise an exception
def pulpTest009(solver):
# infeasible
prob = LpProblem("test09", LpMinimize)
x = LpVariable("x", 0, 4)
y = LpVariable("y", -1, 1)
z = LpVariable("z", 0)
w = LpVariable("w", 0)
prob += x + 4*y + 9*z, "obj"
prob += lpSum([v for v in [x] if False]) >= 5, "c1" #this is a 0 >=5 constraint
prob += x+z >= 10, "c2"
prob += -y+z == 7, "c3"
prob += w >= 0, "c4"
print("\t Testing inconsistant lp solution")
#this was a problem with use_mps=false
if solver.__class__ in [PULP_CBC_CMD, COIN_CMD]:
pulpTestCheck(prob, solver, [LpStatusInfeasible], {x:4, y:-1, z:6, w:0},
use_mps = False)
else:
pulpTestCheck(prob, solver, [LpStatusInfeasible, LpStatusNotSolved])
def pulpTest010(solver):
# Continuous
prob = LpProblem("test010", LpMinimize)
@@ -554,6 +575,7 @@ def pulpTest123(solver):
def pulpTestSolver(solver, msg = 0):
tests = [
pulpTest001,
pulpTest009,
pulpTest010, pulpTest011, pulpTest012, pulpTest013, pulpTest014,
pulpTest015, pulpTest016, pulpTest017,
pulpTest018, pulpTest019,