From a95bf1a53ab49f2ab439272e6f45d953cd939f55 Mon Sep 17 00:00:00 2001 From: odow Date: Sat, 3 Feb 2024 15:40:34 +1300 Subject: [PATCH] Fix a silly mistake with z-1 instead of 1-z --- src/Bridges/Constraint/bridges/count_distinct.jl | 10 +++++----- test/Bridges/Constraint/count_distinct.jl | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Bridges/Constraint/bridges/count_distinct.jl b/src/Bridges/Constraint/bridges/count_distinct.jl index f49c45a570..fa4ce11f2f 100644 --- a/src/Bridges/Constraint/bridges/count_distinct.jl +++ b/src/Bridges/Constraint/bridges/count_distinct.jl @@ -55,7 +55,7 @@ which is equivalent to (for suitable `M`): \\begin{aligned} z \\in \\{0, 1\\} \\\\ x - y - M * z <= -1 \\\\ -y - x - M * (z - 1) <= -1 +y - x - M * (1 - z) <= -1 \\end{aligned} ``` @@ -310,7 +310,7 @@ function _final_touch_not_equal_case( # <--> # {x - y <= -1} \/ {y - x <= -1} # <--> - # {x - y - M * z <= -1} /\ {y - x - M * (z - 1) <= -1}, z in {0, 1} + # {x - y - M * z <= -1} /\ {y - x - M * (1 - z) <= -1}, z in {0, 1} z, _ = MOI.add_constrained_variable(model, MOI.ZeroOne()) push!(bridge.variables, z) x, y = scalars[2], scalars[3] @@ -327,15 +327,15 @@ function _final_touch_not_equal_case( allow_modify_function = true, ), ) - # {y - x - M * (z - 1) <= -1}, M = u_x - l_y + 1 + # {y - x - M * (1 - z) <= -1}, M = u_x - l_y + 1 M = by[2] - bx[1] + 1 g = MOI.Utilities.operate(-, T, y, x) push!( bridge.less_than, MOI.Utilities.normalize_and_add_constraint( model, - MOI.Utilities.operate!(-, T, g, M * z), - MOI.LessThan(T(-1 - M)); + MOI.Utilities.operate!(+, T, g, M * z), + MOI.LessThan(T(-1 + M)); allow_modify_function = true, ), ) diff --git a/test/Bridges/Constraint/count_distinct.jl b/test/Bridges/Constraint/count_distinct.jl index 8502d56835..d06cd33b20 100644 --- a/test/Bridges/Constraint/count_distinct.jl +++ b/test/Bridges/Constraint/count_distinct.jl @@ -75,7 +75,7 @@ function test_runtests_VectorOfVariables_NotEqualTo() """ variables: n, x, y, z 1.0 * x + -1.0 * y + -3.0 * z <= -1.0 - 1.0 * y + -1.0 * x + -5.0 * z <= -6.0 + 1.0 * y + -1.0 * x + 5.0 * z <= 4.0 x in Interval(1.0, 4.0) y >= 2.0 y <= 5.0