JuMP: print constraint evaluated with start_values of variables

I’ve got a moderately complicated model that I’m trying to display the infeasibility of the start point via code that looks like:

    @constraint(model, dyn1, 0 == X1 - Ba * V1 - Xa1 .* ones(N))
    @constraint(model, dyn2, 0 == (t1 - t0) / 2 * F1 - V1)
    @constraint(model, dyn3, 0 == Xa1 + wB' * V1 - Xb1)
    display(start_value(dyn1))
    display(start_value(dyn2))
    display(start_value(dyn3))

I just get three lines of literally “nothing” printed out. I’m expecting a bunch of matrices that would hopefully be filled with values near zero. From the docs, it looks like you can assign a start_value directly on a constraint, which is what that is presumably printing (I don’t want that, so haven’t set that). If I do e.g. display(dyn1) I get a large symbolic expression composed of all my variables, and my variables should all have starting values. How do I push those starting values through the constraint expression and print it out?

1 Like

I think you’re looking for:

julia> model = Model()
A JuMP Model
├ solver: none
├ objective_sense: FEASIBILITY_SENSE
├ num_variables: 0
├ num_constraints: 0
└ Names registered in the model: none

julia> @variable(model, x, start = 1)
x

julia> @constraint(model, c1, x >= 0)
c1 : x ≥ 0

julia> @constraint(model, c2, 2 * x <= -1)
c2 : 2 x ≤ -1

julia> primal_feasibility_report(start_value, model)
Dict{Any, Float64} with 1 entry:
  c2 : 2 x ≤ -1 => 3.0

You could also do

julia> value(start_value, c2)
2.0

which gets the primal value of c2 using start_value for the variables.

Thanks, both of those look like they work, but the primal_infeasibility_report() is a bit harder to read. Using display(value(start_value, dyn1)) gives me all the zeros I was looking for, though.

1 Like

The return value is a dictionary, so it’s intended to be iterated over, rather than pretty printing. You could do something like:

julia> for (k, v) in primal_feasibility_report(start_value, model)
           println("Constraint $(name(k)) is infeasible by $v")
           println("The primal value is ", value(start_value, k))
       end
Constraint c2 is infeasible by 3.0
The primal value is 2.0