Skip to content

Commit

Permalink
workaround to deactivate messages on licenses
Browse files Browse the repository at this point in the history
  • Loading branch information
pchtsp committed Jul 12, 2024
1 parent a96fae6 commit 1cabad0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pulp/apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def listSolvers(onlyAvailable=False):
"""
result = []
for s in _all_solvers:
solver = s()
solver = s(msg=False)
if (not onlyAvailable) or solver.available():
result.append(solver.name)
del solver
Expand Down
16 changes: 12 additions & 4 deletions pulp/apis/copt_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from uuid import uuid4
from .core import sparse, ctypesArrayFill, PulpSolverError
from .core import clock, log
from .core import clock

from .core import LpSolver, LpSolver_CMD
from ..constants import (
Expand Down Expand Up @@ -894,9 +894,17 @@ def __init__(
logPath=logPath,
warmStart=warmStart,
)

self.coptenv = coptpy.Envr()
self.coptmdl = self.coptenv.createModel()
# workaround to deactivate logging when msg=False
if not self.msg:
devnull = open("/dev/null", "w")
oldstdout_fno = os.dup(sys.stdout.fileno())
os.dup2(devnull.fileno(), 1)
self.coptenv = coptpy.Envr()
self.coptmdl = self.coptenv.createModel()
os.dup2(oldstdout_fno, 1)
else:
self.coptenv = coptpy.Envr()
self.coptmdl = self.coptenv.createModel()

if not self.msg:
self.coptmdl.setParam("Logging", 0)
Expand Down
3 changes: 2 additions & 1 deletion pulp/apis/gurobi_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ def available(self):
# normal execution
return True
# error: we display the gurobi message
warnings.warn(f"GUROBI error: {out}.")
if self.msg:
warnings.warn(f"GUROBI error: {out}.")
return False

def actualSolve(self, lp):
Expand Down

0 comments on commit 1cabad0

Please sign in to comment.