[JuMP] Get variable name from a model to use on another


#1

On JuMP, I have a model

m = Model()
@variable(m, x[1:2])

By passing m to a function, can I obtain the variable x to define a new model with x?


[JuMP] Creating a Nonlinear Least Squares model
#2

can I obtain the variable x

Yes m[:x].

to define a new model with x?

No. x belongs to the model m.

Do you want to make a variable with the same name? Or bounds? Or indices? If so, just pass the necessary data to build the variable rather than the model and actual variable.


#3

Thanks @odow, but I must clarify. I don’t know which variables the model has, that is, instead of defining x, an user could define only y.

This is related to another problem and the context is clearer there.


#4

Solved in the other post.