【问题标题】:CVXOPT solar + battery w/ price charge/discharge optimization glpkCVXOPT 太阳能 + 电池,带价格充电/放电优化 glpk
【发布时间】:2020-03-05 23:26:31
【问题描述】:

我有以下 df。电池只能从太阳能充电,并且更喜欢使用减少/免费的太阳能,因为这对可以离开系统的电量设置了新的限制。我很难用 cvxopt 将模型拆分为电池的 energy_in 和 energy_out。任何帮助都非常感谢。

'''
 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']

mw_in 和 mw_out 不能同时发生。如何添加此约束? 抱歉,我不知道如何在此处添加 df 本身。 谢谢!!

【问题讨论】:

    标签: python optimization linear-programming glpk cvxopt


    【解决方案1】:

    条件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 的特殊有序集)变量,可以提供帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-15
      • 1970-01-01
      • 2014-06-28
      • 2011-01-04
      • 2011-07-29
      • 2019-03-15
      • 2018-12-27
      • 1970-01-01
      相关资源
      最近更新 更多