Flow conservation constraint

Hi there! I’m trying to write a flow conservation constrains. Yet it says key not found

# this is the constraint I'd like to write   (and α(i,j) is a binary variable  and A1 is a subset of nodes)
∑ᵢ α[i,j] = ∑ₖ α[j,k]   ∀ j ∈ A1   # flow conservation on all nodes belong to  A1

using JuMP, CPLEX


m = Model(CPLEX.Optimizer)
A1 = [1,2,5]
Arcs = ((3, 1), (1, 2), (2, 5), (7, 7), (4, 2))

@variable(m, α[i in Arcs]>= 0, Bin)

Do you know why the above is not working? any suggestion to write it the other way?

Hi @Takashy! In order to make it easier to help you, please read the advice below. In particular, a reproducible chunk of code would help clarify your problem and look for solutions!

1 Like

Hi @gdalle Thanks for your advice. I’ve made some change. Basically, there are some arcs in a newtrok and I need to ensure that for a subset of nodes (A1); flow conservation constraints hold.
They require that, for each node in A1, the sum of the flow into the node must be equal to the sum of the flow out of the node.

Something like this?

@constraint(
    model,
    [jj in A1],
    sum(α[(i, j)] for (i, j) in Arcs if j == jj) == sum(α[(j, k)] for (j, k) in Arcs if j == jj),
)
1 Like