私はpyomoが初めてです。単純な最大化問題を実行しようとしていますが、次のエラー メッセージが表示され続けます: Error retrieving component Pd[1]: The component has not been constructed.
. 最後の 5 つの制約のみがこの問題を引き起こします。最初の 3 つの制約は正常に機能します。IPythonコンソールでこのコマンドを使用して実行しています!pyomo --solver-manager=neos --solver=cbc battpyomo.py battpyomo.dat
データ ファイルでは、セット T とパラメーター p のみを定義します。
セット T := 1 2 3 4 5 6 7 8 9;
パラメータ: p :=
1 51.12
2
48.79 3 39.56
4 36.27
5 36.16
6 34.90
7 33.33
8 21.16
9 24.42;
以下は、battbyomo.py のコードです。
from pyomo.environ import *
model = AbstractModel()
########Sets#########
#Hours
model.T = Set()
#########Parameters##########
#Price
model.p = Param(model.T,within=PositiveReals)
#Variable OM cost Discharge
model.VOMd = Param(initialize=15)
#Varaible OM cost Charge
model.VOMc = Param(initialize=10)
#State of Charge min
model.SOCmin = Param(initialize=5)
#State of charge max
model.SOCmax = Param(initialize=25)
#ESS efficiency
model.m = Param(initialize=0.99)
#Max discharge rate
model.Pdmax = Param(initialize=20)
#Max charge rate
model.Pcmax = Param(initialize=20)
#Initial State of Charge
model.SOCini = Param(initialize=25)
###########Variables##########
#Power discharged
model.Pd = Var(model.T, within=NonNegativeIntegers)
#Power charged
model.Pc= Var(model.T, within=NonNegativeIntegers)
#Charging Status
model.Uc = Var(model.T, within=NonNegativeIntegers)
#Discharging status
model.Ud = Var(model.T, within=NonNegativeIntegers)
#State of Charge
model.SOC = Var(model.T, within=NonNegativeIntegers)
#######Objective##########
def profit_rule(model):
return sum(model.Pd[i]*model.p[i]-model.Pd[i]*model.VOMd-model.Pc[i]*model.p[i]-model.Pc[i]*model.VOMc for i in model.T)
model.profit = Objective(rule=profit_rule, sense = maximize)
#######Constraints##########
def status_rule(model,i):
return (model.Ud[i] + model.Uc[i] <= 1)
model.status = Constraint(model.T,rule=status_rule)
def Cmax_rule(model,i):
return model.Pc[i] <= model.Pcmax*model.Uc[i]
model.Cmax = Constraint(model.T,rule=Cmax_rule)
def Dmax_rule(model,i):
return model.Pd[i] <= model.Pdmax*model.Ud[i]
model.Dmax = Constraint(model.T,rule=Dmax_rule)
def Dlim_rule(module,i):
return model.Pd[i] <= model.SOC[i] - model.SOCmin
model.Dlim = Constraint(model.T,rule=Dlim_rule)
def Clim_rule(module,i):
return model.Pc[i] <= model.SOCmax-model.SOC[i]
model.Clim = Constraint(model.T,rule=Clim_rule)
def Smin_rule(module,i):
return model.SOC[i] >= model.SOCmin
model.Smin = Constraint(model.T,rule=Smin_rule)
def Smax_rule(module,i):
return model.SOC[i] <= model.SOCmax
model.Smax = Constraint(model.T,rule=Smax_rule)
def E_rule(module,i):
if i == 1:
return model.SOC[i] == model.SOCini + model.Pc[i]*model.m -model.Pd[i]
else:
return model.SOC[i] == model.SOC[i-1] + model.Pc[i]*model.m - model.Pd[i]
model.E = Constraint(model.T,rule=E_rule)