2
$\begingroup$

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?

$\endgroup$

1 Answer 1

2
$\begingroup$

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.

$\endgroup$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.