Show all linear constraints after building JuMP model

Hi all,

I want to visualize all linear constraint in my JuMP model. I used ( model.linconstr) command but it gives only a portion of my constraints. I have 454 constraints but (model.linconstr) shows only 36 of these constraints. There is a question mark in the middle of the screen which I think is the sign for not showing all constraints. Can you please let me know how I can visualize all the constraints in my model. Thanks in advance!

All the best,
Rasoul

1 Like

See JuMP.writeLP in the JuMP docs for how to write a JuMP model as an LP file.

Alternatively,

for con in model.linconstr
    println(con)
end

Thanks for the response.
Is there any way to show variables with their corresponding bounds in JuMP model.
I tried following but I got an error (i.e., ERROR: type Model has no field variables).

for var in model.variables
    println(var)
end

Thanks in advance!

linconstr is a field in the JuMP Model struct. variables isn’t. If you’re interested, you can read the source to find what fields are in Model. That source is here: JuMP.jl/JuMP.jl at 7057a02fc28f58fb6aff9db9981a2a79c9b5ffc9 · jump-dev/JuMP.jl · GitHub

Note that this is an internal implementation detail, and so you shouldn’t rely on these fields staying the same between JuMP versions. In fact, in JuMP 0.19 (the next release), virtually all of these fields change!

The best way to query variable bounds is with JuMP.getupperbound (also getlowerbound).

If you want to visually inspect the model, writing it out as an LP file is best.

Thanks for the response!
I tried “JuMP.getupperbound(x) where x is a variable in my model” but I encountered an error (i.e., x not defined). Can you please explain a little more how I can visually inspect variable bounds after building the model.
Thanks in advance!

getupperbound(x) will only work if you have a variable called x:

model = Model()
@variable(model, x >= 1)
JuMP.getlowerbound(x)  # 1.0

The best way to visually inspect the model is to write it to an LP file.