JuMP anonymous variables


Hi, I’m trying to call anonymous variables based on the edges that exist in my tree-graph, but I’m getting the error with my first constraint stating that “t doesn’t exist.”
I show only the relevant code below. t is a continuous variable.
Any idea what the issue might be?

all_edges is a 6-element Array{Any,1}:
[1, 2]
[2, 1]
[2, 3]
[3, 2]
[3, 4]
[4, 3]

MMkCPP = Model(solver=GurobiSolver(Threads=2));
U = 2;

for edge in all_edges
    x=@variable(MMkCPP,[edge[1],edge[2],1:U], category = :Bin)
    t=@variable(MMkCPP,[edge[1],edge[2],1:U], lowerbound = 0)

@objective(MMkCPP, Min, z)

for i in Adj_Nodes[ind_basenode]
    for k in 1:U
        @constraint(MMkCPP, z>=t[i,ind_basenode,k]) 


sidenote: when you do for edge in all_edges you reassign t; it’s probably not what you intend if you need the variable later.

Why don’t you make X to be a vector?

Xs = [@variable(MMkCPP,[edge[1],edge[2],1:U], category = :Bin) for edge in all_edges]