I am working under pyomo.environ package. I tried to adding a constraint something like this https://i.stack.imgur.com/r1Smc.jpg. i and j are the index of nodes.
The node_set contains N0 to N5, six nodes in total. Arc_set is a set that store the links between nodes, say, [N1, N2], and it doesn't not contain any self loop arc, say, [N1, N1]. F set contains [F1, F2, F3]
So, I did something like this:
def c1_rule(m, j):
return sum(m.X[e[0], j, f] for e in m.arc_set if e[1] != 'N0' for f in m.f_set) == 1
m.c1_cons = pe.Constraint(m.node_set, rule= c1_rule)
However, I realized that this would trigger errors when my j is equal to i, which is e[0] here, since the index of m.X[i, j, k] doesn't have something like [N1, N1, F1]. I have one idea is that adding self loop arcs to the arc set. Is there any other way I can avoid this error?