Skip to content

Commit

Permalink
add default time limit of 5min when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscoey committed Sep 19, 2023
1 parent d4b836f commit 2bee43d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ We always support the following options:

- `silent`: [Bool] Controls if the solver prints any logs.
- `time_limit_sec`: [Float64] Limits the total time expended. The optimization
returns a `TIME_LIMIT` status.
returns a `TIME_LIMIT` status. If not provided, a default of 300s is used.
- `print_only`: [Bool] If set to true the model will only be printed
and not solved.
- `print_format`: [String] If and how the model should be
printed. Currently supported formats: MOI, LaTeX, MOF, LP, MPS, NL.
- `print_format`: [String] If and how the model should be printed.
Currently supported formats: MOI, LaTeX, MOF, LP, MPS, NL.

### Response

Expand Down
13 changes: 8 additions & 5 deletions src/SolverAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,7 @@ end
function initialize(json::Request, solver::MOI.AbstractOptimizer)#::Tuple{Type, Dict{Symbol, Any}, MOI.ModelLike}
solver_info = Dict{Symbol,Any}()

# TODO (dba) `SolverAPI.jl` should be decoupled from any solver
# specific code.
# TODO (dba) `SolverAPI.jl` should be decoupled from any solver specific code.
options = get(() -> Dict{String,Any}(), json, :options)
if lowercase(get(options, :solver, "highs")) == "minizinc"
T = Int
Expand All @@ -367,11 +366,15 @@ function initialize(json::Request, solver::MOI.AbstractOptimizer)#::Tuple{Type,

model = MOI.instantiate(() -> solver; with_cache_type = T, with_bridge_type = T)

if MOI.supports(model, MOI.TimeLimitSec())
# Set time limit, defaulting to 5min.
MOI.set(model, MOI.TimeLimitSec(), Float64(get(options, :time_limit_sec, 300.0)))
end

# Set other solver options.
for (key, val) in options
if key in [:solver, :print_format, :print_only]
if key in [:solver, :print_format, :print_only, :time_limit_sec]
continue
elseif key == :time_limit_sec
MOI.set(model, MOI.TimeLimitSec(), Float64(val))
elseif key == :silent
MOI.set(model, MOI.Silent(), Bool(val))
else
Expand Down

0 comments on commit 2bee43d

Please sign in to comment.