Skip to content

Commit

Permalink
Add conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Dec 11, 2024
1 parent 14b0031 commit dfa44d9
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 160 deletions.
70 changes: 0 additions & 70 deletions src/Bridges/Constraint/bridges/LinearCombinationBridge.jl

This file was deleted.

82 changes: 0 additions & 82 deletions src/Bridges/Variable/bridges/DotProductsBridge.jl

This file was deleted.

77 changes: 69 additions & 8 deletions src/sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1824,12 +1824,18 @@ end

dimension(s::SetDotProducts) = length(s.vectors)

function dual_set(s::SetDotProducts)
return LinearCombinationInSet(s.set, s.vectors)
function MOI.Bridges.Constraint.conversion_cost(
::Type{SetDotProducts{S,A1,Vector{A1}}},
::Type{SetDotProducts{S,A2,Vector{A2}}},
) where {S,A1,A2}
return MOI.Bridges.Constraint.conversion_cost(A1, A2)
end

function dual_set_type(::Type{SetDotProducts{S,A,V}}) where {S,A,V}
return LinearCombinationInSet{S,A,V}
function convert(
::Type{SetDotProducts{S,A,Vector{A}}},
set::SetDotProducts,
)
return SetDotProducts(set.set, convert(A, set.vectors))
end

"""
Expand All @@ -1853,6 +1859,28 @@ end

dimension(s::LinearCombinationInSet) = length(s.vectors)

function MOI.Bridges.Constraint.conversion_cost(
::Type{LinearCombinationInSet{S,A1,Vector{A1}}},
::Type{LinearCombinationInSet{S,A2,Vector{A2}}},
) where {S,A1,A2}
return MOI.Bridges.Constraint.conversion_cost(A1, A2)
end

function convert(
::Type{LinearCombinationInSet{S,A,Vector{A}}},
set::LinearCombinationInSet,
)
return LinearCombinationInSet(set.set, convert(A, set.vectors))
end

function dual_set(s::SetDotProducts)
return LinearCombinationInSet(s.set, s.vectors)
end

function dual_set_type(::Type{SetDotProducts{S,A,V}}) where {S,A,V}
return LinearCombinationInSet{S,A,V}
end

function dual_set(s::LinearCombinationInSet)
return SetDotProducts(s.side_dimension, s.vectors)
end
Expand Down Expand Up @@ -1915,13 +1943,11 @@ function Base.getindex(m::Factorization, i::Int, j::Int)
end

"""
struct Factorization{
struct PositiveSemidefiniteFactorization{
T,
F<:Union{AbstractVector{T},AbstractMatrix{T}},
D<:Union{T,AbstractVector{T}},
} <: AbstractMatrix{T}
} <: AbstractFactorization{T,F}
factor::F
scaling::D
end
Matrix corresponding to `factor * Diagonal(diagonal) * factor'`.
Expand All @@ -1941,10 +1967,45 @@ function Base.getindex(m::PositiveSemidefiniteFactorization, i::Int, j::Int)
return sum(m.factor[i, k] * m.factor[j, k]' for k in axes(m.factor, 2))
end

function MOI.Bridges.Constraint.conversion_cost(
::Type{<:AbstractMatrix},
::Type{<:AbstractMatrix},
)
return Inf
end

function MOI.Bridges.Constraint.conversion_cost(
::Type{<:Factorization{T,F}},
::Type{PositiveSemidefiniteFactorization{T,F}},
) where {T,F}
return 1.0
end

function Base.convert(
::Type{Factorization{T,F,D}},
f::PositiveSemidefiniteFactorization{T,F},
) where {F<:AbstractVector}
return Factorization{T,F,D}(f.factor, one(T))
end

function Base.convert(
::Type{Factorization{T,F,D}},
f::PositiveSemidefiniteFactorization{T,F},
) where {F<:AbstractVector}
return Factorization{T,F,D}(f.factor, one(T))
end

struct TriangleVectorization{T,M<:AbstractMatrix{T}} <: AbstractVector{T}
matrix::M
end

function MOI.Bridges.Constraint.conversion_cost(
::Type{TriangleVectorization{T,M1}},
::Type{TriangleVectorization{T,M2}},
) where {T,M1,M2}
return MOI.Bridges.Constraint.conversion_cost(M1, M2)
end

function Base.size(v::TriangleVectorization)
n = size(v.matrix, 1)
return (Utilities.trimap(n, n),)
Expand Down

0 comments on commit dfa44d9

Please sign in to comment.