# Order of initial values for set\_start\_value in JuMP/Ipopt models

**URL:** <https://discourse.julialang.org/t/order-of-initial-values-for-set-start-value-in-jump-ipopt-models/125511>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [February 4, 2025, 12:23am UTC](https://discourse.julialang.org/t/order-of-initial-values-for-set-start-value-in-jump-ipopt-models/125511 "2025-02-04T00:23:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![askvorts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/askvorts/32/7120_2.png) [@askvorts](https://discourse.julialang.org/u/askvorts)\
**Post date:** [February 4, 2025, 12:23am UTC](https://discourse.julialang.org/t/order-of-initial-values-for-set-start-value-in-jump-ipopt-models/125511/1 "2025-02-04T00:23:55Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [February 4, 2025, 12:45am UTC](https://discourse.julialang.org/t/order-of-initial-values-for-set-start-value-in-jump-ipopt-models/125511/2 "2025-02-04T00:45:23Z")

</div>

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

See:

```Julia
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:

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

```

or

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

```

---

<div class="post-metadata">

**Author:** ![askvorts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/askvorts/32/7120_2.png) [@askvorts](https://discourse.julialang.org/u/askvorts)\
**Post date:** [February 4, 2025, 12:55am UTC](https://discourse.julialang.org/t/order-of-initial-values-for-set-start-value-in-jump-ipopt-models/125511/3 "2025-02-04T00:55:35Z")

</div>

Wonderfully easy! Thank you so much
