mirror of
https://github.com/ANL-CEEESA/MIPLearn.jl.git
synced 2025-12-07 00:48:50 -06:00
Remove object references from model.ext[:miplearn]
This commit is contained in:
@@ -6,10 +6,10 @@ function init_miplearn_ext(model)::Dict
|
||||
if :miplearn ∉ keys(model.ext)
|
||||
model.ext[:miplearn] = Dict{Symbol, Any}()
|
||||
model.ext[:miplearn][:instance_features] = [0.0]
|
||||
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}()
|
||||
model.ext[:miplearn][:variable_features] = Dict{AbstractString, Vector{Float64}}()
|
||||
model.ext[:miplearn][:variable_categories] = Dict{AbstractString, String}()
|
||||
model.ext[:miplearn][:constraint_features] = Dict{AbstractString, Vector{Float64}}()
|
||||
model.ext[:miplearn][:constraint_categories] = Dict{AbstractString, String}()
|
||||
end
|
||||
return model.ext[:miplearn]
|
||||
end
|
||||
@@ -24,28 +24,32 @@ end
|
||||
|
||||
function set_features!(v::VariableRef, f::Array{Float64})::Nothing
|
||||
ext = init_miplearn_ext(v.model)
|
||||
ext[:variable_features][v] = f
|
||||
n = _get_and_check_name(v)
|
||||
ext[:variable_features][n] = f
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
function set_category!(v::VariableRef, category::String)::Nothing
|
||||
ext = init_miplearn_ext(v.model)
|
||||
ext[:variable_categories][v] = category
|
||||
n = _get_and_check_name(v)
|
||||
ext[:variable_categories][n] = category
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
function set_features!(c::ConstraintRef, f::Array{Float64})::Nothing
|
||||
ext = init_miplearn_ext(c.model)
|
||||
ext[:constraint_features][c] = f
|
||||
n = _get_and_check_name(c)
|
||||
ext[:constraint_features][n] = f
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
function set_category!(c::ConstraintRef, category::String)::Nothing
|
||||
ext = init_miplearn_ext(c.model)
|
||||
ext[:constraint_categories][c] = category
|
||||
n = _get_and_check_name(c)
|
||||
ext[:constraint_categories][n] = category
|
||||
return
|
||||
end
|
||||
|
||||
@@ -63,6 +67,15 @@ macro category(obj, category)
|
||||
end
|
||||
end
|
||||
|
||||
function _get_and_check_name(obj)
|
||||
n = name(obj)
|
||||
length(n) > 0 || error(
|
||||
"Features and categories can only be assigned to variables and " *
|
||||
"constraints that have names. Unnamed model element detected."
|
||||
)
|
||||
return n
|
||||
end
|
||||
|
||||
|
||||
export @feature,
|
||||
@category
|
||||
|
||||
Reference in New Issue
Block a user