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

Add Bridges.Constraint.InequalityToComplementsBridge #2582

Merged
merged 6 commits into from
Nov 14, 2024

Conversation

odow
Copy link
Member

@odow odow commented Nov 14, 2024

Closes #2581

Basic

  • Create a new file in src/Bridges/XXX/bridges
  • Define the bridge, following existing examples. The name of the bridge
    struct must end in Bridge
  • Check if your bridge can be a subtype of MOI.Bridges.Constraint.SetMapBridge
  • Define a new const that is a SingleBridgeOptimizer wrapping the
    new bridge. The name of the const must be the name of the bridge, less
    the Bridge suffix
  • include the file in src/Bridges/XXX/bridges/XXX.jl
  • If the bridge should be enabled by default, add the bridge to
    add_all_bridges at the bottom of src/Bridges/XXX/XXX.jl

Tests

  • Create a new file in the appropriate subdirectory of tests/Bridges/XXX
  • Use MOI.Bridges.runtests to test various inputs and outputs of the
    bridge
  • If, after opening the pull request to add the bridge, some lines are not
    covered by the tests, add additional bridge-specific tests to cover the
    untested lines.

Documentation

  • Add a docstring which uses the same template as existing bridges.

Final touch

If the bridge depends on run-time values of other variables and constraints in
the model:

  • Implement MOI.Utilities.needs_final_touch(::Bridge)
  • Implement MOI.Utilities.final_touch(::Bridge, ::MOI.ModelLike)
  • Ensure that final_touch can be called multiple times in a row

@odow
Copy link
Member Author

odow commented Nov 14, 2024

@mitchphillipson with this PR you will be able to do:

julia> using JuMP, PATHSolver

julia> model = Model(PATHSolver.Optimizer);

julia> @variable(model, x >= 0, start = 1.0);

julia> @constraint(model, 2 * x == 1.0)
2 x = 1

julia> optimize!(model)
Path 5.1.99 (Mon Jul 24 14:47:28 2023)
Written by Todd Munson, Steven Dirkse, Youngdae Kim, and Michael Ferris

MCPR: One:    0 Two:    2 Thr:    0 Qua:    0 WBd:    0 Fix:    0 IFx:    0

Major Iterations. . . . 0
Minor Iterations. . . . 0
Restarts. . . . . . . . 0
Crash Iterations. . . . 0
Gradient Steps. . . . . 0
Function Evaluations. . 0
Gradient Evaluations. . 0
Basis Time. . . . . . . 0.000000
Total Time. . . . . . . 0.000167
Residual. . . . . . . . 0.000000e+00
Postsolved residual: 0.0000e+00

julia> value(x)
0.5

@mitchphillipson
Copy link

@mitchphillipson with this PR you will be able to do:

julia> using JuMP, PATHSolver

julia> model = Model(PATHSolver.Optimizer);

julia> @variable(model, x >= 0, start = 1.0);

julia> @constraint(model, 2 * x == 1.0)
2 x = 1

julia> optimize!(model)
Path 5.1.99 (Mon Jul 24 14:47:28 2023)
Written by Todd Munson, Steven Dirkse, Youngdae Kim, and Michael Ferris

MCPR: One:    0 Two:    2 Thr:    0 Qua:    0 WBd:    0 Fix:    0 IFx:    0

Major Iterations. . . . 0
Minor Iterations. . . . 0
Restarts. . . . . . . . 0
Crash Iterations. . . . 0
Gradient Steps. . . . . 0
Function Evaluations. . 0
Gradient Evaluations. . 0
Basis Time. . . . . . . 0.000000
Total Time. . . . . . . 0.000167
Residual. . . . . . . . 0.000000e+00
Postsolved residual: 0.0000e+00

julia> value(x)
0.5

How does JuMP know that 2x=1 is complimentary to x? Or is this being passed to PATH directly?

@odow
Copy link
Member Author

odow commented Nov 14, 2024

know that 2x=1 is complimentary to x

It isn't.

This PR adds a bridge which reformulates 2x == 1 into a new constraint and variable:

y = @variable(model)
@constraint(model, 2x - 1  y)

If no complementarity constraint is set for a variable, it is defined as

@constraint(model, 0  x)

so the full model is equivalent to

model = Model(PATHSolver.Optimizer)
@variable(model, x >= 0, start = 1)
@variable(model, y)
@constraint(model, 0       x)
@constraint(model, 2x - 1  y)

@odow odow merged commit 02dc52c into master Nov 14, 2024
16 checks passed
@odow odow deleted the od/complements-bridges branch November 14, 2024 21:13
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.

Add a bridge for f-in-LessThan,GreaterThan,EqualTo to Complements
3 participants