ERROR: evaluating object as numeric value: p_in[0]
(object: <class 'pyomo.core.base.var._GeneralVarData'>)
No value for uninitialized NumericValue object p_in[0]
ERROR: evaluating object as numeric value: 0.0 < p_in[0]
(object: <class 'pyomo.core.expr.expr_pyomo5.InequalityExpression'>)
No value for uninitialized NumericValue object p_in[0]
ERROR: Rule failed when generating expression for constraint p_out_test with
index 0: ValueError: No value for uninitialized NumericValue object
p_in[0]
ERROR: Constructing component 'p_out_test' from data=None failed: ValueError:
No value for uninitialized NumericValue object p_in[0]ValueError: No value for uninitialized NumericValue object p_in[0]Or is there another way of implementing this in my model?
Thanks in advance!
Best, Patriek
m.p = Var(m.time, doc='energy derivative with respect to time', initialize=0)
m.pd = Var(m.time, doc='discharging power', within=NonNegativeReals, initialize=0)
m.pc = Var(m.time, doc='charging power', within=NonNegativeReals, initialize=0)
m.u = Var(m.time, doc='binary variable', within=Binary, initialize=0)
m.pcmax = Param(default=UB, doc='maximal charging power', mutable=True, within=PositiveReals)
m.pdmax = Param(default=UB, doc='maximal discharging power', mutable=True, within=PositiveReals)
def _p_balance(b, t):
return b.p[t] - b.pd[t] + b.pc[t] == 0
def _pdmax(b, t):
return b.pd[t] - b.u[t] * b.pdmax <= 0
def _pcmax(b, t):
return b.pc[t] + b.u[t] * b.pcmax <= b.pcmax
m._pdmax = Constraint(m.time, rule=_pdmax, doc='Discharging power bound')
m._pcmax = Constraint(m.time, rule=_pcmax, doc='Charging power bound')
m._p_balance = Constraint(m.time, rule=_p_balance, doc='Power balance constraint')
The main idea of this formulation is to use one binary variable 'u' (indexed by the time set) that will describe your conditions (if pd > 0, u = 1 and if pc > 0, u = 0).
You will have to define some efficiency (charging and discharging) and also write a proper energy balance equation. Depending on those value, one could get rid of this binary value. But this is compulsory for the general case.
Good luck !
Vincent
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyomo-forum/0298079a-a5ff-4862-9798-b013b201c9cc%40googlegroups.com.
m.p = Var(m.time, doc='energy derivative with respect to time', initialize=0)
m.pd = Var(m.time, doc='discharging power', within=NonNegativeReals, initialize=0)
m.pc = Var(m.time, doc='charging power', within=NonNegativeReals, initialize=0)
m.u = Var(m.time, doc='binary variable', within=Binary, initialize=0)
m.pcmax = Param(default=UB, doc='maximal charging power', mutable=True, within=PositiveReals)
m.pdmax = Param(default=UB, doc='maximal discharging power', mutable=True, within=PositiveReals)
def _p_balance(b, t):
return b.p[t] - b.pd[t] + b.pc[t] == 0
def _pdmax(b, t):
return b.pd[t] - b.u[t] * b.pdmax <= 0
def _pcmax(b, t):
return b.pc[t] + b.u[t] * b.pcmax <= b.pcmax
m._pdmax = Constraint(m.time, rule=_pdmax, doc='Discharging power bound')
m._pcmax = Constraint(m.time, rule=_pcmax, doc='Charging power bound')
m._p_balance = Constraint(m.time, rule=_p_balance, doc='Power balance constraint')
Take a minute to think about those inequality, to be sure it is suits your needs.
I suppose that, you want to go further and write a proper energy equality constraint, taking into account charging and discharging efficiencies. For that purpose,
you will need to define, the energy in the battery (as a variable), the efficiencies (as a Param), initial and final energies (as Params), such as:
m.e = Var(m.time, doc='energy in battery', initialize=0)
m.emin = Param(default=0, doc='minimum energy (kWh)', mutable=True, within=NonNegativeReals)
m.emax = Param(default=10000, doc='maximal energy (kWh)', mutable=True)
m.e0 = Param(default=None, doc='initial state', mutable=True)
m.ef = Param(default=None, doc='final state', mutable=True)
m.etac = Param(default=1.0, doc='charging efficiency', mutable=True)
m.etad = Param(default=1.0, doc='discharging efficiency', mutable=True)
def _e_balance(m, t):
if not (m.etac.value and m.etad.value == 1.):
return m.de[t] == 1 / 3600 * (m.pc[t] * m.etac - m.pd[t] / m.etad)
else:
return m.de[t] == 1 / 3600 * (m.pc[t] - m.pd[t])
def _e_initial(m, t):
if m.e0.value is not None:
if t == 0:
return m.e[t] == m.e0
return Constraint.Skip
def _e_final(m, t):
if m.ef.value is None:
return Constraint.Skip
if t == m.time.last():
return m.e[t] == m.ef
else:
return Constraint.Skip
def _e_min(m, t):
if m.emin.value is None:
return Constraint.Skip
return m.e[t] >= m.emin
def _e_max(m, t):
if m.emax.value is None:
return Constraint.Skip
return m.e[t] <= m.emax
m._e_balance = Constraint(m.time, rule=_energy_balance, doc='Energy balance constraint')
m._e_initial = Constraint(m.time, rule=_e_initial, doc='Initial energy constraint')
m._e_final = Constraint(m.time, rule=_e_final, doc='Final stored energy constraint')
m._e_min = Constraint(m.time, rule=_e_min, doc='Minimal energy constraint')
m._e_max = Constraint(m.time, rule=_e_max, doc='Maximal energy constraint')
Hi Vincent,I am trying this with a binary constraint but it is not working. I don’t understand your explanation. Can you explain?model.P = Var(T, within = Binary)M = 10000000def p_batt1(model,t):return model.p_out[t] - model.p_in[t] <= M*(1-model.P[t])model.p_batt1 = Constraint(T, rule=p_batt1, doc = 'Testje1')def p_batt2(model,t):return model.p_in[t] - model.p_out[t] <= M*model.P[t]model.p_batt2 = Constraint(T, rule=p_batt2, doc = 'Testje2')def p_batt3(model,t):return eta == eta_in*model.P[t] + eta_out*(1-model.P[t])model.p_batt3 = Constraint(T, rule=p_batt3, doc = 'Testje3')
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyomo-forum/505eabdd-13eb-4ad4-a954-a215a627171f%40googlegroups.com.
I would replace the constraint 'p_batt1', 'p_batt2', 'p_batt3', 'p_in_max' and 'p_out_max' by the one I gave you (m._pdmax ,m._pcmax). Also soc_rule does not seem homogeneous to me, soc is usually normalized (between 0 and 100 %).
Vincent
Hi Vincent,
To view this discussion on the web visit https://groups.google.com/d/msgid/pyomo-forum/505eabdd-13eb-4ad4-a954-a215a627171f%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyomo-forum/54af3401-0588-4bdf-9f66-279a98ecd130n%40googlegroups.com.