Skip to content

Commit

Permalink
[docs] clarify indicator constraints must use variables for LHS
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Nov 26, 2023
1 parent ca42d00 commit b9117b9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/src/developers/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ Rewriting my_equal_to to ==

!!! tip
When parsing a constraint you can recurse into sub-constraint (for example, the
`{expr}` in `z => {x <= 1}`) by calling [`parse_constraint`](@ref).
`{expr}` in `z --> {x <= 1}`) by calling [`parse_constraint`](@ref).

To prevent JuMP from promoting the set to the same value type as the model, use
[`SkipModelConvertScalarSetWrapper`](@ref).
Expand Down
12 changes: 8 additions & 4 deletions docs/src/manual/constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -1366,17 +1366,21 @@ y
julia> @variable(model, a, Bin)
a
julia> @constraint(model, a => {x + y <= 1})
a => {x + y ≤ 1}
julia> @constraint(model, a --> {x + y <= 1})
a --> {x + y ≤ 1}
```

If the constraint must hold when `a` is zero, add `!` or `¬` before the binary
variable;
```jldoctest indicator
julia> @constraint(model, !a => {x + y <= 1})
!a => {x + y ≤ 1}
julia> @constraint(model, !a --> {x + y <= 1})
!a --> {x + y ≤ 1}
```

!!! warning
You cannot use an expression for the left-hand side of an indicator
constraint.

## Semidefinite constraints

To constrain a matrix to be positive semidefinite (PSD), use [`PSDCone`](@ref):
Expand Down
4 changes: 2 additions & 2 deletions docs/src/tutorials/linear/tips_and_tricks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ M = 100
model = Model();
@variable(model, x[1:2])
@variable(model, z, Bin)
@constraint(model, z => {sum(x) <= 1})
@constraint(model, z --> {sum(x) <= 1})

# **Example** $x_1 + x_2 \leq 1$ if $z = 0$.

model = Model();
@variable(model, x[1:2])
@variable(model, z, Bin)
@constraint(model, !z => {sum(x) <= 1})
@constraint(model, !z --> {sum(x) <= 1})

# ### Trick 2

Expand Down
2 changes: 1 addition & 1 deletion src/indicator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ function constraint_string(
end
con = ScalarConstraint(constraint.func[2], constraint.set.set)
con_str = constraint_string(print_mode, con)
return var_str * " => {" * con_str * "}"
return var_str * " --> {" * con_str * "}"
end
4 changes: 4 additions & 0 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ JuMP currently supports the following `expr` objects:
* `lhs ⟂ rhs`
* `lhs in rhs`
* `lhs ∈ rhs`
* `z --> {constraint}`
* `!z --> {constraint}`
* `z <--> {constraint}`
* `!z <--> {constraint}`
* `z => {constraint}`
* `!z => {constraint}`
as well as all broadcasted variants.
Expand Down
2 changes: 1 addition & 1 deletion test/test_print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ function test_extension_printing_indicator_constraints(
@variable(model, y)
ind_constr = @constraint(model, !x => {y <= 1})

io_test(MIME("text/plain"), ind_constr, "!x => {y $le 1}")
io_test(MIME("text/plain"), ind_constr, "!x --> {y $le 1}")
# TODO: Test in IJulia mode.
return
end
Expand Down

0 comments on commit b9117b9

Please sign in to comment.