mirror of
https://github.com/ANL-CEEESA/MIPLearn.jl.git
synced 2025-12-06 08:28:52 -06:00
Simplify ext dictionary
This commit is contained in:
@@ -4,68 +4,47 @@
|
||||
|
||||
function init_miplearn_ext(model)::Dict
|
||||
if :miplearn ∉ keys(model.ext)
|
||||
model.ext[:miplearn] = Dict{Symbol,Any}(
|
||||
:features => Dict(
|
||||
:variables => Dict{String,Dict}(),
|
||||
:constraints => Dict{String,Dict}(),
|
||||
:instance => Dict{Symbol,Any}(),
|
||||
),
|
||||
:training_samples => [],
|
||||
)
|
||||
model.ext[:miplearn] = Dict{Symbol, Any}()
|
||||
model.ext[:miplearn][:variable_features] = Dict{VariableRef, Vector{Float64}}()
|
||||
model.ext[:miplearn][:variable_categories] = Dict{VariableRef, String}()
|
||||
model.ext[:miplearn][:constraint_features] = Dict{ConstraintRef, Vector{Float64}}()
|
||||
model.ext[:miplearn][:constraint_categories] = Dict{ConstraintRef, String}()
|
||||
end
|
||||
return model.ext[:miplearn]
|
||||
end
|
||||
|
||||
|
||||
function init_miplearn_ext(v::VariableRef)::Dict
|
||||
ext = init_miplearn_ext(v.model)
|
||||
if name(v) ∉ keys(ext[:features][:variables])
|
||||
ext[:features][:variables][name(v)] = Dict{Symbol,Any}()
|
||||
end
|
||||
return ext
|
||||
end
|
||||
|
||||
|
||||
function init_miplearn_ext(c::ConstraintRef)::Dict
|
||||
ext = init_miplearn_ext(c.model)
|
||||
if name(c) ∉ keys(ext[:features][:constraints])
|
||||
ext[:features][:constraints][name(c)] = Dict{Symbol,Any}()
|
||||
end
|
||||
return ext
|
||||
end
|
||||
|
||||
|
||||
function set_features!(m::Model, f::Array{Float64})::Nothing
|
||||
ext = init_miplearn_ext(m)
|
||||
ext[:features][:instance][:user_features] = f
|
||||
ext[:instance_features] = f
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
function set_features!(v::VariableRef, f::Array{Float64})::Nothing
|
||||
ext = init_miplearn_ext(v)
|
||||
ext[:features][:variables][name(v)][:user_features] = f
|
||||
ext = init_miplearn_ext(v.model)
|
||||
ext[:variable_features][v] = f
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
function set_category!(v::VariableRef, category::String)::Nothing
|
||||
ext = init_miplearn_ext(v)
|
||||
ext[:features][:variables][name(v)][:category] = category
|
||||
ext = init_miplearn_ext(v.model)
|
||||
ext[:variable_categories][v] = category
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
function set_features!(c::ConstraintRef, f::Array{Float64})::Nothing
|
||||
ext = init_miplearn_ext(c)
|
||||
ext[:features][:constraints][name(c)][:user_features] = f
|
||||
ext = init_miplearn_ext(c.model)
|
||||
ext[:constraint_features][c] = f
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
function set_category!(c::ConstraintRef, category::String)::Nothing
|
||||
ext = init_miplearn_ext(c)
|
||||
ext[:features][:constraints][name(c)][:category] = category
|
||||
ext = init_miplearn_ext(c.model)
|
||||
ext[:constraint_categories][c] = category
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user