Order of initial values for set_start_value in JuMP/Ipopt models

I am optimizing a model in Jump with IPOPT. The model has T x 6 variables: a1_t, a2_t...a6_t with t = 1...T When defining initial values using the function,

set_start_value.(all_variables(model), initial_values)

The expected sequence of elements in the initial_values vector should be:

a1_1, a1_2, a1_3,…, a2_1, a2_2,…

or otherwise (which would be unexpected)?

a1_1, a2_1, a3_1,…, a_12, a_22,…

The model minimises a least-squares sum in t. Also, possibly, it would better to use set_start_values instead? Could not find any advise about this in the documentation for JuMP. Thank you!

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

Wonderfully easy! Thank you so much

1 Like