Skip to content

Commit

Permalink
fixes #348: options in SCIP_CMD. Added timeLimit and maxNodes argumen…
Browse files Browse the repository at this point in the history
…ts to SCIP_CMD to interface.
  • Loading branch information
pchtsp committed Oct 20, 2020
1 parent 9b7f53f commit cd7a542
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions pulp/apis/scip_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ class SCIP_CMD(LpSolver_CMD):
"""The SCIP optimization solver"""
name ='SCIP_CMD'

def __init__(self, path=None, keepFiles=False, mip=True, msg=True, options=None):
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, options=None, timeLimit=None, maxNodes=None):
"""
:param bool mip: if False, assume LP even if integer variables
:param bool msg: if False, no log is shown
:param list options: list of additional options to pass to solver
:param bool keepFiles: if True, files are saved in the current directory and not deleted after solving
:param str path: path to the solver binary
:param float timeLimit: maximum time for solver (in seconds)
:param int maxNodes: max number of nodes during branching. Stops the solving when reached.
"""
LpSolver_CMD.__init__(self, mip=mip, msg=msg, options=options, path=path, keepFiles=keepFiles)
LpSolver_CMD.__init__(self, mip=mip, msg=msg, options=options, path=path,
keepFiles=keepFiles, timeLimit=timeLimit, maxNodes=maxNodes)

SCIP_STATUSES = {
'unknown': constants.LpStatusUndefined,
Expand Down Expand Up @@ -82,13 +85,18 @@ def actualSolve(self, lp):

tmpLp, tmpSol = self.create_tmp_files(lp.name, 'lp', 'sol')
lp.writeLP(tmpLp)
proc = [
'%s' % self.path, '-c', 'read "%s"' % tmpLp, '-c', 'optimize',
'-c', 'write solution "%s"' % tmpSol, '-c', 'quit'
]

proc = ['%s' % self.path, '-c', 'read "%s"' % tmpLp]
if self.timeLimit is not None:
proc.extend(['-c', 'set limits time {}'.format(self.timeLimit)])

maxNodes = self.optionsDict.get('maxNodes')
if maxNodes is not None:
proc.extend(['-c', 'set limits nodes {}'.format(maxNodes)])
proc.extend(self.options)
if not self.msg:
proc.append('-q')
proc.extend(['-c', 'optimize', '-c', 'write solution "%s"' % tmpSol, '-c', 'quit'])

self.solution_time = clock()
subprocess.check_call(proc, stdout=sys.stdout, stderr=sys.stderr)
Expand Down

0 comments on commit cd7a542

Please sign in to comment.