# instance of equality constraint

19 views

### arg...@gmail.com

Jun 26, 2023, 12:54:55 PMJun 26
to Pyomo Forum
I have a generation planning model where there is a generation-demand node balance equality constraint.
For some case studies, some dual variables of these equations are reported as negative because the constraint is formulated as
- sum of generation in the node = - node demand
where usually I would expect to be created as
sum of generation in the node = node demand
Can the way the constraint is created be controlled? Can be detected how has been created?
Thanks in advance for the help
Andrés

### Siirola, John D

Jun 27, 2023, 11:26:48 AMJun 27

Pyomo generally uses (and preserves) whatever expression that you provide.  The one exception is that all variables have to be in the “body” of the constraint.  This means that expressions of the form “f(x) == g(y)” (where x and y are variables) will be converted to “f(x) – g(y) == 0”.  Similar things happen to inequalities (“f(x) <= g(y)” goes to “f(x) – g(y) <= 0” and “f(x) >= g(y)” goes to “g(y) – f(x) <= 0”).  I don’t see how Pyomo would be negating both sides of your constraint.  Can you share the constraint definition that you are using?

John

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.

### Andres Ramos

Jun 28, 2023, 8:17:20 AMJun 28
Hi John,
Here it is the original constraint where the parameter is in the RHS but there are also some variables in the RHS

def eBalance(mTEPES,n,nd):
if sum(1 for g in g2n[nd]) + sum(1 for lout in lout[nd]) + sum(1 for ni,cc in lin[nd]):
return (sum(mTEPES.vTotalOutput[p,sc,n,g] for g in g2n[nd]) - sum(mTEPES.vESSTotalCharge[p,sc,n,es] for es in e2n[nd]) + mTEPES.vENS[p,sc,n,nd] == mTEPES.pDemand[p,sc,n,nd] +
sum(mTEPES.vLineLosses[p,sc,n,nd,lout ] for lout  in loutl[nd]) + sum(mTEPES.vFlow[p,sc,n,nd,lout ] for lout  in lout[nd]) +
sum(mTEPES.vLineLosses[p,sc,n,ni,nd,cc] for ni,cc in linl [nd]) - sum(mTEPES.vFlow[p,sc,n,ni,nd,cc] for ni,cc in lin [nd]))
else:
return Constraint.Skip
setattr(mTEPES, 'eBalance_'+str(p)+'_'+str(sc)+'_'+str(st), Constraint(mTEPES.n, mTEPES.nd, rule=eBalance, doc='load generation balance [GW]'))

and the fixed constraint where only the parameter is in the RHS

def eBalance(OptModel,n,nd):
if sum(1 for g in g2n[nd]) + sum(1 for lout in lout[nd]) + sum(1 for ni,cc in lin[nd]):
return (sum(mTEPES.vTotalOutput[p,sc,n,g] for g in g2n[nd]) - sum(mTEPES.vESSTotalCharge[p,sc,n,es] for es in e2n[nd]) + mTEPES.vENS[p,sc,n,nd] -
sum(mTEPES.vLineLosses[p,sc,n,nd,lout ] for lout  in loutl[nd]) - sum(mTEPES.vFlow[p,sc,n,nd,lout ] for lout  in lout[nd]) -
sum(mTEPES.vLineLosses[p,sc,n,ni,nd,cc] for ni,cc in linl [nd]) + sum(mTEPES.vFlow[p,sc,n,ni,nd,cc] for ni,cc in lin [nd])) == mTEPES.pDemand[p,sc,n,nd]
else:
return Constraint.Skip
setattr(mTEPES, 'eBalance_'+str(p)+'_'+str(sc)+'_'+str(st), Constraint(mTEPES.n, mTEPES.nd, rule=eBalance, doc='load generation balance [GW]'))