From 045a0ce53e2aeadbde4c5dc5ab443648c81b0162 Mon Sep 17 00:00:00 2001 From: Stuart Mitchell Date: Tue, 17 Mar 2015 23:46:09 +1300 Subject: [PATCH] fixed problem with lp files making constraints with no lhs feasible --- src/pulp/pulp.py | 5 ++++- src/pulp/tests.py | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/pulp/pulp.py b/src/pulp/pulp.py index 97c4ed0..de2c2c6 100644 --- a/src/pulp/pulp.py +++ b/src/pulp/pulp.py @@ -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 diff --git a/src/pulp/tests.py b/src/pulp/tests.py index f803a71..6d63a81 100644 --- a/src/pulp/tests.py +++ b/src/pulp/tests.py @@ -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,