Skip to content

Commit

Permalink
Fix a silly mistake with z-1 instead of 1-z
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Feb 3, 2024
1 parent 36a0ff4 commit a95bf1a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/Bridges/Constraint/bridges/count_distinct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
```
Expand Down Expand Up @@ -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]
Expand All @@ -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,
),
)
Expand Down
2 changes: 1 addition & 1 deletion test/Bridges/Constraint/count_distinct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a95bf1a

Please sign in to comment.