Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set for low-rank constrained SDP #2198

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
15 changes: 8 additions & 7 deletions src/Bridges/Variable/set_map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
bridge::SetMapBridge,
)
set = MOI.get(model, attr, bridge.constraint)
return MOI.Bridges.map_set(typeof(bridge), set)
return MOI.Bridges.map_set(bridge, set)

Check warning on line 132 in src/Bridges/Variable/set_map.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Variable/set_map.jl#L132

Added line #L132 was not covered by tests
end

function MOI.set(
Expand All @@ -149,7 +149,7 @@
bridge::SetMapBridge,
)
value = MOI.get(model, attr, bridge.constraint)
return MOI.Bridges.map_function(typeof(bridge), value)
return MOI.Bridges.map_function(bridge, value)

Check warning on line 152 in src/Bridges/Variable/set_map.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Variable/set_map.jl#L152

Added line #L152 was not covered by tests
end

function MOI.get(
Expand All @@ -171,7 +171,7 @@
if any(isnothing, value)
return nothing
end
return MOI.Bridges.map_function(typeof(bridge), value, i)
return MOI.Bridges.map_function(bridge, value, i)

Check warning on line 174 in src/Bridges/Variable/set_map.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Variable/set_map.jl#L174

Added line #L174 was not covered by tests
end

function MOI.supports(
Expand Down Expand Up @@ -203,7 +203,7 @@
i::MOI.Bridges.IndexInVector,
) where {T}
func = MOI.Bridges.map_function(
typeof(bridge),
bridge,
MOI.VectorOfVariables(bridge.variables),
i,
)
Expand All @@ -212,7 +212,7 @@

function unbridged_map(bridge::SetMapBridge{T}, vi::MOI.VariableIndex) where {T}
F = MOI.ScalarAffineFunction{T}
mapped = MOI.Bridges.inverse_map_function(typeof(bridge), vi)
mapped = MOI.Bridges.inverse_map_function(bridge, vi)

Check warning on line 215 in src/Bridges/Variable/set_map.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Variable/set_map.jl#L215

Added line #L215 was not covered by tests
return Pair{MOI.VariableIndex,F}[bridge.variable=>mapped]
end

Expand All @@ -222,9 +222,10 @@
) where {T}
F = MOI.ScalarAffineFunction{T}
func = MOI.VectorOfVariables(vis)
funcs = MOI.Bridges.inverse_map_function(typeof(bridge), func)
funcs = MOI.Bridges.inverse_map_function(bridge, func)

Check warning on line 225 in src/Bridges/Variable/set_map.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Variable/set_map.jl#L225

Added line #L225 was not covered by tests
scalars = MOI.Utilities.eachscalar(funcs)
# FIXME not correct for SetDotProducts, it won't recover the dot product variables
return Pair{MOI.VariableIndex,F}[
bridge.variables[i] => scalars[i] for i in eachindex(vis)
bridge.variables[i] => scalars[i] for i in eachindex(bridge.variables)
]
end
4 changes: 4 additions & 0 deletions src/Bridges/set_map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
return MOI.Utilities.eachscalar(map_function(BT, func))[i.value]
end

function map_function(bridge::AbstractBridge, func, i::IndexInVector)
return map_function(typeof(bridge), func, i)

Check warning on line 84 in src/Bridges/set_map.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/set_map.jl#L83-L84

Added lines #L83 - L84 were not covered by tests
end

"""
inverse_map_function(bridge::MOI.Bridges.AbstractBridge, func)
inverse_map_function(::Type{BT}, func) where {BT}
Expand Down
10 changes: 8 additions & 2 deletions src/Utilities/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -638,18 +638,24 @@ end
A type that allows iterating over the scalar-functions that comprise an
`AbstractVectorFunction`.
"""
struct ScalarFunctionIterator{F<:MOI.AbstractVectorFunction,C}
struct ScalarFunctionIterator{F<:MOI.AbstractVectorFunction,C,S} <:
AbstractVector{S}
f::F
# Cache that can be used to store a precomputed datastructure that allows
# an efficient implementation of `getindex`.
cache::C
function ScalarFunctionIterator(f::MOI.AbstractVectorFunction, cache)
return new{typeof(f),typeof(cache),scalar_type(typeof(f))}(f, cache)
end
end

function ScalarFunctionIterator(func::MOI.AbstractVectorFunction)
return ScalarFunctionIterator(func, scalar_iterator_cache(func))
end

scalar_iterator_cache(func::MOI.AbstractVectorFunction) = nothing
Base.size(s::ScalarFunctionIterator) = (MOI.output_dimension(s.f),)

scalar_iterator_cache(::MOI.AbstractVectorFunction) = nothing

function output_index_iterator(terms::AbstractVector, output_dimension)
start = zeros(Int, output_dimension)
Expand Down
Loading