@@ -124,6 +124,65 @@ function add_constrained_variable(model::ModelLike, set::AbstractScalarSet)
124124 return variable, constraint
125125end
126126
127+ """
128+ add_constrained_variable(
129+ model::ModelLike,
130+ set::Tuple{<:GreaterThan,<:LessThan},
131+ )
132+
133+ A special-case method to add a scalar variable with a lower and upper bound.
134+
135+ This method should be implemented by optimizers which have native support for
136+ adding a variable with bounds and which cannot performantly modify the variable
137+ bounds after creation.
138+
139+ ## Example
140+
141+ ```jldoctest
142+ julia> import MathOptInterface as MOI
143+
144+ julia> model = MOI.Utilities.Model{Float64}();
145+
146+ julia> set = (MOI.GreaterThan(1.0), MOI.LessThan(2.0));
147+
148+ julia> x, (c_l, c_u) = MOI.add_constrained_variable(model, set);
149+
150+ julia> c_l
151+ MathOptInterface.ConstraintIndex{MathOptInterface.VariableIndex, MathOptInterface.GreaterThan{Float64}}(1)
152+
153+ julia> c_u
154+ MathOptInterface.ConstraintIndex{MathOptInterface.VariableIndex, MathOptInterface.LessThan{Float64}}(1)
155+
156+ julia> print(model)
157+ Feasibility
158+
159+ Subject to:
160+
161+ VariableIndex-in-GreaterThan{Float64}
162+ v[1] >= 1.0
163+
164+ VariableIndex-in-LessThan{Float64}
165+ v[1] <= 2.0
166+ ```
167+ """
168+ function add_constrained_variable (
169+ model:: ModelLike ,
170+ set:: Tuple{<:GreaterThan,<:LessThan} ,
171+ )
172+ set_1, set_2 = set
173+ x, c_1 = add_constrained_variable (model, set_1)
174+ c_2 = add_constraint (model, x, set_2)
175+ return x, (c_1, c_2)
176+ end
177+
178+ function supports_add_constrained_variable (
179+ model:: ModelLike ,
180+ :: Type{Tuple{L,U}} ,
181+ ) where {L<: GreaterThan ,U<: LessThan }
182+ return supports_add_constrained_variable (model, L) &&
183+ supports_constraint (model, VariableIndex, U)
184+ end
185+
127186"""
128187 supports_add_constrained_variables(
129188 model::ModelLike,
0 commit comments