Skip to content

Commit

Permalink
Merge pull request #42 from joehuchette/rawparameter
Browse files Browse the repository at this point in the history
Add support for getting/setting MOI.RawParameters
  • Loading branch information
joehuchette authored Aug 4, 2020
2 parents 373a2eb + 02f8671 commit 3b73fa4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/BARON.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ mutable struct SolutionStatus
end

mutable struct BaronModel
options::Dict{Symbol, Any}
options::Dict{String, Any}

variable_info::Vector{VariableInfo}
constraint_info::Vector{ConstraintInfo}
Expand All @@ -80,7 +80,7 @@ mutable struct BaronModel
solution_info::Union{Nothing, SolutionStatus}

function BaronModel(; kwargs...)
options = Dict{Symbol, Any}(key => val for (key,val) in kwargs)
options = Dict{String, Any}(string(key) => val for (key,val) in kwargs)
model = new()
model.options = options
model.variable_info = VariableInfo[]
Expand All @@ -89,10 +89,10 @@ mutable struct BaronModel
model.objective_expr = nothing
temp_dir = mktempdir()
model.temp_dir_name = temp_dir
model.problem_file_name = get!(options, :ProName, joinpath(temp_dir, "baron_problem.bar"))
model.times_file_name = get!(options, :TimName, joinpath(temp_dir, "tim.lst"))
model.summary_file_name = get!(options, :SumName, joinpath(temp_dir, "sum.lst"))
model.result_file_name = get!(options, :ResName, joinpath(temp_dir, "res.lst"))
model.problem_file_name = get!(options, "ProName", joinpath(temp_dir, "baron_problem.bar"))
model.times_file_name = get!(options, "TimName", joinpath(temp_dir, "tim.lst"))
model.summary_file_name = get!(options, "SumName", joinpath(temp_dir, "sum.lst"))
model.result_file_name = get!(options, "ResName", joinpath(temp_dir, "res.lst"))
model.solution_info = nothing
return model
end
Expand Down
19 changes: 16 additions & 3 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ function MOI.is_empty(model::Optimizer)
end

function MOI.empty!(model::Optimizer)
model.inner = BaronModel(; model.inner.options...)
model.inner = BaronModel(; ((Symbol(key), val) for (key, val) in model.inner.options)...)
model.nlp_block_data = nothing
return
end

# copy
Expand All @@ -57,16 +58,28 @@ function MOI.optimize!(model::Optimizer)
read_results(model.inner)
end

# RawParameter
MOI.supports(::Optimizer, ::MOI.RawParameter) = true
function MOI.set(model::Optimizer, param::MOI.RawParameter, value)
model.inner.options[param.name] = value
return
end
function MOI.get(model::Optimizer, param::MOI.RawParameter)
return get(model.inner.options, param.name) do
throw(ErrorException("Requested parameter $(param.name) is not set."))
end
end

# TimeLimitSec
MOI.supports(::Optimizer, ::MOI.TimeLimitSec) = true
function MOI.set(model::Optimizer, ::MOI.TimeLimitSec, val::Real)
model.inner.options[:MaxTime] = Float64(val)
model.inner.options["MaxTime"] = Float64(val)
return
end

# BARON's default time limit is 1000 seconds.
function MOI.get(model::Optimizer, ::MOI.TimeLimitSec)
return get(model.inner.options, :MaxTime, 1000.0)
return get(model.inner.options, "MaxTime", 1000.0)
end

include(joinpath("moi", "util.jl"))
Expand Down

0 comments on commit 3b73fa4

Please sign in to comment.