From 97cdc5731ae4edb7a81c184ce6482829812b38a5 Mon Sep 17 00:00:00 2001 From: Stuart Mitchell Date: Fri, 3 Apr 2015 03:17:12 +0000 Subject: [PATCH 1/3] added timelimit to cplex_cmd hopefully fixes https://github.com/coin-or/pulp-or/issues/74 --- src/pulp/solvers.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pulp/solvers.py b/src/pulp/solvers.py index f9b9138..65dfd86 100644 --- a/src/pulp/solvers.py +++ b/src/pulp/solvers.py @@ -429,6 +429,12 @@ GLPK = GLPK_CMD class CPLEX_CMD(LpSolver_CMD): """The CPLEX LP solver""" + + def __init__(self, path = None, keepFiles = 0, mip = 1, + msg = 0, options = [], timelimit = None): + LpSolver_CMD.__init__(self, path, keepFiles, mip, msg, options) + self.timelimit = timelimit + def defaultPath(self): return self.executableExtension("cplex") @@ -456,6 +462,8 @@ class CPLEX_CMD(LpSolver_CMD): else: cplex = subprocess.Popen(self.path, stdin = subprocess.PIPE) cplex_cmds = "read "+tmpLp+"\n" + if self.timelimit is not None: + cplex_cmds += "set timelimit " + self.timelimt + "\n" for option in self.options: cplex_cmds += option+"\n" if lp.isMIP(): From e0757f9f50af559a85fbe7ad47ed9173733f3bfb Mon Sep 17 00:00:00 2001 From: Stuart Mitchell Date: Fri, 3 Apr 2015 03:25:11 +0000 Subject: [PATCH 2/3] fixes encoding for cplex_cmd https://github.com/coin-or/pulp-or/issues/73 --- src/pulp/solvers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pulp/solvers.py b/src/pulp/solvers.py index 65dfd86..5361288 100644 --- a/src/pulp/solvers.py +++ b/src/pulp/solvers.py @@ -476,6 +476,7 @@ class CPLEX_CMD(LpSolver_CMD): cplex_cmds += "optimize\n" cplex_cmds += "write "+tmpSol+"\n" cplex_cmds += "quit\n" + cplex_cmds = cplex_cmds.encode('UTF-8') cplex.communicate(cplex_cmds) if cplex.returncode != 0: raise PulpSolverError("PuLP: Error while trying to execute "+self.path) From 1b5e9c697d455df5f82504bd22d4b99c2cae6a5a Mon Sep 17 00:00:00 2001 From: timnon Date: Thu, 23 Apr 2015 09:29:57 +0200 Subject: [PATCH 3/3] Update solvers.py fix of typo and string conversion --- src/pulp/solvers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pulp/solvers.py b/src/pulp/solvers.py index 5361288..22e55ce 100644 --- a/src/pulp/solvers.py +++ b/src/pulp/solvers.py @@ -463,7 +463,7 @@ class CPLEX_CMD(LpSolver_CMD): cplex = subprocess.Popen(self.path, stdin = subprocess.PIPE) cplex_cmds = "read "+tmpLp+"\n" if self.timelimit is not None: - cplex_cmds += "set timelimit " + self.timelimt + "\n" + cplex_cmds += "set timelimit " + str(self.timelimit) + "\n" for option in self.options: cplex_cmds += option+"\n" if lp.isMIP(): @@ -2523,4 +2523,4 @@ class GurobiFormulation(object): self.objective.name = name else: raise TypeError("Can only add LpConstraint, LpAffineExpression or True objects") - return self \ No newline at end of file + return self