微电网电池调度的约束优化 [英] Constrained Optimization of battery scheduling in microgrid

查看:74
本文介绍了微电网电池调度的约束优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定输入,例如电力消耗、太阳能电池板发电量、价格(全部在给定时间 t),我们有一个电池,我们想评估它在任何给定时间应该(放电)/充电多少.问题可以表述如下:

Given inputs such as electricity consumption, generation from solar panel, price, (All at a given time t), we have a battery, and we want to evaluate how much it should (dis)/charge at any given time. The Problem can be formulated as follows:

Pt = t 时刻的电价

Lt = t 时刻的电力消耗

Zt = 时间 t 的电池电量(电池中有多少)

St = 时间 t 太阳能发电机产生的电力

Qt = 时间 t 时的电池电量(dis)/充电量

我们要优化的函数是Ct = Pt *(Lt - St - Qt)

这旨在最大限度地减少购买的电量

This aims to minimise the amount of electricity purchased

具有以下约束:

Lt - St - Qt >= 0(我们的需求必须是非负的)

Qmin <= Qt <= Qmax(在任何给定时间,电池只能在特定值之间(放电)/充电)

Zmin <= Zt <= Zmax.(电池必须在其容量范围内,即不能放电超过电池座,可以充电超过电池容量)

Zt+1 = Zt + Qt+1(这意味着下一个时间步的电池电量等于前一个时间步的电池电量加上从(dis)/充电的量电池)

我遇到的问题是如何在 python (Scipy) 中制定问题,特别是更新电池电量.

The problem I am having how to formulate in python (Scipy) the problem, particularly updating the battery levels.

我知道存在其他图书馆(Pyomo、Pulp),欢迎提供解决方案.

I know other library's (Pyomo, Pulp) exist, solutions in that would be welcome.

推荐答案

你很幸运,Giorgio 的回答激励我学习 pyomo(我主要使用 PULP),所以用你的问题作为一个机会来确保我了解所有接口.我会把它贴在这里,这样我以后可以自己找到它:

You're in luck, I was motivated by Giorgio's answer to learn pyomo (I mostly user PULP), so used your question as a chance to make sure I understood all the interfaces. I'll post it here so I can find it again myself in the future:

import pyomo.environ as pyomo
import numpy as np

# create model
m = pyomo.ConcreteModel()

# Problem DATA
T = 24

Zmin = 0.0
Zmax = 2.0

Qmin = -1.0
Qmax = 1.0

# Generate prices, solar output and load signals
np.random.seed(42)
P = np.random.rand(T)*5.0
S = np.random.rand(T)
L = np.random.rand(T)*2.0

# Indexes
times = range(T)
times_plus_1 = range(T+1)

# Decisions variables
m.Q = pyomo.Var(times, domain=pyomo.Reals)
m.Z = pyomo.Var(times_plus_1, domain=pyomo.NonNegativeReals)

# objective
cost = sum(P[t]*(L[t] - S[t] - m.Q[t]) for t in times)
m.cost = pyomo.Objective(expr = cost, sense=pyomo.minimize)

# constraints
m.cons = pyomo.ConstraintList()
m.cons.add(m.Z[0] == 0.5*(Zmin + Zmax))

for t in times:
    m.cons.add(pyomo.inequality(Qmin, m.Q[t], Qmax))
    m.cons.add(pyomo.inequality(Zmin, m.Z[t], Zmax))
    m.cons.add(m.Z[t+1] == m.Z[t] - m.Q[t])
    m.cons.add(L[t] - S[t] - m.Q[t] >= 0)

# solve
solver = pyomo.SolverFactory('cbc')
solver.solve(m)

# display results
print("Total cost =", m.cost(), ".")

for v in m.component_objects(pyomo.Var, active=True):
    print ("Variable component object",v)
    print ("Type of component object: ", str(type(v))[1:-1]) # Stripping <> for nbconvert
    varobject = getattr(m, str(v))
    print ("Type of object accessed via getattr: ", str(type(varobject))[1:-1])

    for index in varobject:
        print ("   ", index, varobject[index].value)

这篇关于微电网电池调度的约束优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆