diff --git a/src/Bridges/Constraint/map.jl b/src/Bridges/Constraint/map.jl index 95a6d63e16..38cfbb11d7 100644 --- a/src/Bridges/Constraint/map.jl +++ b/src/Bridges/Constraint/map.jl @@ -86,7 +86,7 @@ function Base.getindex( end function Base.delete!(map::Map, ci::MOI.ConstraintIndex) - _unregister_for_final_touch(map, map.bridges[_index(ci)]) + _unregister_for_final_touch(map, map.bridges[_index(ci)]::AbstractBridge) map.bridges[_index(ci)] = nothing return map end diff --git a/src/Bridges/Variable/map.jl b/src/Bridges/Variable/map.jl index 9563d0c6f0..7b9e98adb0 100644 --- a/src/Bridges/Variable/map.jl +++ b/src/Bridges/Variable/map.jl @@ -208,7 +208,7 @@ function number_with_set(map::Map, S::Type{<:MOI.AbstractSet}) end function constraint(map::Map, vi::MOI.VariableIndex) - S = constrained_set(map, vi) + S = constrained_set(map, vi)::Type{<:MOI.AbstractSet} F = MOI.Utilities.variable_function_type(S) return MOI.ConstraintIndex{F,S}(-bridge_index(map, vi)) end @@ -235,12 +235,14 @@ Return a list of all the different types `(F, S)` of `F`-in-`S` constraints in function list_of_constraint_types(map::Map) list = Set{Tuple{Type,Type}}() for i in eachindex(map.bridges) - if map.bridges[i] !== nothing - S = map.sets[i] - if S != MOI.Reals - push!(list, (MOI.Utilities.variable_function_type(S), S)) - end + if map.bridges[i] === nothing + continue + end + S = map.sets[i] + if S === nothing || S == MOI.Reals + continue end + push!(list, (MOI.Utilities.variable_function_type(S), S)) end return list end diff --git a/src/Bridges/bridge_optimizer.jl b/src/Bridges/bridge_optimizer.jl index 22aba001c9..c0af0b3440 100644 --- a/src/Bridges/bridge_optimizer.jl +++ b/src/Bridges/bridge_optimizer.jl @@ -1225,7 +1225,7 @@ end function MOI.set( b::AbstractBridgeOptimizer, attr::MOI.AbstractVariableAttribute, - index::MOI.Index, + index::MOI.VariableIndex, value, ) value = bridged_function(b, value) @@ -1240,7 +1240,7 @@ end function MOI.set( b::AbstractBridgeOptimizer, attr::MOI.AbstractVariableAttribute, - indices::Vector{<:MOI.Index}, + indices::Vector{MOI.VariableIndex}, values::Vector, ) if any(index -> is_bridged(b, index), indices) @@ -2004,7 +2004,10 @@ function bridged_variable_function( vi::MOI.VariableIndex, ) if is_bridged(b, vi) - func = bridged_function(bridge(b, vi), _index(b, vi)...) + func = bridged_function( + bridge(b, vi)::Variable.AbstractBridge, + _index(b, vi)..., + ) # If two variable bridges are chained, `func` may still contain # bridged variables. return bridged_function(b, func) diff --git a/src/Bridges/lazy_bridge_optimizer.jl b/src/Bridges/lazy_bridge_optimizer.jl index daac29de41..fb5c9703f8 100644 --- a/src/Bridges/lazy_bridge_optimizer.jl +++ b/src/Bridges/lazy_bridge_optimizer.jl @@ -128,9 +128,12 @@ end Return the list of `VariableNode` that would be added if `BT` is used in `b`. """ -function _variable_nodes(b::LazyBridgeOptimizer, ::Type{BT}) where {BT} +function _variable_nodes( + b::LazyBridgeOptimizer, + ::Type{BT}, +) where {BT<:AbstractBridge} return VariableNode[ - node(b, S) for (S,) in added_constrained_variable_types(BT) + node(b, S)::VariableNode for (S,) in added_constrained_variable_types(BT) ] end @@ -139,7 +142,10 @@ end Return the list of `ConstraintNode` that would be added if `BT` is used in `b`. """ -function _constraint_nodes(b::LazyBridgeOptimizer, ::Type{BT}) where {BT} +function _constraint_nodes( + b::LazyBridgeOptimizer, + ::Type{BT}, +) where {BT<:AbstractBridge} return ConstraintNode[ node(b, F, S) for (F, S) in added_constraint_types(BT) ] @@ -168,10 +174,10 @@ function _edge( ) return ObjectiveEdge( index, - _variable_nodes(b, BT), - _constraint_nodes(b, BT), - node(b, set_objective_function_type(BT)), - bridging_cost(BT), + _variable_nodes(b, BT)::Vector{VariableNode}, + _constraint_nodes(b, BT)::Vector{ConstraintNode}, + node(b, set_objective_function_type(BT))::ObjectiveNode, + bridging_cost(BT)::Float64, ) end @@ -321,7 +327,7 @@ function node(b::LazyBridgeOptimizer, F::Type{<:MOI.AbstractFunction}) push!(b.objective_types, (F,)) for (i, BT) in enumerate(b.objective_bridge_types) if Objective.supports_objective_function(BT, F) - bridge_type = Objective.concrete_bridge_type(BT, F) + bridge_type = Objective.concrete_bridge_type(BT, F)::Type{<:Objective.AbstractBridge} edge = _edge(b, i, bridge_type)::ObjectiveEdge add_edge(b.graph, objective_node, edge) end diff --git a/src/Utilities/functions.jl b/src/Utilities/functions.jl index 3c436b43a7..53fefc8da8 100644 --- a/src/Utilities/functions.jl +++ b/src/Utilities/functions.jl @@ -150,7 +150,7 @@ function eval_variables(value_fn::Function, f::MOI.ScalarQuadraticFunction) end function eval_variables(value_fn::Function, f::MOI.VectorOfVariables) - return value_fn.(f.variables) + return map(value_fn, f.variables) end function eval_variables(value_fn::Function, f::MOI.VectorAffineFunction) diff --git a/src/Utilities/matrix_of_constraints.jl b/src/Utilities/matrix_of_constraints.jl index 10bdac499f..843f2262cc 100644 --- a/src/Utilities/matrix_of_constraints.jl +++ b/src/Utilities/matrix_of_constraints.jl @@ -271,7 +271,7 @@ function rows end MOI.is_empty(v::MatrixOfConstraints) = MOI.is_empty(v.sets) -function MOI.empty!(v::MatrixOfConstraints{T}) where {T} +function MOI.empty!(v::MatrixOfConstraints{T,AT,BT,ST}) where {T,AT,BT,ST} MOI.empty!(v.coefficients) empty!(v.constants) MOI.empty!(v.sets) diff --git a/src/Utilities/objective_container.jl b/src/Utilities/objective_container.jl index d8fd4db793..59f046d8a0 100644 --- a/src/Utilities/objective_container.jl +++ b/src/Utilities/objective_container.jl @@ -123,12 +123,12 @@ function MOI.get( T, F<:Union{ MOI.VariableIndex, - MOI.ScalarAffineFunction{T}, - MOI.ScalarQuadraticFunction{T}, + MOI.ScalarAffineFunction, + MOI.ScalarQuadraticFunction, MOI.ScalarNonlinearFunction, MOI.VectorOfVariables, - MOI.VectorAffineFunction{T}, - MOI.VectorQuadraticFunction{T}, + MOI.VectorAffineFunction, + MOI.VectorQuadraticFunction, MOI.VectorNonlinearFunction, }, } diff --git a/src/Utilities/struct_of_constraints.jl b/src/Utilities/struct_of_constraints.jl index 41d6f83cda..b383ceeb5c 100644 --- a/src/Utilities/struct_of_constraints.jl +++ b/src/Utilities/struct_of_constraints.jl @@ -283,7 +283,7 @@ function struct_of_constraint_code(struct_name, types, field_types = nothing) typed_struct = :($(struct_name){$T}) type_parametrized = field_types === nothing if type_parametrized - field_types = [Symbol("C$i") for i in eachindex(types)] + field_types = Symbol[Symbol("C$i") for i in eachindex(types)] append!(typed_struct.args, field_types) end code = quote diff --git a/src/Utilities/universalfallback.jl b/src/Utilities/universalfallback.jl index db1e624867..0c90656c41 100644 --- a/src/Utilities/universalfallback.jl +++ b/src/Utilities/universalfallback.jl @@ -579,7 +579,7 @@ function MOI.modify( if uf.objective === nothing MOI.modify(uf.model, obj, change) else - uf.objective = modify_function(uf.objective, change) + uf.objective = modify_function(something(uf.objective), change) end return end