Order of initial values for set_start_value in JuMP/Ipopt models

Hi @askvorts, JuMP orders variables down the columns and then across the rows.

See:

julia> using JuMP

julia> T = 3
3

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[1:T, 1:6])
3×6 Matrix{VariableRef}:
 x[1,1]  x[1,2]  x[1,3]  x[1,4]  x[1,5]  x[1,6]
 x[2,1]  x[2,2]  x[2,3]  x[2,4]  x[2,5]  x[2,6]
 x[3,1]  x[3,2]  x[3,3]  x[3,4]  x[3,5]  x[3,6]

julia> all_variables(model)
18-element Vector{VariableRef}:
 x[1,1]
 x[2,1]
 x[3,1]
 x[1,2]
 x[2,2]
 x[3,2]
 x[1,3]
 x[2,3]
 x[3,3]
 x[1,4]
 x[2,4]
 x[3,4]
 x[1,5]
 x[2,5]
 x[3,5]
 x[1,6]
 x[2,6]
 x[3,6]

However, instead of trying to set the starting value as a single vector, set the
starting value using the original structure of the variable. For example, do:

model = Model();
@variable(model, x[t in 1:T, i in 1:6], start = (2 * t + i))

or

model = Model();
@variable(model, x[t in 1:T, i in 1:6])
x_start = rand(T, 6)
set_start_value.(x, x_start)
1 Like