Creating a new variable in JuMP with other variables already existing

See this part of the documentation:

https://jump.dev/JuMP.jl/stable/manual/variables/#variable_names_and_bindings

julia> using JuMP

julia> model = Model();

julia> @variable(model, x[1:2])
2-element Vector{VariableRef}:
 x[1]
 x[2]

julia> for i in (length(x)+1):4
           push!(x, @variable(model, base_name = "x[$i]"))
       end

julia> x
4-element Vector{VariableRef}:
 x[1]
 x[2]
 x[3]
 x[4]
4 Likes