From ee544c9a049a113efdb78bca9ba0917e57d8341e Mon Sep 17 00:00:00 2001 From: odow Date: Tue, 7 Nov 2023 09:48:05 +1300 Subject: [PATCH 1/3] [docs] move manual section on Semicontinuous and Semiinteger variables --- docs/src/manual/constraints.md | 28 ---------------------------- docs/src/manual/variables.md | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/docs/src/manual/constraints.md b/docs/src/manual/constraints.md index 40df7c8dc1e..9f6490e044d 100644 --- a/docs/src/manual/constraints.md +++ b/docs/src/manual/constraints.md @@ -1296,34 +1296,6 @@ julia> @constraint(model, [t; u; x] in RotatedSecondOrderCone()) [t, u, x[1], x[2]] ∈ MathOptInterface.RotatedSecondOrderCone(4) ``` -## Semi-integer and semi-continuous variables - -Semi-continuous variables are constrained to the set -``x \in \{0\} \cup [l, u]``. - -Create a semi-continuous variable using the [`Semicontinuous`](@ref) set: -```jldoctest -julia> model = Model(); - -julia> @variable(model, x); - -julia> @constraint(model, x in Semicontinuous(1.5, 3.5)) -x in MathOptInterface.Semicontinuous{Float64}(1.5, 3.5) -``` - -Semi-integer variables are constrained to the set -``x \in \{0\} \cup \{l, l+1, \dots, u\}``. - -Create a semi-integer variable using the [`Semiinteger`](@ref) set: -```jldoctest -julia> model = Model(); - -julia> @variable(model, x); - -julia> @constraint(model, x in Semiinteger(1.0, 3.0)) -x in MathOptInterface.Semiinteger{Float64}(1.0, 3.0) -``` - ## Special Ordered Sets of Type 1 In a Special Ordered Set of Type 1 (often denoted SOS-I or SOS1), at most one diff --git a/docs/src/manual/variables.md b/docs/src/manual/variables.md index ce8d6cf11a5..4c57da8a370 100644 --- a/docs/src/manual/variables.md +++ b/docs/src/manual/variables.md @@ -640,6 +640,30 @@ julia> set_integer(x) in the model, returning a function that can be called to undo the operation later on. +## Semi-integer and semi-continuous variables + +Semi-continuous variables are constrained to the set +``x \in \{0\} \cup [l, u]``. + +Create a semi-continuous variable using the [`Semicontinuous`](@ref) set: +```jldoctest +julia> model = Model(); + +julia> @variable(model, x in Semicontinuous(1.5, 3.5)) +x +``` + +Semi-integer variables are constrained to the set +``x \in \{0\} \cup \{l, l+1, \dots, u\}``. + +Create a semi-integer variable using the [`Semiinteger`](@ref) set: +```jldoctest +julia> model = Model(); + +julia> @variable(model, x in Semiinteger(1.0, 3.0)) +x +``` + ## Start values There are two ways to provide a primal starting solution (also called MIP-start From b4eb983976e1f3389516dbd481f7d966d40060f1 Mon Sep 17 00:00:00 2001 From: odow Date: Tue, 7 Nov 2023 09:53:11 +1300 Subject: [PATCH 2/3] Update tips_and_tricks --- docs/src/tutorials/linear/tips_and_tricks.jl | 31 ++++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/docs/src/tutorials/linear/tips_and_tricks.jl b/docs/src/tutorials/linear/tips_and_tricks.jl index ab2b5a7e9d2..b339521c36e 100644 --- a/docs/src/tutorials/linear/tips_and_tricks.jl +++ b/docs/src/tutorials/linear/tips_and_tricks.jl @@ -237,15 +237,6 @@ M = 100 # ## Semi-continuous variables -# !!! info -# This section uses sets from [MathOptInterface](@ref moi_documentation). -# By default, JuMP exports the `MOI` symbol as an alias for the -# MathOptInterface.jl package. We recommend making this more explicit in -# your code by adding the following lines: -# ```julia -# import MathOptInterface as MOI -# ``` - # A semi-continuous variable is a continuous variable between bounds $[l,u]$ # that also can assume the value zero, that is: # $$x \in \{0\} \cup [l,u].$$ @@ -255,6 +246,17 @@ M = 100 model = Model(); @variable(model, x in Semicontinuous(1.0, 2.0)) +# You can also represent a semi-continuous variable using the reformulation: + +model = Model(); +@variable(model, x) +@variable(model, z, Bin) +@constraint(model, x <= 2 * z) +@constraint(model, x >= 1 * z) + +# When `z = 0` the two constraints are equivalent to `0 <= x <= 0`. When `z = 1`, +# the two constraints are equivalennt to `1 <= x <= 2`. + # ## Semi-integer variables # A semi-integer variable is a variable which assumes integer values between @@ -264,6 +266,17 @@ model = Model(); model = Model(); @variable(model, x in Semiinteger(5.0, 10.0)) +# You can also represent a semi-integer variable using the reformulation: + +model = Model(); +@variable(model, x, Int) +@variable(model, z, Bin) +@constraint(model, x <= 10 * z) +@constraint(model, x >= 5 * z) + +# When `z = 0` the two constraints are equivalent to `0 <= x <= 0`. When `z = 1`, +# the two constraints are equivalennt to `5 <= x <= 10`. + # ## Special Ordered Sets of Type 1 # A Special Ordered Set of Type 1 is a set of variables, at most one of which From a82fc6687ee7711cf883221b7e5e80073f0d9de0 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Tue, 7 Nov 2023 11:10:31 +1300 Subject: [PATCH 3/3] Apply suggestions from code review --- docs/src/tutorials/linear/tips_and_tricks.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/tutorials/linear/tips_and_tricks.jl b/docs/src/tutorials/linear/tips_and_tricks.jl index b339521c36e..279f15e1a3e 100644 --- a/docs/src/tutorials/linear/tips_and_tricks.jl +++ b/docs/src/tutorials/linear/tips_and_tricks.jl @@ -255,7 +255,7 @@ model = Model(); @constraint(model, x >= 1 * z) # When `z = 0` the two constraints are equivalent to `0 <= x <= 0`. When `z = 1`, -# the two constraints are equivalennt to `1 <= x <= 2`. +# the two constraints are equivalent to `1 <= x <= 2`. # ## Semi-integer variables @@ -275,7 +275,7 @@ model = Model(); @constraint(model, x >= 5 * z) # When `z = 0` the two constraints are equivalent to `0 <= x <= 0`. When `z = 1`, -# the two constraints are equivalennt to `5 <= x <= 10`. +# the two constraints are equivalent to `5 <= x <= 10`. # ## Special Ordered Sets of Type 1