Skip to content

Commit

Permalink
Merge pull request #1693 from JuliaOpt/bl/binint
Browse files Browse the repository at this point in the history
🚸 Improve integer and binary printing
  • Loading branch information
blegat committed Dec 20, 2018
2 parents 7a0d183 + cf6f6d9 commit 820ae46
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
4 changes: 2 additions & 2 deletions docs/src/constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,12 @@ achieved using the [`@constraint`](@ref) macro. For example, `MOI.ZeroOne()`
restricts the domain to ``\{0, 1\}:
```jldoctest; setup = :(model = Model(); @variable(model, x))
julia> @constraint(model, x in MOI.ZeroOne())
x in MathOptInterface.ZeroOne()
x binary
```
and `MOI.Integer()` restricts to the domain to the integers ``\mathbb{Z}``:
```jldoctest; setup = :(model = Model(); @variable(model, x))
julia> @constraint(model, x in MOI.Integer())
x in MathOptInterface.Integer()
x integer
```

JuMP also supports modeling semi-continuous variables, whose domain is ``\{0\}
Expand Down
3 changes: 3 additions & 0 deletions src/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,9 @@ function in_set_string(print_mode, set::MOI.Interval)
set.upper, math_symbol(print_mode, :close_rng))
end

in_set_string(print_mode, ::MOI.ZeroOne) = "binary"
in_set_string(print_mode, ::MOI.Integer) = "integer"

# TODO: Convert back to JuMP types for sets like PSDCone.
# TODO: Consider fancy latex names for some sets. They're currently printed as
# regular text in math mode which looks a bit awkward.
Expand Down
36 changes: 18 additions & 18 deletions test/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ function printing_test(ModelType::Type{<:JuMP.AbstractModel})
zero_one = @constraint(model, x in MathOptInterface.ZeroOne())

io_test(REPLMode, JuMP.LowerBoundRef(x), "x $ge 10.0")
io_test(REPLMode, zero_one, "x $in_sym MathOptInterface.ZeroOne()")
# TODO: Test in IJulia mode and do nice printing for {0, 1}.
io_test(REPLMode, zero_one, "x binary")
# TODO: Test in IJulia mode
end

@testset "VectorOfVariable constraints" begin
Expand Down Expand Up @@ -378,14 +378,14 @@ function printing_test(ModelType::Type{<:JuMP.AbstractModel})
io_test(REPLMode, model_1, """
Max a - b + 2 a1 - 10 x
Subject to
x $inset MathOptInterface.ZeroOne()
u[1] $inset MathOptInterface.ZeroOne()
u[2] $inset MathOptInterface.ZeroOne()
u[3] $inset MathOptInterface.ZeroOne()
a1 $inset MathOptInterface.Integer()
b1 $inset MathOptInterface.Integer()
c1 $inset MathOptInterface.Integer()
z $inset MathOptInterface.Integer()
x binary
u[1] binary
u[2] binary
u[3] binary
a1 integer
b1 integer
c1 integer
z integer
fi $eq 9.0
a $ge 1.0
c $ge -1.0
Expand Down Expand Up @@ -420,14 +420,14 @@ function printing_test(ModelType::Type{<:JuMP.AbstractModel})

io_test(IJuliaMode, model_1, """
\\begin{alignat*}{1}\\max\\quad & a - b + 2 a1 - 10 x\\\\
\\text{Subject to} \\quad & x \\in MathOptInterface.ZeroOne()\\\\
& u_{1} \\in MathOptInterface.ZeroOne()\\\\
& u_{2} \\in MathOptInterface.ZeroOne()\\\\
& u_{3} \\in MathOptInterface.ZeroOne()\\\\
& a1 \\in MathOptInterface.Integer()\\\\
& b1 \\in MathOptInterface.Integer()\\\\
& c1 \\in MathOptInterface.Integer()\\\\
& z \\in MathOptInterface.Integer()\\\\
\\text{Subject to} \\quad & x binary\\\\
& u_{1} binary\\\\
& u_{2} binary\\\\
& u_{3} binary\\\\
& a1 integer\\\\
& b1 integer\\\\
& c1 integer\\\\
& z integer\\\\
& fi = 9.0\\\\
& a \\geq 1.0\\\\
& c \\geq -1.0\\\\
Expand Down

0 comments on commit 820ae46

Please sign in to comment.