From 438fb7e376d42cdf84d0bc62599a1beea177929b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Wed, 19 Dec 2018 18:58:36 -0500 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=9A=B8=20Improve=20integer=20and=20bi?= =?UTF-8?q?nary=20printing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/print.jl | 3 +++ test/print.jl | 34 +++++++++++++++++----------------- 2 files changed, 20 insertions(+), 17 deletions(-) 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..5fd765bda03 100644 --- a/test/print.jl +++ b/test/print.jl @@ -274,7 +274,7 @@ 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()") + io_test(REPLMode, zero_one, "x binary") # TODO: Test in IJulia mode and do nice printing for {0, 1}. end @@ -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\\\\ From da6eb4d1d7031999ab7179e1bc6e4307e54584e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Wed, 19 Dec 2018 19:19:22 -0500 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=91=8C=20Remove=20TODO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/print.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/print.jl b/test/print.jl index 5fd765bda03..3309b6d22ad 100644 --- a/test/print.jl +++ b/test/print.jl @@ -275,7 +275,7 @@ function printing_test(ModelType::Type{<:JuMP.AbstractModel}) io_test(REPLMode, JuMP.LowerBoundRef(x), "x $ge 10.0") io_test(REPLMode, zero_one, "x binary") - # TODO: Test in IJulia mode and do nice printing for {0, 1}. + # TODO: Test in IJulia mode end @testset "VectorOfVariable constraints" begin From cf6f6d92637f3acf361cde275d994c627e9f4585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Wed, 19 Dec 2018 21:35:09 -0500 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=93=9D=20Fix=20doctests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/src/constraints.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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\} ∪