# Variable start values from Dict

**URL:** https://discourse.julialang.org/t/variable-start-values-from-dict/124650
**Category:** Optimization (Mathematical)
**Created:** [January 10, 2025, 5:27pm UTC](https://discourse.julialang.org/t/variable-start-values-from-dict/124650 "2025-01-10T17:27:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![maxminn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxminn/32/214592_2.png) [@maxminn](https://discourse.julialang.org/u/maxminn)
#### Post date: [January 10, 2025, 5:27pm UTC](https://discourse.julialang.org/t/variable-start-values-from-dict/124650/1 "2025-01-10T17:27:32Z")

</div>

I want to initialize a variable that is indexed by sets of strings to a dictionary with keys that are tuples of those same sets

```Julia
A = ["cat","dog"]
R = ["E" , "W"]
X0 = Dict(
    ("cat","E") => 1.1,
    ("cat","W") => 1.2,
    ("dog","E") => 1.3,
    ("dog","W") => 1.4
)

m1 = Model()

@variable(m1, X[A,R], start = X0)

```

Gives: ERROR: Unable to use `Dict...` as the start value of a variable because it is not convertable to type `::Float64`.

If I convert to an array …

```Julia
nA = length(A)
nR = length(R)
X00 = zeros(2,2)
for i in 1:nA
    for j in 1:nR
        X00[i,j] = X0[A[i],R[j]]
    end
end

@variable(m1, X[A,R], start = X00)
@variable(m1, X[A,R], start = X00[i,j] for i in 1:nA for j in 1:nR)

```

Gives: ERROR: Passing arrays as variable starts without indexing them is not supported.  
And : ERROR: Unrecognized positional arguments…  
respectively.

Any thoughts on the best way to do this?

---

<div class="post-metadata">

### Author: ![maxminn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxminn/32/214592_2.png) [@maxminn](https://discourse.julialang.org/u/maxminn)
#### Post date: [January 10, 2025, 7:27pm UTC](https://discourse.julialang.org/t/variable-start-values-from-dict/124650/2 "2025-01-10T19:27:40Z")

</div>

Ok, I figured this out. You can use the Dict directly. Here’s what worked:

```Julia
A = ["cat","dog"]
R = ["E" , "W"]
X0 = Dict(
       ("cat","E") => 1.1,
       ("cat","W") => 1.2,
       ("dog","E") => 1.3,
       ("dog","W") => 1.4
)

m1 = Model()

@variable(m1, X[i = A,j = R], start = X0[i,j])

```

Thank you for the interest.

---

<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: [January 10, 2025, 7:31pm UTC](https://discourse.julialang.org/t/variable-start-values-from-dict/124650/3 "2025-01-10T19:31:07Z")

</div>

You beat me to replying 😄 Yes, using indices is the correct way to solve this problem.
