Skip to content

Commit

Permalink
add timeLimit arg to __init__ (coin-or#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidggphy authored Dec 3, 2022
1 parent 0a7c675 commit cb6d294
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pulp/apis/mosek_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from .. import constants
import sys

from typing import Optional


class MOSEK(LpSolver):
"""Mosek lp and mip solver (via Mosek Optimizer API)."""
Expand All @@ -54,7 +56,8 @@ def __init__(
self,
mip=True,
msg=True,
options={},
timeLimit: Optional[float] = None,
options: Optional[dict] = None,
task_file_name="",
sol_type=mosek.soltype.bas,
):
Expand All @@ -66,6 +69,8 @@ def __init__(
@param msg: Enable Mosek log output.
@param float timeLimit: maximum time for solver (in seconds)
@param options: Accepts a dictionary of Mosek solver parameters. Ignore to
use default parameter values. Eg: options = {mosek.dparam.mio_max_time:30}
sets the maximum time spent by the Mixed Integer optimizer to 30 seconds.
Expand All @@ -85,9 +90,19 @@ def __init__(
"""
self.mip = mip
self.msg = msg
self.timeLimit = timeLimit
self.task_file_name = task_file_name
self.solution_type = sol_type
if options is None:
options = {}
self.options = options
if self.timeLimit is not None:
timeLimit_keys = {"MSK_DPAR_MIO_MAX_TIME", mosek.dparam.mio_max_time}
if not timeLimit_keys.isdisjoint(self.options.keys()):
raise ValueError(
"timeLimit parameter has been provided trough `timeLimit` and `options`."
)
self.options["MSK_DPAR_MIO_MAX_TIME"] = self.timeLimit

def available(self):
"""True if Mosek is available."""
Expand Down

0 comments on commit cb6d294

Please sign in to comment.