diff --git a/docs/src/constraints.md b/docs/src/constraints.md index cf793477eab..29b2762b25b 100644 --- a/docs/src/constraints.md +++ b/docs/src/constraints.md @@ -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\} ∪ diff --git a/src/print.jl b/src/print.jl index f1392a72507..0d3ccd0d8a1 100644 --- a/src/print.jl +++ b/src/print.jl @@ -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. diff --git a/test/print.jl b/test/print.jl index fbd2123cdc6..3309b6d22ad 100644 --- a/test/print.jl +++ b/test/print.jl @@ -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 @@ -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 @@ -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\\\\