# Create variable based on array

**URL:** <https://discourse.julialang.org/t/create-variable-based-on-array/73070>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [December 14, 2021, 11:18am UTC](https://discourse.julialang.org/t/create-variable-based-on-array/73070 "2021-12-14T11:18:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahmad88](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmad88/32/32437_2.png) [@ahmad88](https://discourse.julialang.org/u/ahmad88)\
**Post date:** [December 14, 2021, 11:18am UTC](https://discourse.julialang.org/t/create-variable-based-on-array/73070/1 "2021-12-14T11:18:43Z")

</div>

I have a tuple that contains pairs and I want to create a variable based on these pairs as follows

```julia
E = [(1, 2), (10, 16), (18, 24), (32, 33), (12, 10), (19, 18), (31, 30), (17, 36)]
for (i,j) in E
   @variable(model,x[i,j], binary = true)
end

```

and I got this error message

An object of name x is already attached to this model. If this is intended, consider using the anonymous construction syntax, e.g., x = @variable(model, [1:N], …) where the name of the object does not appear inside the macro.

---

<div class="post-metadata">

**Author:** ![Lilith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lilith/32/27492_2.png) [@Lilith](https://discourse.julialang.org/u/Lilith)\
**Post date:** [December 14, 2021, 4:59pm UTC](https://discourse.julialang.org/t/create-variable-based-on-array/73070/2 "2021-12-14T16:59:43Z")

</div>

Welcome!

It would be easier to reproduce this if you provided a MWE (e.g.)

```julia
using JuMP
model = Model()
E = [(1, 2), (10, 16), (18, 24), (32, 33), (12, 10), (19, 18), (31, 30), (17, 36)]
for (i,j) in E
   @variable(model,x[i,j], binary = true)
end

```

Is this what you are looking for:

```julia
using JuMP
model = Model()
E = [(1, 2), (10, 16), (18, 24), (32, 33), (12, 10), (19, 18), (31, 30), (17, 36)]
@variable(model, x[E], binary = true)
print(model)
#=
Feasibility
Subject to
 x[(1, 2)] binary
 x[(10, 16)] binary
 x[(18, 24)] binary
 x[(32, 33)] binary
 x[(12, 10)] binary
 x[(19, 18)] binary
 x[(31, 30)] binary
 x[(17, 36)] binary
=#

```
