Skip to content

Commit

Permalink
Merge branch 'master' into aphi
Browse files Browse the repository at this point in the history
  • Loading branch information
pchtsp committed Sep 24, 2023
2 parents 9d551c9 + 9b59ce4 commit a4dfbda
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
# Semantic version range syntax or exact version of a Python version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-to-test-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Build and publish Python 🐍 distributions 📦 to PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3
uses: actions/setup-python@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
os: [ubuntu-latest, macOS-latest, windows-latest]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand Down
10 changes: 10 additions & 0 deletions pulp/apis/cplex_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ def __init__(
logPath=None,
epgap=None,
logfilename=None,
threads=None,
):
"""
:param bool mip: if False, assume LP even if integer variables
Expand All @@ -313,6 +314,7 @@ def __init__(
:param str logPath: path to the log file
:param float epgap: deprecated for gapRel
:param str logfilename: deprecated for logPath
:param int threads: number of threads to be used by CPLEX to solve a problem (default None uses all available)
"""
if epgap is not None:
warnings.warn("Parameter epgap is being depreciated for gapRel")
Expand All @@ -337,6 +339,7 @@ def __init__(
timeLimit=timeLimit,
warmStart=warmStart,
logPath=logPath,
threads=threads,
)

def available(self):
Expand Down Expand Up @@ -455,6 +458,7 @@ def cplex_var_types(var):
self.changeEpgap(gapRel)
if self.timeLimit is not None:
self.setTimeLimit(self.timeLimit)
self.setThreads(self.optionsDict.get("threads", None))
if self.optionsDict.get("warmStart", False):
# We assume "auto" for the effort_level
effort = self.solverModel.MIP_starts.effort_level.auto
Expand All @@ -478,6 +482,12 @@ def setlogfile(self, fileobj):
self.solverModel.set_warning_stream(fileobj)
self.solverModel.set_results_stream(fileobj)

def setThreads(self, threads=None):
"""
Change cplex thread count used (None is default which uses all available resources)
"""
self.solverModel.parameters.threads.set(threads or 0)

def changeEpgap(self, epgap=10**-4):
"""
Change cplex solver integer bound gap tolerence
Expand Down
23 changes: 23 additions & 0 deletions pulp/tests/test_pulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,29 @@ def test_pulp_123(self):
else:
pulpTestCheck(prob, self.solver, [const.LpStatusUnbounded])

def test_msg_arg(self):
"""
Test setting the msg arg to True does not interfere with solve
"""
prob = LpProblem("test_msg_arg", const.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 += x + y <= 5, "c1"
prob += x + z >= 10, "c2"
prob += -y + z == 7, "c3"
prob += w >= 0, "c4"
data = prob.toDict()
var1, prob1 = LpProblem.fromDict(data)
x, y, z, w = (var1[name] for name in ["x", "y", "z", "w"])

self.solver.msg = True
pulpTestCheck(
prob1, self.solver, [const.LpStatusOptimal], {x: 4, y: -1, z: 6, w: 0}
)

def test_pulpTestAll(self):
"""
Test the availability of the function pulpTestAll
Expand Down

0 comments on commit a4dfbda

Please sign in to comment.