What about adding a kwarg option obj in JuMP.@variable so that we can specify objective coefficients? just like the existing lower_bound?
julia> import JuMP
julia> model = JuMP.Model();
julia> JuMP.set_objective_sense(model, JuMP.MIN_SENSE);
julia> # [I propose this] JuMP.@variable(model, x[i=1:2, j=1:3], lower_bound=i-j, obj=i+j);
julia> JuMP.@variable(model, x[i=1:2, j=1:3], lower_bound=i-j); # existing
julia> for i=1:2, j=1:3 # currently I have to single this part out
JuMP.set_objective_coefficient(model, x[i,j], i+j)
end
julia> print(model)
Min 2 x[1,1] + 3 x[1,2] + 4 x[1,3] + 3 x[2,1] + 4 x[2,2] + 5 x[2,3]
Subject to
x[1,1] ≥ 0
x[2,1] ≥ 1
x[1,2] ≥ -1
x[2,2] ≥ 0
x[1,3] ≥ -2
x[2,3] ≥ -1
(I happen to think of this today, it’s a different issue. I put it here for convenience)
I think the design of the JuMP container is somewhat inconsistent. Look at
julia> JuMP.@variable(model, x[i=1:2, j=1:3])
2×3 Matrix{JuMP.VariableRef}:
x[1,1] x[1,2] x[1,3]
x[2,1] x[2,2] x[2,3]
julia> JuMP.@variable(model, y[i=1:2, j=ifelse(i>1, 2:3, 1:1)])
JuMP.Containers.SparseAxisArray{JuMP.VariableRef, 2, Tuple{Int64, Int64}} with 3 entries:
[1, 1] = y[1,1]
[2, 2] = y[2,2]
[2, 3] = y[2,3]
For the x, from julia’s (column-wise storage) standpoint, j is the “major” or “outer” index.,
But concerning y, i becomes the “major” or “outer” index.
What I’m thinking is that if we change the JuMP’s grammar for the y’s construction to be
JuMP.@variable(model, y[j=ifelse(i>1, 2:3, 1:1), i=1:2])
, it would seems more consistent to me, resembling the math textbook style, e.g.
" some assertion about s holds, \forall s \in S(n), n \in \mathbb{Z}"