|
| 1 | +struct DotProductsBridge{T,S,V} <: SetMapBridge{T,S,MOI.SetWithDotProducts{S,V}} |
| 2 | + variables::Vector{MOI.VariableIndex} |
| 3 | + constraint::MOI.ConstraintIndex{MOI.VectorOfVariables, S} |
| 4 | + set::MOI.SetWithDotProducts{S,V} |
| 5 | +end |
| 6 | + |
| 7 | +function supports_constrained_variable( |
| 8 | + ::Type{<:DotProductsBridge}, |
| 9 | + ::Type{<:MOI.SetWithDotProducts}, |
| 10 | +) |
| 11 | + return true |
| 12 | +end |
| 13 | + |
| 14 | +function concrete_bridge_type( |
| 15 | + ::Type{<:DotProductsBridge{T}}, |
| 16 | + ::Type{MOI.SetWithDotProducts{S,V}}, |
| 17 | +) where {T,S,V} |
| 18 | + return DotProductsBridge{T,S,V} |
| 19 | +end |
| 20 | + |
| 21 | +function bridge_constrained_variable( |
| 22 | + BT::Type{DotProductsBridge{T,S,V}}, |
| 23 | + model::MOI.ModelLike, |
| 24 | + set::MOI.SetWithDotProducts{S,V}, |
| 25 | +) where {T,S,V} |
| 26 | + variables, constraint = |
| 27 | + _add_constrained_var(model, MOI.Bridges.inverse_map_set(BT, set)) |
| 28 | + return BT(variables, constraint, set) |
| 29 | +end |
| 30 | + |
| 31 | +function MOI.Bridges.map_set( |
| 32 | + bridge::DotProductsBridge{T,S}, |
| 33 | + set::S, |
| 34 | +) where {T,S} |
| 35 | + return MOI.SetWithDotProducts(set, bridge.vectors) |
| 36 | +end |
| 37 | + |
| 38 | +function MOI.Bridges.inverse_map_set( |
| 39 | + ::Type{<:DotProductsBridge}, |
| 40 | + set::MOI.SetWithDotProducts, |
| 41 | +) |
| 42 | + return set.set |
| 43 | +end |
| 44 | + |
| 45 | +function MOI.Bridges.map_function( |
| 46 | + bridge::DotProductsBridge{T}, |
| 47 | + func, |
| 48 | + i::MOI.Bridges.IndexInVector, |
| 49 | +) where {T} |
| 50 | + scalars = MOI.Utilities.eachscalar(func) |
| 51 | + if i.value in eachindex(bridge.set.vectors) |
| 52 | + return MOI.Utilities.set_dot(bridge.set.vectors[i.value], scalars, bridge.set.set) |
| 53 | + else |
| 54 | + return convert(MOI.ScalarAffineFunction{T}, scalars[i.value - length(bridge.vectors)]) |
| 55 | + end |
| 56 | +end |
| 57 | + |
| 58 | +function MOI.Bridges.inverse_map_function(bridge::DotProductsBridge{T}, func) where {T} |
| 59 | + m = length(bridge.set.vectors) |
| 60 | + return MOI.Utilities.operate(vcat, T, MOI.Utilities.eachscalar(func)[(m+1):end]) |
| 61 | +end |
| 62 | + |
0 commit comments