When I read a model from a ".mps" file using "read_from_file" in JuMP and print it, I find that many bounds are written in the interval format like "x \in [0, 1]". I want to change an interval to a lower bound and an upper bound like "x >= 0, x <= 1" but when I use the function "lower_bound", it tells me "x does not have a lower bound". Why would this happen? How can I do the transformation?
1 Answer
You can use:
julia> using JuMP
julia> function change_interval_to_bounds(model::JuMP.Model)
for c_index in all_constraints(model, VariableRef, MOI.Interval{Float64})
constraint = constraint_object(c_index)
delete(model, c_index)
set_lower_bound(constraint.func, constraint.set.lower)
set_upper_bound(constraint.func, constraint.set.upper)
end
return
end
change_interval_to_bounds (generic function with 1 method)
julia> model = Model();
julia> @variable(model, x in MOI.Interval(0.0, 1.0));
julia> print(model)
Feasibility
Subject to
x ∈ [0, 1]
julia> change_interval_to_bounds(model)
julia> print(model)
Feasibility
Subject to
x ≥ 0
x ≤ 1
We don't have built-in support for this because we assume that models read from file should stay as they are. (And it's only a few lines to implement manually.)
When you create a model using @variable(model, l <= x <= u)
we add two separate constraints instead of a single Interval
constraint because people want to change bounds, etc.
-
$\begingroup$ p.s. you can also post JuMP-related questions on our forum discourse.julialang.org/c/domain/opt/13 $\endgroup$ Sep 18 at 6:45