Where:
Var: PG # power generated.
Var P # Power flow through branches
Param: L # load
For example:
Set: B = [[1,2], [2,3], [2,4]] # BRANCHES
Set: N = [1, 2, 3, 4] # NODES
The expected set of constraints is:
PG_[1] - P_[1,2] = L_[1] for [i=1]
PG_[2] + P_[1,2] - P_[2,3] - P_[2,4] = L_[2] for [i=2]
PG_[3] + P_[2,3] = L_[3] for [i=3]
PG_[4] + P_[2,4] = L_[4] for [i=4]
In Python, I tried this:
N = pd.Index(N_,name='N') # N_ = [1,2,3,4]
B = pd.Index(B_, name='B') # B_ = [[1,2], [2,3], [2,4]]
PG = m.add_variables(lower = 0, coords=[N], name=PG)
P = m.add_variables(coords=[B], name='P')
L = xr.DataArray(L, coords=[N], name="L")
P_Balance = m.add_constraints(PG + P.sum(dims=['Linhas']) == L)
unfortunately, P.sum(dims=['Linhas']) includes all the branches.
Any suggestion?
Best regards,
Juan