Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Jun 17, 2024
1 parent 397b779 commit 9f99f35
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/Bridges/Constraint/bridges/slack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,22 @@ function MOI.get(
) where {T}
# The dual constraint on slack (since it is free) is
# `-dual_slack_in_set + dual_equality = 0` so the two duals are
# equal and we can return either one of them.
# We decide to use the dual of the equality constraints because
# the `slack_in_set` constraint might be bridge by a variable bridge that
# does not # support `ConstraintDual`. This is the case if the adjoint of
# the linear map on which the bridge is based is not invertible, as for
# instance with `Variable.ZerosBridge` or
# `SumOfSquares.Bridges.Variable.KernelBridge`.
# equal (modulo a rescaling for things like symmetric matrices) and we can
# return either one of them.
#
# We decide to use the dual of the equality constraints because the
# `slack_in_set` constraint might be bridged by a variable bridge that does
# not support `ConstraintDual`. This is the case if the adjoint of the
# linear map on which the bridge is based is not invertible, for example,
# `Variable.ZerosBridge` or `SumOfSquares.Bridges.Variable.KernelBridge`.
dual = MOI.get(model, a, bridge.equality)
if dual === nothing
return nothing
elseif dual isa AbstractVector

Check warning on line 142 in src/Bridges/Constraint/bridges/slack.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/bridges/slack.jl#L139-L142

Added lines #L139 - L142 were not covered by tests
# The equality constraints gives the term <dual, primal> with the
# standard inner product but <dual, primal>_PSD is like scaling each
# entry of dual and primal by the entry of SetDotScalingVector. To undo,
# we need to divide by the square.
scale = MOI.Utilities.SetDotScalingVector{T}(bridge.set)
return dual ./ scale .^ 2

Check warning on line 148 in src/Bridges/Constraint/bridges/slack.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/bridges/slack.jl#L147-L148

Added lines #L147 - L148 were not covered by tests
end
Expand All @@ -148,15 +153,17 @@ end
function MOI.set(
model::MOI.ModelLike,
attr::MOI.ConstraintDualStart,
bridge::_AbstractSlackBridge,
bridge::_AbstractSlackBridge{T},
value,
)
# As the slack appears `+slack` in `slack_in_set` and `-slack` in equality,
# giving `value` to both will cancel it out in the Lagrangian.
# Giving `value` to `bridge.equality` will put the function in the
# Lagrangian as expected.
) where {T}
# See comments in MOI.get for why we need to rescale, etc.
MOI.set(model, attr, bridge.slack_in_set, value)
MOI.set(model, attr, bridge.equality, value)
if value isa AbstractVector
scale = MOI.Utilities.SetDotScalingVector{T}(bridge.set)
MOI.set(model, attr, bridge.equality, value .* scale .^ 2)

Check warning on line 163 in src/Bridges/Constraint/bridges/slack.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/bridges/slack.jl#L161-L163

Added lines #L161 - L163 were not covered by tests
else
MOI.set(model, attr, bridge.equality, value)

Check warning on line 165 in src/Bridges/Constraint/bridges/slack.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/bridges/slack.jl#L165

Added line #L165 was not covered by tests
end
return
end

Expand Down
12 changes: 12 additions & 0 deletions test/Bridges/Constraint/slack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,18 @@ function test_runtests()
[y, z] in SecondOrderCone(2)
""",
)
MOI.Bridges.runtests(
MOI.Bridges.Constraint.VectorSlackBridge,
"""
variables: x11, x12, x22
[1.0 * x11, x12, 2.0 * x22] in PositiveSemidefiniteConeTriangle(2)
""",
"""
variables: x11, x12, x22, y11, y12, y22
[1.0 * x11 + -1.0 * y11, x12 + -1.0 * y12, 2.0 * x22 + -1.0 * y22] in Zeros(3)
[y11, y12, y22] in PositiveSemidefiniteConeTriangle(2)
""",
)
return
end

Expand Down

0 comments on commit 9f99f35

Please sign in to comment.