From 7580ae6d504d1028c150220abf2939e1e17b5b18 Mon Sep 17 00:00:00 2001 From: Stuart Mitchell Date: Sat, 18 Apr 2015 02:56:36 +0000 Subject: [PATCH 1/2] fixed problem with scientific notation in glpk solution --- src/pulp/pulp.cfg.osx | 2 +- src/pulp/solvers.py | 2 +- src/pulp/tests.py | 35 +++++++++++++++++++++++++++++------ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/pulp/pulp.cfg.osx b/src/pulp/pulp.cfg.osx index b359d99..7bc2df1 100644 --- a/src/pulp/pulp.cfg.osx +++ b/src/pulp/pulp.cfg.osx @@ -12,7 +12,7 @@ CplexPath = /usr/ilog/cplex/bin/x86_rhel4.0_3.4/libcplex110.so GurobiPath = /opt/gurobi201/linux32/lib/python2.5 CbcPath = cbc GlpkPath = glpsol -PulpCbcPath = %(here)s/solverdir/cbc/%(os)s/%(arch)scbc +PulpCbcPath = %(here)s/solverdir/cbc/%(os)s/%(arch)s/cbc [licenses] ilm_cplex_license = "LICENSE your-enterprise\nRUNTIME NEVER ..." ilm_cplex_license_signature = 0 diff --git a/src/pulp/solvers.py b/src/pulp/solvers.py index f9b9138..d556922 100644 --- a/src/pulp/solvers.py +++ b/src/pulp/solvers.py @@ -419,7 +419,7 @@ class GLPK_CMD(LpSolver_CMD): name = line[1] if len(line) ==2: line = [0,0]+f.readline().split() if isInteger: - if line[2] == "*": value = int(line[3]) + if line[2] == "*": value = int(float(line[3])) else: value = float(line[2]) else: value = float(line[3]) diff --git a/src/pulp/tests.py b/src/pulp/tests.py index bffdd88..979e201 100644 --- a/src/pulp/tests.py +++ b/src/pulp/tests.py @@ -9,6 +9,7 @@ def pulpTestCheck(prob, solver, okstatus, sol = {}, slacks = None, eps = 10**-3, status = None, + objective = None, **kwargs): if status is None: @@ -48,9 +49,17 @@ def pulpTestCheck(prob, solver, okstatus, sol = {}, if abs(c.slack - slack) > eps: prob.writeLP("debug.lp") prob.writeMPS("debug.mps") - print(("Test failed: constraint.slack", cname , "==", - c.slack, "!=", slack)) - raise PulpError("Tests failed for solver %s"%solver) + print("Test failed: constraint.slack", cname , "==", + c.slack, "!=", slack) + raise PulpError("Tests failed for solver %s" % solver) + if objective is not None: + z = prob.objective.value() + if abs(z - objective) > eps: + prob.writeLP("debug.lp") + prob.writeMPS("debug.mps") + print("Test failed: objective ", z, " != ", objective) + raise PulpError("Tests failed for solver %s" % solver) + def pulpTest001(solver): """ @@ -224,7 +233,7 @@ def pulpTest016(solver): def pulpTest017(solver): # variable as objective - prob = LpProblem("test016", LpMinimize) + prob = LpProblem("test017", LpMinimize) x = LpVariable("x", 0, 4) y = LpVariable("y", -1, 1) z = LpVariable("z", 0) @@ -240,7 +249,7 @@ def pulpTest017(solver): def pulpTest018(solver): # Long name in lp - prob = LpProblem("test013", LpMinimize) + prob = LpProblem("test018", LpMinimize) x = LpVariable("x"*90, 0, 4) y = LpVariable("y"*90, -1, 1) z = LpVariable("z"*90, 0) @@ -283,6 +292,20 @@ def pulpTest020(solver): print("\t Testing MIP solution") pulpTestCheck(prob, solver, [LpStatusOptimal], {x:3, y:-0.5, z:7}) +def pulpTest021(solver): + # MIP with floats in objective + prob = LpProblem("test021", LpMinimize) + x = LpVariable("x", 0, 4) + y = LpVariable("y", -1, 1) + z = LpVariable("z", 0, None, LpInteger) + prob += 1.1 * x + 4.1 * y + 9.1 * z, "obj" + prob += x+y <= 5, "c1" + prob += x+z >= 10, "c2" + prob += -y+z == 7.5, "c3" + print("\t Testing MIP solution with floats in objective") + pulpTestCheck(prob, solver, [LpStatusOptimal], {x:3, y:-0.5, z:7}, + objective=64.95) + def pulpTest030(solver): # relaxed MIP prob = LpProblem("test030", LpMinimize) @@ -580,7 +603,7 @@ def pulpTestSolver(solver, msg = 0): pulpTest010, pulpTest011, pulpTest012, pulpTest013, pulpTest014, pulpTest015, pulpTest016, pulpTest017, pulpTest018, pulpTest019, - pulpTest020, + pulpTest020, pulpTest021, pulpTest030, pulpTest040, pulpTest050, From be09116d483677561f33890eae26d15b0f1f3f65 Mon Sep 17 00:00:00 2001 From: Stuart Mitchell Date: Sat, 18 Apr 2015 08:38:12 +0000 Subject: [PATCH 2/2] version bump --- setup.py | 2 +- src/pulp/constants.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index df76d6c..119ae6e 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,7 @@ problems. keywords = ["Optimization", "Linear Programming", "Operations Research"], author="J.S. Roy and S.A. Mitchell", author_email="pulp@stuartmitchell.com", - url="https://github.com/stumitchell/pulp-or", + url="https://github.com/coin-or/pulp", classifiers = ['Development Status :: 5 - Production/Stable', 'Environment :: Console', 'Intended Audience :: Science/Research', diff --git a/src/pulp/constants.py b/src/pulp/constants.py index 7c11346..139deb1 100644 --- a/src/pulp/constants.py +++ b/src/pulp/constants.py @@ -28,7 +28,7 @@ This file contains the constant definitions for PuLP Note that hopefully these will be changed into something more pythonic """ -VERSION = '1.5.8' +VERSION = '1.5.9' EPS = 1e-7 # variable categories