Skip to content

Commit

Permalink
Fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Dec 5, 2024
1 parent e954eec commit 7919b2f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 37 deletions.
13 changes: 5 additions & 8 deletions src/Bridges/Constraint/bridges/linear_combination.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ end
function _map_function(set::MOI.LinearCombinationInSet, func)
scalars = MOI.Utilities.eachscalar(func)
return MOI.Utilities.vectorize([
sum(scalars[j] * set.vectors[j][i] for j in eachindex(scalars))
for i in 1:MOI.dimension(set.set)
sum(scalars[j] * set.vectors[j][i] for j in eachindex(scalars)) for
i in 1:MOI.dimension(set.set)
])
end

Expand Down Expand Up @@ -61,13 +61,10 @@ function MOI.Bridges.inverse_map_set(
return bridge.set
end

function MOI.Bridges.adjoint_map_function(
bridge::LinearCombinationBridge,
func,
)
function MOI.Bridges.adjoint_map_function(bridge::LinearCombinationBridge, func)
scalars = MOI.Utilities.eachscalar(func)
return MOI.Utilities.vectorize([
MOI.Utilities.set_dot(vector, scalars, bridge.set.set)
for vector in bridge.set.vectors
MOI.Utilities.set_dot(vector, scalars, bridge.set.set) for
vector in bridge.set.vectors
])
end
16 changes: 4 additions & 12 deletions src/Bridges/Variable/bridges/set_dot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

struct DotProductsBridge{T,S,A,V} <:
SetMapBridge{T,S,MOI.SetDotProducts{S,A,V}}
struct DotProductsBridge{T,S,A,V} <: SetMapBridge{T,S,MOI.SetDotProducts{S,A,V}}
variables::Vector{MOI.VariableIndex}
constraint::MOI.ConstraintIndex{MOI.VectorOfVariables,S}
set::MOI.SetDotProducts{S,A,V}
Expand Down Expand Up @@ -59,18 +58,11 @@ function MOI.Bridges.map_function(
)
end

function MOI.Bridges.map_function(
bridge::DotProductsBridge{T},
func,
) where {T}
function MOI.Bridges.map_function(bridge::DotProductsBridge{T}, func) where {T}
scalars = MOI.Utilities.eachscalar(func)
return MOI.Utilities.vectorize([
MOI.Utilities.set_dot(
vector,
scalars,
bridge.set.set,
)
for vector in bridge.set.vectors
MOI.Utilities.set_dot(vector, scalars, bridge.set.set) for
vector in bridge.set.vectors
])
end

Expand Down
54 changes: 37 additions & 17 deletions src/Test/test_conic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5801,7 +5801,11 @@ function test_conic_PositiveSemidefinite_RankOne_polynomial(
MOI.PositiveSemidefiniteFactorization(T[1, 1]),
]),
)
@requires MOI.supports_constraint(model, MOI.VectorAffineFunction{T}, typeof(set))
@requires MOI.supports_constraint(
model,
MOI.VectorAffineFunction{T},
typeof(set),
)
@requires MOI.supports_incremental_interface(model)
@requires MOI.supports(model, MOI.ObjectiveSense())
@requires MOI.supports(model, MOI.ObjectiveFunction{MOI.VariableIndex}())
Expand Down Expand Up @@ -5839,17 +5843,23 @@ function setup_test(
model::MOIU.MockOptimizer,
::Config{T},
) where {T<:Real}
A = MOI.TriangleVectorization{T,MOI.PositiveSemidefiniteFactorization{T,Vector{T}}}
A = MOI.TriangleVectorization{
T,
MOI.PositiveSemidefiniteFactorization{T,Vector{T}},
}
MOIU.set_mock_optimize!(
model,
(mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!(
mock,
T[-1],
(MOI.VectorAffineFunction{T}, MOI.SetDotProducts{
MOI.PositiveSemidefiniteConeTriangle,
A,
Vector{A},
}) => [T[0, 1]],
(
MOI.VectorAffineFunction{T},
MOI.SetDotProducts{
MOI.PositiveSemidefiniteConeTriangle,
A,
Vector{A},
},
) => [T[0, 1]],
),
)
return
Expand Down Expand Up @@ -5877,14 +5887,18 @@ function test_conic_PositiveSemidefinite_RankOne_moment(
@requires MOI.supports_add_constrained_variables(model, typeof(set))
@requires MOI.supports_incremental_interface(model)
@requires MOI.supports(model, MOI.ObjectiveSense())
@requires MOI.supports(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}())
y, cy = MOI.add_constrained_variables(
@requires MOI.supports(
model,
set,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
)
y, cy = MOI.add_constrained_variables(model, set)
c = MOI.add_constraint(model, T(1) * y[1] + T(1) * y[2], MOI.EqualTo(T(1)))
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
MOI.set(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(), T(3) * y[1] - T(1) * y[2])
MOI.set(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
T(3) * y[1] - T(1) * y[2],
)
if _supports(config, MOI.optimize!)
@test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMIZE_NOT_CALLED
MOI.optimize!(model)
Expand Down Expand Up @@ -5912,18 +5926,24 @@ function setup_test(
model::MOIU.MockOptimizer,
::Config{T},
) where {T<:Real}
A = MOI.TriangleVectorization{T,MOI.PositiveSemidefiniteFactorization{T,Vector{T}}}
A = MOI.TriangleVectorization{
T,
MOI.PositiveSemidefiniteFactorization{T,Vector{T}},
}
MOIU.set_mock_optimize!(
model,
(mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!(
mock,
T[0, 1],
(MOI.ScalarAffineFunction{T}, MOI.EqualTo{T}) => [T(-1)],
(MOI.VectorOfVariables, MOI.LinearCombinationInSet{
MOI.PositiveSemidefiniteConeTriangle,
A,
Vector{A},
}) => [T[4, 0]],
(
MOI.VectorOfVariables,
MOI.LinearCombinationInSet{
MOI.PositiveSemidefiniteConeTriangle,
A,
Vector{A},
},
) => [T[4, 0]],
),
)
return
Expand Down

0 comments on commit 7919b2f

Please sign in to comment.