From 2d05105ccff6086f9364a36e3ca10e2880598198 Mon Sep 17 00:00:00 2001 From: Stuart Mitchell Date: Thu, 17 May 2012 21:32:22 +1200 Subject: [PATCH] Bugfix for lp format http://code.google.com/p/pulp-or/issues/detail?id=41 --- VERSION | 2 +- src/pulp/pulp.py | 4 ++-- src/pulp/solvers.py | 4 ++-- src/pulp/tests.py | 27 +++++++++++++++++++++++---- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/VERSION b/VERSION index 26ca594..4cda8f1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.5.1 +1.5.2 diff --git a/src/pulp/pulp.py b/src/pulp/pulp.py index 9c06f0b..7b2e5c0 100755 --- a/src/pulp/pulp.py +++ b/src/pulp/pulp.py @@ -680,7 +680,7 @@ class LpAffineExpression(_DICT_TYPE): term = " + %s" % self.constant if self._count_characters(line) + len(term) > LpCplexLPLineSize: result += ["".join(line)] - line = [term] + line += [term] else: line += [term] result += ["".join(line)] @@ -859,7 +859,7 @@ class LpConstraint(LpAffineExpression): c = 0 # Supress sign term = " %s %.12g" % (LpConstraintSenses[self.sense], c) if self._count_characters(line)+len(term) > LpCplexLPLineSize: - line = "".join(line) + result += ["".join(line)] line = [term] else: line += [term] diff --git a/src/pulp/solvers.py b/src/pulp/solvers.py index e478c4b..e242afe 100644 --- a/src/pulp/solvers.py +++ b/src/pulp/solvers.py @@ -1222,9 +1222,9 @@ class COIN_CMD(LpSolver_CMD): aCopy.strong = self.strong return aCopy - def actualSolve(self, lp): + def actualSolve(self, lp, **kwargs): """Solve a well formulated lp problem""" - return self.solve_CBC(lp) + return self.solve_CBC(lp, **kwargs) def available(self): """True if the solver is available""" diff --git a/src/pulp/tests.py b/src/pulp/tests.py index f7b8cd5..5a786ad 100644 --- a/src/pulp/tests.py +++ b/src/pulp/tests.py @@ -8,10 +8,11 @@ def pulpTestCheck(prob, solver, okstatus, sol = {}, duals = None, slacks = None, eps = 10**-3, - status = None): + status = None, + **kwargs): if status is None: - status = prob.solve(solver) + status = prob.solve(solver, **kwargs) if status not in okstatus: prob.writeLP("debug.lp") prob.writeMPS("debug.mps") @@ -215,6 +216,22 @@ def pulpTest017(solver): print "\t Testing LpVariable (not LpAffineExpression) objective" pulpTestCheck(prob, solver, [LpStatusOptimal]) +def pulpTest018(solver): + # Long name in lp + prob = LpProblem("test013", LpMinimize) + x = LpVariable("x"*90, 0, 4) + y = LpVariable("y"*90, -1, 1) + z = LpVariable("z"*90, 0) + w = LpVariable("w"*90, 0) + prob += x + 4*y + 9*z, "obj" + prob += x+y <= 5, "c1" + prob += x+z >= 10, "c2" + prob += -y+z == 7, "c3" + prob += w >= 0, "c4" + if solver.__class__ in [COIN_CMD]: + print "\t Testing Long lines in LP" + pulpTestCheck(prob, solver, [LpStatusOptimal], {x:4, y:-1, z:6, w:0}, + use_mps=False) def pulpTest020(solver): # MIP @@ -520,9 +537,11 @@ def pulpTest123(solver): def pulpTestSolver(solver, msg = 0): - tests = [pulpTest001, - pulpTest010, pulpTest011, pulpTest012, pulpTest013, pulpTest014, + tests = [ + pulpTest001, + pulpTest010, pulpTest011, pulpTest012, pulpTest013, pulpTest014, pulpTest015, pulpTest016, pulpTest017, + pulpTest018, pulpTest020, pulpTest030, pulpTest040,