From 4714a1218d98a31ee502392ad947d740ccc07dc2 Mon Sep 17 00:00:00 2001 From: joaquimg Date: Fri, 25 Oct 2024 18:47:46 -0300 Subject: [PATCH] [DNM] add variables and bound in a single shot --- src/Utilities/variables.jl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Utilities/variables.jl b/src/Utilities/variables.jl index 7f0ed67149..4e7abd72c4 100644 --- a/src/Utilities/variables.jl +++ b/src/Utilities/variables.jl @@ -125,3 +125,19 @@ function get_bounds( bounds_cache[x] = (l, u) return (l, u) end + +# fallback +function add_variable_and_bounds( + model::MOI.ModelLike, + lower_bound, + upper_bound, +) + v = MOI.add_variable(model) + if lower_bound !== nothing + MOI.add_constraint(model, v, MOI.GreaterThan(lower_bound)) + end + if upper_bound !== nothing + MOI.add_constraint(model, v, MOI.LessThan(upper_bound)) + end + return v +end