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

Conversation

blegat
Copy link
Member

@blegat blegat commented Jun 14, 2024

We can take inspiration from

function _scale(::Type{T}, ::Type{S}, func) where {T,S}
set = MOI.Utilities.set_with_dimension(S, _length(func))
scale = MOI.Utilities.SetDotScalingVector{T}(set)
return MOI.Utilities.operate(*, T, LinearAlgebra.Diagonal(scale), func)
end
function _inverse_scale(::Type{T}, ::Type{S}, func) where {T,S}
set = MOI.Utilities.set_with_dimension(S, _length(func))
scale = MOI.Utilities.SetDotScalingVector{T}(set)
inv_scale = MOI.Utilities.lazy_map(T, inv, scale)
return MOI.Utilities.operate(*, T, LinearAlgebra.Diagonal(inv_scale), func)
end

Closes #2513

@odow
Copy link
Member

odow commented Jun 16, 2024

@odow
Copy link
Member

odow commented Jun 16, 2024

Still the same problem: https://github.com/jump-dev/MathOptInterface.jl/actions/runs/9531770131/job/26273074388

image

There's a suspicious 1 / sqrt(2) there, so perhaps we need 1 / scale^2 somewhere?

@odow
Copy link
Member

odow commented Jun 16, 2024

@odow
Copy link
Member

odow commented Jun 16, 2024

The COPT failure is unrelated: COPT-Public/COPT.jl#40

@odow
Copy link
Member

odow commented Jun 16, 2024

I don't fully understand the math logic, but the code does something like set_dot(scale * x, scale * y), which is more or less equivalent to sum(scale.^2 .* x .* y), so to reverse, we need to divide by scale.^2.

@blegat
Copy link
Member Author

blegat commented Jun 17, 2024

Yes, the trick is to keep the same term in the Lagrangian. 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 so dividing by the square makes sense

@blegat
Copy link
Member Author

blegat commented Jun 17, 2024

Maybe we should add a test in test/Bridges/Constraint/slack.jl

@odow
Copy link
Member

odow commented Jun 17, 2024

I've added a test that triggers the scale and tweaked the comments. I also needed to update the MOI.set for ::ConstraintDualStart because it didn't scale things either.

As a more general comment: our tests just check that get/set is a round-trip. We can't easily automatically test that the numeric values are correct.

@odow
Copy link
Member

odow commented Jun 18, 2024

MOI.set(model, attr, bridge.slack_in_set, value)
MOI.set(model, attr, bridge.equality, value)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, this was a bug, good catch

@blegat blegat merged commit 193aec6 into master Jun 18, 2024
69 of 72 checks passed
@blegat blegat deleted the bl/slack_dual branch June 18, 2024 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Revisit PR#2508
2 participants