# How to register the name of anonymous variable to certain model?

**URL:** https://discourse.julialang.org/t/how-to-register-the-name-of-anonymous-variable-to-certain-model/69273
**Category:** Optimization (Mathematical)
**Tags:** question, jump
**Created:** [October 5, 2021, 11:57pm UTC](https://discourse.julialang.org/t/how-to-register-the-name-of-anonymous-variable-to-certain-model/69273 "2021-10-05T23:57:27Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![iiitr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iiitr/32/24586_2.png) [@iiitr](https://discourse.julialang.org/u/iiitr)
#### Post date: [October 5, 2021, 11:57pm UTC](https://discourse.julialang.org/t/how-to-register-the-name-of-anonymous-variable-to-certain-model/69273/1 "2021-10-05T23:57:27Z")

</div>

Hi all,

I cannot view the anonymous variable in the model, when I use the following method:

```julia
julia> model = Model()
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.

julia> x = @variable(model, [1:2, 1:3])
2×3 Matrix{VariableRef}:
 noname noname noname
 noname noname noname

julia> model
A JuMP Model
Feasibility problem with:
Variables: 6
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.

```

How can I set a name for the anonymous variable so that I can create it in the same way as the following variable creation method.

```julia
julia> model = Model()
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.

julia> @variable(model, x[1:2, 1:3])
2×3 Matrix{VariableRef}:
 x[1,1] x[1,2] x[1,3]
 x[2,1] x[2,2] x[2,3]

julia> model
A JuMP Model
Feasibility problem with:
Variables: 6
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.
Names registered in the model: x

```

I don’t want to add 6 `base_name` to each of the 6 `noname`, but I want to register these 6 anonymous variables with the only one name `x` in the model, as if I didn’t create an anonymous variable in the beginning.

My question does seem strange, but I still want to know if there is such a way to achieve the idea.

Thanks a lot!

---

<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: [October 6, 2021, 3:47am UTC](https://discourse.julialang.org/t/how-to-register-the-name-of-anonymous-variable-to-certain-model/69273/2 "2021-10-06T03:47:49Z")

</div>

It seems there is a bit of confusion because “name” is an overloaded concept:

- Each variable has a string name, accessible via `name(x)`. If `name(x) == ""`, then it get’s printed as `noname`
- You can use `base_name = ` to set a string name for anonymous variables
- JuMP variables (and collections of) can be assigned to Julia variables. We often say that this is a binding between a name and an object. In the assignment `y = 1`, the object `1` is bound to the name `y`.
- Named JuMP variables get bound to the Julia variable of the same name
- Named JuMP variables are registered in the model using the symbol of the same name
- Anonymous variables don’t get registered in the model, and you choose which name it gets bound to
- You can manually register things in the model via `model[:key] = value`

Perhaps this example makes things clearer

```nohighlight
julia> model = Model()
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.

julia> x_binding = @variable(model, [1:2, 1:3], base_name = "x")
2×3 Matrix{VariableRef}:
 x[1,1] x[1,2] x[1,3]
 x[2,1] x[2,2] x[2,3]

julia> model
A JuMP Model
Feasibility problem with:
Variables: 6
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.

julia> x
ERROR: UndefVarError: x not defined

julia> x_binding
2×3 Matrix{VariableRef}:
 x[1,1] x[1,2] x[1,3]
 x[2,1] x[2,2] x[2,3]

julia> model[:x_register] = x_binding
2×3 Matrix{VariableRef}:
 x[1,1] x[1,2] x[1,3]
 x[2,1] x[2,2] x[2,3]

julia> model
A JuMP Model
Feasibility problem with:
Variables: 6
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.
Names registered in the model: x_register

julia> model[:x_register]
2×3 Matrix{VariableRef}:
 x[1,1] x[1,2] x[1,3]
 x[2,1] x[2,2] x[2,3]

julia> model[:x_register] === x_binding
true

julia> x
ERROR: UndefVarError: x not defined

```
