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] improve function getter of SplitHyperRectangleBridge #2681

Merged
merged 2 commits into from
Mar 6, 2025

Conversation

odow
Copy link
Member

@odow odow commented Mar 5, 2025

This avoids adding and subtracting 0 to avoid terms like +(-(+(x), 0), 0)

Before

julia> include("/Users/oscar/.julia/dev/MathOptInterface/test/Bridges/Constraint/SplitHyperRectangleBridge.jl")
WARNING: replacing module TestConstraintHyperRectangle.
test_basic_HyperRectangle: Test Failed at /Users/oscar/.julia/dev/MathOptInterface/src/Test/test_basic_constraint.jl:268
  Expression: isapprox(MOI.Utilities.canonical(f), constraint_function, config)
   Evaluated: isapprox(┌                                                                                                           ┐
│+(-(+(^(MOI.VariableIndex(1), (2)), ^(MOI.VariableIndex(2), (2)), ^(MOI.VariableIndex(3), (2))), 0.0), 0.0)│
│+(-(+(MOI.VariableIndex(2)), 0.0), 0.0)                                                                    │
│+(-(+(MOI.VariableIndex(3)), 0.0), 0.0)                                                                    │
└                                                                                                           ┘, ┌                                                                                           ┐
│+(^(MOI.VariableIndex(1), (2)), ^(MOI.VariableIndex(2), (2)), ^(MOI.VariableIndex(3), (2)))│
│+(MOI.VariableIndex(2))                                                                    │
│+(MOI.VariableIndex(3))                                                                    │
└                                                                                           ┘, MathOptInterface.Test.Config{Float64}(1.4901161193847656e-8, 1.4901161193847656e-8, MathOptInterface.OPTIMAL, MathOptInterface.INFEASIBLE, Any[]))

Stacktrace:
 [1] macro expansion
   @ ~/.julia/juliaup/julia-1.10.8+0.x64.apple.darwin14/share/julia/stdlib/v1.10/Test/src/Test.jl:672 [inlined]
 [2] _basic_constraint_test_helper(model::MathOptInterface.Bridges.Constraint.SingleBridgeOptimizer{MathOptInterface.Bridges.Constraint.SplitHyperRectangleBridge{Float64}, MathOptInterface.Utilities.Model{Float64}}, config::MathOptInterface.Test.Config{Float64}, ::Type{MathOptInterface.VectorNonlinearFunction}, ::Type{MathOptInterface.HyperRectangle}, add_variables_fn::typeof(MathOptInterface.add_variables))
   @ MathOptInterface.Test ~/.julia/dev/MathOptInterface/src/Test/test_basic_constraint.jl:268
 [3] _basic_constraint_test_helper
   @ ~/.julia/dev/MathOptInterface/src/Test/test_basic_constraint.jl:219 [inlined]
 [4] test_basic_VectorNonlinearFunction_HyperRectangle
   @ ~/.julia/dev/MathOptInterface/src/Test/test_basic_constraint.jl:403 [inlined]
 [5] test_basic_HyperRectangle()
   @ Main.TestConstraintHyperRectangle ~/.julia/dev/MathOptInterface/test/Bridges/Constraint/SplitHyperRectangleBridge.jl:129
 [6] macro expansion
   @ ~/.julia/dev/MathOptInterface/test/Bridges/Constraint/SplitHyperRectangleBridge.jl:17 [inlined]
 [7] macro expansion
   @ ~/.julia/juliaup/julia-1.10.8+0.x64.apple.darwin14/share/julia/stdlib/v1.10/Test/src/Test.jl:1577 [inlined]
 [8] runtests()
   @ Main.TestConstraintHyperRectangle ~/.julia/dev/MathOptInterface/test/Bridges/Constraint/SplitHyperRectangleBridge.jl:17
test_basic_HyperRectangle: Test Failed at /Users/oscar/.julia/dev/MathOptInterface/src/Test/test_basic_constraint.jl:269
  Expression: isapprox(MOI.get(model, MOI.CanonicalConstraintFunction(), c), constraint_function, config)
   Evaluated: isapprox(┌                                                                                                           ┐
│+(-(+(^(MOI.VariableIndex(1), (2)), ^(MOI.VariableIndex(2), (2)), ^(MOI.VariableIndex(3), (2))), 0.0), 0.0)│
│+(-(+(MOI.VariableIndex(2)), 0.0), 0.0)                                                                    │
│+(-(+(MOI.VariableIndex(3)), 0.0), 0.0)                                                                    │
└                                                                                                           ┘, ┌                                                                                           ┐
│+(^(MOI.VariableIndex(1), (2)), ^(MOI.VariableIndex(2), (2)), ^(MOI.VariableIndex(3), (2)))│
│+(MOI.VariableIndex(2))                                                                    │
│+(MOI.VariableIndex(3))                                                                    │
└                                                                                           ┘, MathOptInterface.Test.Config{Float64}(1.4901161193847656e-8, 1.4901161193847656e-8, MathOptInterface.OPTIMAL, MathOptInterface.INFEASIBLE, Any[]))

Stacktrace:
 [1] macro expansion
   @ ~/.julia/juliaup/julia-1.10.8+0.x64.apple.darwin14/share/julia/stdlib/v1.10/Test/src/Test.jl:672 [inlined]
 [2] _basic_constraint_test_helper(model::MathOptInterface.Bridges.Constraint.SingleBridgeOptimizer{MathOptInterface.Bridges.Constraint.SplitHyperRectangleBridge{Float64}, MathOptInterface.Utilities.Model{Float64}}, config::MathOptInterface.Test.Config{Float64}, ::Type{MathOptInterface.VectorNonlinearFunction}, ::Type{MathOptInterface.HyperRectangle}, add_variables_fn::typeof(MathOptInterface.add_variables))
   @ MathOptInterface.Test ~/.julia/dev/MathOptInterface/src/Test/test_basic_constraint.jl:269
 [3] _basic_constraint_test_helper
   @ ~/.julia/dev/MathOptInterface/src/Test/test_basic_constraint.jl:219 [inlined]
 [4] test_basic_VectorNonlinearFunction_HyperRectangle
   @ ~/.julia/dev/MathOptInterface/src/Test/test_basic_constraint.jl:403 [inlined]
 [5] test_basic_HyperRectangle()
   @ Main.TestConstraintHyperRectangle ~/.julia/dev/MathOptInterface/test/Bridges/Constraint/SplitHyperRectangleBridge.jl:129
 [6] macro expansion
   @ ~/.julia/dev/MathOptInterface/test/Bridges/Constraint/SplitHyperRectangleBridge.jl:17 [inlined]
 [7] macro expansion
   @ ~/.julia/juliaup/julia-1.10.8+0.x64.apple.darwin14/share/julia/stdlib/v1.10/Test/src/Test.jl:1577 [inlined]
 [8] runtests()
   @ Main.TestConstraintHyperRectangle ~/.julia/dev/MathOptInterface/test/Bridges/Constraint/SplitHyperRectangleBridge.jl:17
Test Summary:             | Pass  Fail  Total  Time
test_basic_HyperRectangle |   89     2     91  2.1s
ERROR: LoadError: Some tests did not pass: 89 passed, 2 failed, 0 errored, 0 broken.
in expression starting at /Users/oscar/.julia/dev/MathOptInterface/test/Bridges/Constraint/SplitHyperRectangleBridge.jl:135

After

julia> include("/Users/oscar/.julia/dev/MathOptInterface/test/Bridges/Constraint/SplitHyperRectangleBridge.jl")
WARNING: replacing module TestConstraintHyperRectangle.
Test Summary:             | Pass  Total  Time
test_basic_HyperRectangle |   91     91  1.8s
Test Summary:                      | Pass  Total  Time
test_runtests_VectorAffineFunction |   29     29  0.1s
Test Summary:                   | Pass  Total  Time
test_runtests_VectorOfVariables |   29     29  0.1s
Test Summary:                         | Pass  Total  Time
test_runtests_VectorOfVariables_zeros |   29     29  0.0s
Test Summary:          | Pass  Total  Time
test_runtests_free_row |   29     29  0.0s
Test Summary:                | Pass  Total  Time
test_runtests_infinity_lower |   29     29  0.0s
Test Summary:                | Pass  Total  Time
test_runtests_infinity_upper |   29     29  0.0s

This avoids adding and subtracting 0 to avoid terms like +(-(+(x), 0), 0)
@odow
Copy link
Member Author

odow commented Mar 5, 2025

This needs some better tests. It doesn't account for a few things

@odow odow merged commit 6e9fcac into master Mar 6, 2025
31 checks passed
@odow odow deleted the od/SplitHyperRectangleBridge branch March 6, 2025 01:06
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.

1 participant