I am a starter to JuMP and I am trying to construct a matrix that consists of both variables and real number(0s). The first way I can think of is to push! entries(variables or 0s) to an array and then push! multiple arrays to another array. But this array of arrays may not work well for matrix multiplication since the dimension doesn’t match. The second way is to construct a matrix of variables @variable(model, C[1:100,1:100]), and then fix some entries to 0. But those entries with fixed values are still considered as variables in the solver, so I am adding unnecessary variables to the model. Therefore, does anyone know how to construct a matrix (2D array, not array of arrays) that consists of both variables and 0s? Thanks in advance.
You could try d = Matrix(n, m);
which returns a n*m matrix of #undefined values, it’s a bit of a workaround for the zeros(type ::Any) error
Note that julia doesn’t like to display (vectors of?) #undef’s, eg print(d[1, :]) will probably err until you put data in there
Thanks I will try! I should have got more familiar with Julia before using JuMP.
1 Like
If your non-variable entries will always take on the value 0, could you not just use a sparse array?
1 Like