Search code examples
pythonpyomoobjective-function

pyomo accuracy; objective rule doesn´t return the expacted value


using pyomo and glpk solver I defind the follwing ojective rule:

def cost_rule(m): 
    return (sum(m.rd[i]*m.pRdImp*m.dt - m.vr[i]*m.pRdExp*m.dt for i in m.t) + m.cb + m.cPV + (150+10*m.kWp) )
m.cost = Objective(rule=cost_rule)

If I know compare the outputs after a minimum was found I get different results:

sum(m.rd[i]()*m.pRdImp()*m.dt() - m.vr[i]()*m.pRdExp()*m.dt() for i in t_t) + m.cPV() + m.cb() + (150+5*m.kWp())
Out[46]: 1136.468

m.cost()
Out[43]: 1173.178

(m.t and t_t are range sets representing the hours of a year) This is an error of around 3 %, any ideas where is could come from? And which value would be the correct one if I would need to choose one.

Thanks in advance!


Solution

  • The expressions are different. The last term in the first one is (150+10*m.kWp) and the last term in the second one is (150+5*m.kWp())