diff --git a/README.md b/README.md index d1c880e..12af970 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/SolverAPI.jl b/src/SolverAPI.jl index 164fabf..f11f663 100644 --- a/src/SolverAPI.jl +++ b/src/SolverAPI.jl @@ -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 @@ -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