Recently, I have encountered some problems in optimizing code speed. I guess it is because I always create dense array variables
I want to create a 4x4 array variables, but it only has a value at the index (1, 2), (2, 1), (2, 3), (3, 2) and the rest is 0. The current practice is to use the following code:
model = Model(Gurobi.Optimizer) @variable(model, x[1:4, 1:4]) @constraints(model, begin x[1, 2] == 0 x[2, 1] == 0 x[2, 3] == 0 x[3, 2] == 0 end)
When the array size is very small, this will not have any adverse impact, but when the array size is very large, many unnecessary variables and constraints will be created. I guess this reduces the speed of model construction and solver solving
What I want to achieve is to create a sparse array variable, but it can be used as a full matrix, including index, matrix multiplication and so on. It is as natural and convenient as MATLAB.
Thanks a lot !