优化的一个电池的存储与pyomo

0

的问题

我目前正在努力优化CO2的排放量的一个househould基于电力消耗。 它也包括电池的存储。 但由于某些原因,国家能源计算的新工作。 我不断收到这个错误:

WARNING: Implicitly replacing the Component attribute soe (type=<class
    'pyomo.core.base.var.IndexedVar'>) on block unknown with a new Component
    (type=<class 'pyomo.core.base.constraint.IndexedConstraint'>). This is
    usually indicative of a modelling error. To avoid this warning, use
    block.del_component() and block.add_component().

Restarting kernel...

这是我的代码迄今为止:

model = ConcreteModel()

n = 30
model.t = RangeSet(1, n)

model.consumption = Param(model.t, initialize = df['Consumption'])
model.pv = Param(model.t, initialize = df['PV'])
model.emissionen = Param(model.t, initialize = df['CO2-Emissions'])
model.heatpump = Param(model.t, initialize = df['Heatpump'])

in_out_leistung = bt.iloc[1]['Values']
in_out_efficiency = bt.iloc[2]['Values']
battery_capacity = bt.iloc[0]['Values'] 
soe_start = 0
elec_import_max = 200

model.soe = Var(model.t, initialize = 0, within = NonNegativeReals)
model.charge = Var(model.t, within = NonNegativeReals, initialize = 0)
model.discharge = Var(model.t, within = NonNegativeReals, initialize = 0)
model.elec_grid = Var(model.t, bounds = (0, elec_import_max), within = NonNegativeReals)

def discharge_capacity_rule(model, t):
    return model.discharge[t] <= in_out_leistung
model.discharge_capacity_rule = Constraint(model.t, rule = discharge_capacity_rule)

def charge_capacity_rule(model, t):
    return model.charge[t] <= in_out_leistung
model.charge_capacity_rule = Constraint(model.t, rule = charge_capacity_rule)
    
def max_capacity_rule(model, t):
    return model.soe[t] <= battery_capacity
model.max_capacity_rule = Constraint(model.t, rule = max_capacity_rule)
    
def soe_start_rule(model):
    return model.soe[1] == soe_start 
model.soe_start_rule = Constraint(rule = soe_start_rule)

def soe(model, t):
    if t == 1:
        return model.soe[t] == soe_start
    else:
        return model.soe[t] == model.soe[t-1] + (model.charge[t] * in_out_efficiency) - model.discharge[t] / in_out_efficiency
model.soe = Constraint(model.t, rule = soe)

def soe_end_rule(model):
    return model.soe[n] == model.soe[1]
model.soe_end_rule = Constraint(rule = soe_end_rule)

def demand(model, t):
    return model.demand[t] == model.heatpump[t] + model.consumption[t] + model.charge[t]
model.demand = Constraint(model.t, rule = demand)

def lastdeckung(model, t):
    return model.pv[t] + model.elec_grid[t] + model.discharge[t] == model.demand[t]
model.lastdeckung = Constraint(model.t, rule = lastdeckung)

def emissionsreduzierung(model, t):
    return sum(model.elec_grid[t] * model.emissionen[t] for t in model.n)
model.emissionsreduzierung = Objective(rule = emissionsreduzierung, sense = minimize)

存储ist应该是空的开始和结束。

optimization pyomo python
2021-11-20 18:35:47
2
1

你正在使用的相同名字的两倍。 你必须 model.soe 作为一个变量,并作为一个制约因素。

你必须重新命名的一个他们作为模式不能有两个名为的对象,用相同的名字...

2021-11-21 00:18:37

我已经改变,但现在它只是说 Restarting kernel... 当我试试运行。
saschav

最好的答案

1

所以我有几个错误在这里和那里。 例如在的目标功能我忘了变化模型。n模型。t因为我重新命名这一过程中编写的代码。 最大的错误想法是忘记创建一个可变的需求。

model.demand = Var(model.t, within = NonNegativeReals)

def demand_rule(model, t):
    return model.demand[t] == model.heatpump[t] + model.consumption[t] + model.charge[t]
model.demand_rule = Constraint(model.t, rule = demand_rule)

现在它的实际工作。

2021-11-27 10:36:56

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................