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

[Bridges] use dual of equality in slack bridge (take 2) #2515

Merged
merged 10 commits into from
Jun 18, 2024
Merged
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/Bridges/Constraint/bridges/slack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,25 @@
function MOI.get(
model::MOI.ModelLike,
a::Union{MOI.ConstraintDual,MOI.ConstraintDualStart},
bridge::_AbstractSlackBridge,
)
bridge::_AbstractSlackBridge{T},
) where {T}
# The dual constraint on slack (since it is free) is
# -dual_slack_in_set + dual_equality = 0 so the two duals are
# `-dual_slack_in_set + dual_equality = 0` so the two duals are
# equal and we can return either one of them.
return MOI.get(model, a, bridge.slack_in_set)
# 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`.
dual = MOI.get(model, a, bridge.equality)
if dual === nothing
return nothing
elseif dual isa AbstractVector
scale = MOI.Utilities.SetDotScalingVector{T}(bridge.set)
return dual ./ scale.^2

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

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/bridges/slack.jl#L138-L143

Added lines #L138 - L143 were not covered by tests
odow marked this conversation as resolved.
Show resolved Hide resolved
end
return dual

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L145 was not covered by tests
end

function MOI.set(
Expand Down Expand Up @@ -209,6 +222,7 @@
struct ScalarSlackBridge{T,F,S} <:
_AbstractSlackBridge{T,MOI.VariableIndex,MOI.EqualTo{T},F,S}
slack::MOI.VariableIndex
set::S
slack_in_set::MOI.ConstraintIndex{MOI.VariableIndex,S}
equality::MOI.ConstraintIndex{F,MOI.EqualTo{T}}
end
Expand All @@ -226,7 +240,7 @@
slack, slack_in_set = MOI.add_constrained_variable(model, s)
new_f = MOI.Utilities.operate(-, T, f, slack)
equality = MOI.add_constraint(model, new_f, MOI.EqualTo(zero(T)))
return ScalarSlackBridge{T,F,S}(slack, slack_in_set, equality)
return ScalarSlackBridge{T,F,S}(slack, s, slack_in_set, equality)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L243 was not covered by tests
end

# Start by allowing all scalar constraints:
Expand Down Expand Up @@ -341,6 +355,7 @@
struct VectorSlackBridge{T,F,S} <:
_AbstractSlackBridge{T,MOI.VectorOfVariables,MOI.Zeros,F,S}
slack::Vector{MOI.VariableIndex}
set::S
slack_in_set::MOI.ConstraintIndex{MOI.VectorOfVariables,S}
equality::MOI.ConstraintIndex{F,MOI.Zeros}
end
Expand All @@ -358,7 +373,7 @@
slack, slack_in_set = MOI.add_constrained_variables(model, s)
new_f = MOI.Utilities.operate(-, T, f, MOI.VectorOfVariables(slack))
equality = MOI.add_constraint(model, new_f, MOI.Zeros(d))
return VectorSlackBridge{T,F,S}(slack, slack_in_set, equality)
return VectorSlackBridge{T,F,S}(slack, s, slack_in_set, equality)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L376 was not covered by tests
end

function MOI.supports_constraint(
Expand Down
Loading