Pyomo:努力获得工作上的约束 [英] Pyomo: Struggling to get a constraint to work

查看:62
本文介绍了Pyomo:努力获得工作上的约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为电动汽车调度建模,以最大程度地减少电费.当然,EV只能在每次插入充电站时进行充电(即,在车辆行驶时无法充电).基本上,它是一块固定电池,可以断开并重新连接.

I am trying to model an Electric Vehicle scheduling to minimise the electricity bill. Of course, the EV will only be able to charge every time that is plugged into a charging station (i.e. it cannnot charge when the vehicle is driving). Basically, it is a stationary battery that can be disconnected and connected again.

我之前已经设法建立了固定电池调度模型,并且可以按预期工作,但是我很难设置一个约束来连接和断开电池.

I already managed to model a stationary battery scheduling before and is working good as I expected, however I am having a hard time setting up a constraint to connect and disconnect the battery.

在某些时间段内,我正在使用车辆的数据集被插入,并且我正在使用像这样的字典 availDict = dict(enumerate(df [avail]))一天中不同时间的值 1 =已插入 0 =未插入.例如,假设在不开车时堵车,那么从早上7点到早上9点就不堵车,从早上9点到下午6点就堵车了,因为早上不堵车,从早上6点到晚上8点堵车了.车辆正在行驶,并且由于车辆未行驶而从晚上8点至早上7点被堵住.

In the dataset that I am using the vehicle is plugged in at certain periods of time, and I am using a dictionary like this availDict = dict(enumerate(df[avail])) that contains values 1 = plugged and 0 = not plugged at different times of the day. For example, assuming that when the vehicle is plugged when is not driving then, from 7am to 9am is not plugged as the vehicle is driving, from 9am to 6pm is plugged as the vehicle is not driving, from 6pm to 8pm is not plugged as the vehicle is driving and from 8pm to 7am is plugged as the vehicle is not driving.

此刻,我试图将约束建模为一个布尔值,如下所示:

At the moment I have tried to model the constraint as a boolean like this:

model.avail_bool = en.Var(model.Time, within=en.Boolean, initialize=1)

model.not_avail_bool = en.Var(model.Time, within=en.Boolean)

我当时在考虑使用BigM强制模型限制车辆充电,但是我很难设置它.

I was thinking to use BigM to force the model to constraint the vehicle from charging during that time, but I am having a hard time to set this up.

为进一步解释,这是我试图在论文中建模的方程式:

For further explanation, this are the equations that I am trying to model that I found in a paper:

SOCmin(t) <= SOC(t) <= SOCmax(t)

if avail = 0 (not plugged)

SOCmin(t) = SOCmax(t) = 0

if avail = 1 (plugged) but idle

SOCmin(t) = 0 and SOCmax(t) = SOC

if avail = 1 (plugged) and needed by time (t)

SOCmin(t) = SOCmax(t) = SOC

希望我能正确解释我的问题,并希望您能够理解我的意思.

I hope that I explained my problem properly and hopefully you are able to undertstand what I meant.

如果还有其他建议或您需要更多信息,请告诉我,以便我尽快提供.

If there is another suggestion or you need more information please let me know so I can provide it as soon as possible.

推荐答案

DVRJ大家好,欢迎来到stackoverflow,

Hi DVRJ and welcome to stackoverflow,

这更多是关于问题的数学公式的问题,而不是Python/Pyomo问题,但我想我可以帮忙.

This is more a question of a problem's mathematical formulation, rather than a Python/Pyomo problem, but I think I can be of help.

首先,术语"avail_bool"和"not_avail_bool"不必是变量,因为您不确定它们的任何内容.取而代之的是,它们可以是参数,这些参数基本上指示EV是否能够在 model.Time 的特定时间步长内进行充电/放电.

First, the terms 'avail_bool' and 'not_avail_bool' do not have to be variables, as you are not deciding anything about them. Instead, they can be parameters, that basically dictate whether the EV is able to charge/discharge in a specific time step of model.Time or not.

因此,我将定义一个布尔参数 avail_bool ,当插入EV时该参数等于1,否则插入0.为此,您可以通过已有的 availDict 字典读取值.

Thus, I would define a single boolean parameter avail_bool, which is equal to 1 when the EV is plugged and 0 when it is not. For this, you can read the values via the availDict dictionary, which you already have.

然后,如果我们将计费变量称为 Qch ,则需要两个约束条件:

Then, if we call the charging variable Qch, you would need two constraints that say:

Qch <= BigM * avail_bool
Qch >= 0

这意味着当 avail_bool 为0时, Qch 项将为0,这意味着无法为EV电池充电.当 avail_bool 为1时, Qch 将采用优化问题所决定的值.

This means that when avail_bool is 0, then the Qch term will be 0, meaning that the EV battery cannot be charged. When avail_bool is 1, then Qch will take the value dictated by the optimization problem.

对于电池的放电变量,您也将需要类似的术语.

You will need similar terms for the discharging variable of the battery too.

希望这会有所帮助!

这篇关于Pyomo:努力获得工作上的约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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