How to include the iteration number of a loop in variable names?

Are you looking for something like:

model = Model()
x = VariableRef[]
for r in 1:4
    x_r = @variable(model, base_name = "x[$r]")
    push!(x, x_r)
end

Docs: Variables · JuMP

1 Like