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

[docs] clarify indicator constraints must use variables for LHS #3582

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading