JuMP package: Cannot display the values of decision variable

Hello everyone,

I have coded a mixed-integer linear optimization model.
I am having trouble displaying the decision variable results.

I have a decision variable:
@variable(m, 0 <= Y[i in I,j in J] <=1)

It is optimally solved and I get results for my other binary decision variable X[i]. However Y does not display. (Which is only 300 by 300 matrix).

Thus, I have tried the following and it is also not working:
image

Could you please help me with this?
I need to write Y values in excel file eventually.

Thanks!

You have getvalue(Y[i, j] > 0), but you should have getvalue(Y[i, j]) > 0.

Thank you rdeits for the prompt help. You are right.

One code that still does not work
getvalue(Y) takes forever. On the other side, getvalue(X) works perfect.

As an alternative, when I use the code below, it works:

Matrix=zeros(size(I)[1],size(J)[1])
for i in I
for j in J
Matrix[i,j]=getvalue(Y[i,j])
end
end
Matrix

Any thought what could be the reason for not getting anything from getvalue(Y) ?

It’s difficult to answer that without being able to see your code. Can you post a minimal reproducible example that shows the difference in timing?

I can’t reproduce those performance results. In fact, that appears to be significantly slower than getvalue(Y).

julia> using JuMP, Clp, BenchmarkTools

julia> m = Model(solver = ClpSolver());

julia> I = 1 : 300; J = 1 : 300;

julia> @variable(m, 0 <= Y[i in I, j in J] <=1)
0 ≤ Y[i,j] ≤ 1 ∀ i ∈ {1,2,…,299,300}, j ∈ {1,2,…,299,300}

julia> solve(m);

julia> @benchmark getvalue($Y)
WARNING: JuMP._getValue has been called on a collection of variables a large number of times. For performance reasons, this should be avoided. Instead of JuMP._getValue(x)[a,b,c], use JuMP._getValue(x[a,b,c]) to avoid temporary allocations.
BenchmarkTools.Trial: 
  memory estimate:  706.77 KiB
  allocs estimate:  52
  --------------
  minimum time:     1.315 ms (0.00% GC)
  median time:      1.438 ms (0.00% GC)
  mean time:        1.690 ms (12.55% GC)
  maximum time:     128.004 ms (97.99% GC)
  --------------
  samples:          2952
  evals/sample:     1

julia> function getvalue_alt(Y, I, J)
              Matrix=zeros(size(I)[1],size(J)[1])
              for i in I
              for j in J
              Matrix[i,j]=getvalue(Y[i,j])
              end
              end
              Matrix
              end
getvalue_alt (generic function with 1 method)

julia> @benchmark getvalue_alt($Y, $I, $J)
BenchmarkTools.Trial: 
  memory estimate:  703.20 KiB
  allocs estimate:  2
  --------------
  minimum time:     3.267 ms (0.00% GC)
  median time:      3.601 ms (0.00% GC)
  mean time:        3.689 ms (1.63% GC)
  maximum time:     7.498 ms (31.97% GC)
  --------------
  samples:          1352
  evals/sample:     1

Thank you both!

getvalue(X) is working but getvalue(Y) is not working at all. In fact, I don’t know how long it is suppose to take to display the results so I kill it after a few minutes. However, assigning its values to Matrix works.

getvalue(Y) >> This does not display anything, it keeps processing it for a long time without any output.

  1. This code below works:
    Matrix=zeros(size(I)[1],size(J)[1])
    for i in I
    for j in J
    Matrix[i,j]=getvalue(Y[i,j])
    end
    end
    Matrix