Skip to content

Commit

Permalink
fix custom data (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
guimarqu authored Apr 14, 2023
1 parent fe5d418 commit bb04c3d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
4 changes: 0 additions & 4 deletions src/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ function MOI.submit(
return MOI.submit(JuMP.backend(model), cb, JuMP.moi_function(con.func), con.set, custom_data)
end

MathOptInterface.Utilities.map_indices(
variable_map::MathOptInterface.Utilities.IndexMap, x::AbstractCustomData
) = x

"""
A callback to provide initial columns to the optimizer before starting the optimization.
"""
Expand Down
13 changes: 7 additions & 6 deletions src/customdata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ function MOI.set(
dest::MOIU.UniversalFallback, attribute::CustomVars, value
)
if !haskey(dest.modattr, attribute)
dest.modattr[attribute] = []
dest.modattr[attribute] = Type{<:AbstractCustomData}[]
end
for elem in value
@assert elem <: AbstractCustomData
push!(dest.modattr[attribute], elem)
end
return
Expand All @@ -58,21 +57,20 @@ function MOI.set(
dest::MOIU.UniversalFallback, attribute::CustomConstrs, value
)
if !haskey(dest.modattr, attribute)
dest.modattr[attribute] = []
dest.modattr[attribute] = Type{<:AbstractCustomData}[]
end
for elem in value
@assert elem <: AbstractCustomData
push!(dest.modattr[attribute], elem)
end
return
end

function MOI.get(dest::MOIU.UniversalFallback, attribute::CustomVars)
return get(dest.modattr, attribute, [])
return get(dest.modattr, attribute, Type{<:AbstractCustomData}[])
end

function MOI.get(dest::MOIU.UniversalFallback, attribute::CustomConstrs)
return get(dest.modattr, attribute, [])
return get(dest.modattr, attribute, Type{<:AbstractCustomData}[])
end

struct CustomVarValue <: MOI.AbstractVariableAttribute end
Expand Down Expand Up @@ -149,4 +147,7 @@ end

MathOptInterface.Utilities.map_indices(
variable_map::MathOptInterface.Utilities.IndexMap, x::AbstractCustomData
) = x
MathOptInterface.Utilities.map_indices(
variable_map::MathOptInterface.Utilities.IndexMap, x::Vector{AbstractCustomData}
) = x

0 comments on commit bb04c3d

Please sign in to comment.