# How to create a huge set of variables (500k or more) in JUMP

**URL:** <https://discourse.julialang.org/t/how-to-create-a-huge-set-of-variables-500k-or-more-in-jump/10325>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [April 13, 2018, 12:36pm UTC](https://discourse.julialang.org/t/how-to-create-a-huge-set-of-variables-500k-or-more-in-jump/10325 "2018-04-13T12:36:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayce\_ram](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jayce_ram/32/3977_2.png) [@jayce\_ram](https://discourse.julialang.org/u/jayce_ram)\
**Post date:** [April 13, 2018, 12:36pm UTC](https://discourse.julialang.org/t/how-to-create-a-huge-set-of-variables-500k-or-more-in-jump/10325/1 "2018-04-13T12:36:51Z")

</div>

Hello everybody, I’m completely new in Jump and I have a very large LP to solve. The number of variables depend of the input data. My variables are too nested, for example, for each given installation, there’s an associated technology( solar, wind), a region, and a period of time. I have already read about how to set variables, but I cannot really see how I can do it in my problem. If I use the sintaxe bellow, that’s not seems too readable… Anyone could give me a direction? Thanks in advance.  
@variable  
(m, x[1:M,1:N] \>= 0 )

---

<div class="post-metadata">

**Author:** ![joaquimg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joaquimg/32/223_2.png) [@joaquimg](https://discourse.julialang.org/u/joaquimg)\
**Post date:** [April 13, 2018, 4:45pm UTC](https://discourse.julialang.org/t/how-to-create-a-huge-set-of-variables-500k-or-more-in-jump/10325/2 "2018-04-13T16:45:34Z")

</div>

I am not sure I understand you question, what do you want exactly?

You want to define variables with different names?

You can write LaTex between “$” signs. If its better to explain what you consider readable.

---

<div class="post-metadata">

**Author:** ![joaquimg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joaquimg/32/223_2.png) [@joaquimg](https://discourse.julialang.org/u/joaquimg)\
**Post date:** [April 13, 2018, 4:51pm UTC](https://discourse.julialang.org/t/how-to-create-a-huge-set-of-variables-500k-or-more-in-jump/10325/3 "2018-04-13T16:51:29Z")

</div>

Also, for JuMP questions it better to set the category to Domains \> Oprimization (Mathematical)

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [April 13, 2018, 5:32pm UTC](https://discourse.julialang.org/t/how-to-create-a-huge-set-of-variables-500k-or-more-in-jump/10325/4 "2018-04-13T17:32:19Z")

</div>

> [@jayce\_ram](#):
>
> If I use the sintaxe bellow, that’s not seems too readable…

I’m not sure what you mean by this. I have to do problems like this all the time as well, and my primary method of declaring variables is with `@variable` just as you’ve shown.

I also frequently have to use sparse matrices as is probably common for people working on problems of this size. Fortunately, there is nothing stopping you from declaring scalar variables and populating sparse matrices with these in any way that you would populate sparse matrices with any other objects see [here](https://docs.julialang.org/en/latest/stdlib/SparseArrays/).

---

<div class="post-metadata">

**Author:** ![bbrunaud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bbrunaud/32/1737_2.png) [@bbrunaud](https://discourse.julialang.org/u/bbrunaud)\
**Post date:** [April 15, 2018, 5:26am UTC](https://discourse.julialang.org/t/how-to-create-a-huge-set-of-variables-500k-or-more-in-jump/10325/5 "2018-04-15T05:26:45Z")

</div>

For the record. I’ve create models with a million variables in JuMP, and it wasn’t a problem.

But, like @ExpandingMan said, maybe some of those variables don’t even need to be defined. My approach is to created dictionaries beforehand and use them when creating the variables.

For example

```julia
@variable(m, w[i in n.units, j in n.tasks[i], t in timeperiods], Bin)

```

as opposed to

```julia
@variable(m, w[i in n.units, j in n.tasks, t in timeperiods], Bin)

```

Here, I’m creating the `w` variable only for the tasks that are actually performed by unit i, and not by every element in the cross product `units x tasks`

cheers!
