diff --git a/src/Utilities/CleverDicts.jl b/src/Utilities/CleverDicts.jl index 13cc59bd3c..407ea35940 100644 --- a/src/Utilities/CleverDicts.jl +++ b/src/Utilities/CleverDicts.jl @@ -86,7 +86,7 @@ mutable struct CleverDict{K,V,F<:Function,I<:Function} <: AbstractDict{K,V} end end function CleverDict{K,V}(n::Integer = 0) where {K,V} - return CleverDict{K,V}(key_to_index, index_to_key, n) + return CleverDict{K,V}(key_to_index, Base.Fix1(index_to_key, K), n) end """ @@ -116,7 +116,7 @@ function add_item(c::CleverDict{K,V}, val::V)::K where {K,V} error("Keys were added out of order. `add_item` requires that keys are always added in order.") end # adding a key in order - key = c.inverse_hash(K, Int64(c.last_index + 1))::K + key = c.inverse_hash(Int64(c.last_index + 1))::K c[key] = val return key end @@ -144,7 +144,7 @@ end function Base.keys(c::CleverDict{K}) where {K} return if _is_dense(c) - [c.inverse_hash(K, index) for index in c.set] + [c.inverse_hash(index)::K for index in c.set] else collect(keys(c.dict)) end @@ -284,7 +284,7 @@ function Base.iterate( return nothing else el, i = itr - new_el = c.inverse_hash(K, Int64(el))::K => c.vector[el]::V + new_el = c.inverse_hash(Int64(el))::K => c.vector[el]::V @static if VERSION >= v"1.4.0" return new_el, State(i[2], i[1]) else @@ -318,7 +318,7 @@ function Base.iterate( return nothing else el, i = itr - new_el = c.inverse_hash(K, Int64(el))::K => c.vector[el]::V + new_el = c.inverse_hash(Int64(el))::K => c.vector[el]::V @static if VERSION >= v"1.4.0" return new_el, State(i[2], i[1]) else diff --git a/src/Utilities/model.jl b/src/Utilities/model.jl index 684bd4bd91..c21169900d 100644 --- a/src/Utilities/model.jl +++ b/src/Utilities/model.jl @@ -530,34 +530,34 @@ function MOI.modify( end function MOI.set( - model::AbstractModel, + ::AbstractModel, ::MOI.ConstraintFunction, - ci::CI{MOI.SingleVariable}, - change::MOI.AbstractFunction, + ::CI{MOI.SingleVariable}, + ::MOI.SingleVariable, ) return throw(MOI.SettingSingleVariableFunctionNotAllowed()) end function MOI.set( model::AbstractModel, - attr::MOI.ConstraintFunction, - ci::MOI.ConstraintIndex{F}, - func::F, -) where {F,S} - return MOI.set(constraints(model, ci), attr, ci, func) + attr::Union{MOI.ConstraintFunction, MOI.ConstraintSet}, + ci::MOI.ConstraintIndex, + func_or_set, +) + return MOI.set(constraints(model, ci), attr, ci, func_or_set) end function MOI.set( - model::AbstractModel, + model::AbstractModel{T}, ::MOI.ConstraintSet, ci::CI{MOI.SingleVariable}, - change::MOI.AbstractSet, -) + set::SUPPORTED_VARIABLE_SCALAR_SETS{T}, +) where {T} MOI.throw_if_not_valid(model, ci) - flag = single_variable_flag(typeof(change)) + flag = single_variable_flag(typeof(set)) if !iszero(flag & LOWER_BOUND_MASK) - model.lower_bound[ci.value] = extract_lower_bound(change) + model.lower_bound[ci.value] = extract_lower_bound(set) end if !iszero(flag & UPPER_BOUND_MASK) - model.upper_bound[ci.value] = extract_upper_bound(change) + model.upper_bound[ci.value] = extract_upper_bound(set) end end function MOI.set( diff --git a/src/Utilities/vector_of_constraints.jl b/src/Utilities/vector_of_constraints.jl index 1bae7303e2..c11359fbcd 100644 --- a/src/Utilities/vector_of_constraints.jl +++ b/src/Utilities/vector_of_constraints.jl @@ -16,7 +16,9 @@ # updated. struct VectorOfConstraints{F<:MOI.AbstractFunction,S<:MOI.AbstractSet} <: MOI.ModelLike - constraints::CleverDicts.CleverDict{MOI.ConstraintIndex{F,S},Tuple{F,S},typeof(CleverDicts.key_to_index),typeof(CleverDicts.index_to_key)} + # FIXME It is not ideal that we have `DataType` here, it might induce type instabilities. + # We should change `CleverDicts` so that we can just use `typeof(CleverDicts.index_to_key)` here. + constraints::CleverDicts.CleverDict{MOI.ConstraintIndex{F,S},Tuple{F,S},typeof(CleverDicts.key_to_index),Base.Fix1{typeof(CleverDicts.index_to_key),DataType}} function VectorOfConstraints{F,S}() where {F,S} return new{F,S}(CleverDicts.CleverDict{MOI.ConstraintIndex{F,S},Tuple{F,S}}()) end