CVXOPT太阳能电池+带价格充电/放电优化glpk

2024-05-29 11:43:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下几点意见。电池只能从太阳能电池充电,并且更喜欢选择限制/免费的太阳能电池,因为这设置了新的限制可以离开系统的电量。我用cvxopt将模型分解为电池的能量输入和能量输出,这是一段艰难的时间。非常感谢您的帮助。 enter image description here

'''
 GLPK OPTIMIZER BELOW:
'''
df = df[~pd.isnull(df['timestamp'])]
max_dispatch = 110
rte = 0.88 #round trip efficiency (RTE) of the system from PV to Battery to Grid
df['pv'] = pd.to_numeric(df['pv'], errors='coerce').fillna(0.0)
df['pv'] = df['pv']
df['pv_minus_curtail'] = df['pv'] - (df['pv_clip']) # we've addded pv_clip to pv above
df['poi_curtail_limit'] = np.where(df['pv_clip']>0, df['pv_minus_curtail'], max_dispatch )
df['price'] = df['price']
df['is_curtail'] = np.where(df['pv_clip'] > 0, 1, 0)

df['battery_level'] = 0.0
battery_capacity = cp.Parameter(nonneg=True)
battery_capacity.value = 220 / rte
discharge_max = cp.Parameter(nonneg=True)
# for australia data that is in 30min intervals = max for every 30min, so the actual MW is discharge_max*2
discharge_max.value = 55 / rte 
charge_max = cp.Parameter(nonneg=True)
charge_max.value = 55
x_in = cp.Variable(len(df.index))
x_out = cp.Variable(len(df.index))

price = df['price'].values
pv = df['pv'].values
batt_level = cp.cumsum((x_in) + (x_out))

curtail_limit = df['poi_curtail_limit'].values
pv_net_curtail = df['pv_minus_curtail'].values
pv_clip = df['pv_clip'].values
is_curtail = df['is_curtail'].values


constraints = [
    batt_level >= 0.0, # can't have negative battery 
    batt_level <= battery_capacity, # can't go above battery
    x_out >= -1*discharge_max, #don't discharge faster than it can handle it
    x_in <= charge_max, #no charging faster than allowed
    x_in <= pv, # constrained by PV generation
    x_out <= 0,
    x_in >= 0,

]
rev = cp.sum( cp.minimum (pv - x_in - (x_out * rte), curtail_limit) * price)
prob = cp.Problem(cp.Maximize(rev), constraints) # Maximize revenue, conditional on constraints

start_time = time()

prob.solve(solver='GLPK_MI', verbose=True)

df.loc[:,'mw_in'] = x_in.value
df.loc[:,'mw_out'] = x_out.value

df.loc[:,'battery_level'] = np.cumsum(df['mw_in'] + (df['mw_out']))
#df['rev']
# Put things back in data frame for inpsection
#df.loc[:,'charge'] = np.where(np.abs(df['charge']) > 0.001, df['charge']*scale, 0.0)
df.loc[:,'mw_poi'] = df['pv'] - df['mw_in'] - (df['mw_out'] * rte)

df.loc[:,'rev'] = (df['mw_poi']) * df['price']

微波输入和微波输出不能同时发生。如何在中添加此约束? 对不起,我不知道如何在这里添加df本身。 谢谢


Tags: indfclipoutcppricelocmax
1条回答
网友
1楼 · 发布于 2024-05-29 11:43:09

条件x=0 or y=0有时称为互补约束。它也可以写成x*y=0。CVXOPT和GLPK不直接支持此类约束。但是,我们可以使用二进制变量实现此约束

 x ≤ U1 δ
 y ≤ U2 (1-δ)
 x ∈ [0,U1]
 y ∈ [0,U2]
 δ ∈ {0,1}

这里U1(U2)是x(y)上的上界。如果没有好的边界U1、U2,则某些MIP解算器支持所谓的SOS1(类型1的特殊有序集)变量,这会有所帮助

相关问题 更多 >

    热门问题