问题
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.
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)
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.
回答1:
Hi DVRJ and welcome to stackoverflow,
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.
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.
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.
Then, if we call the charging variable Qch
, you would need two constraints that say:
Qch <= BigM * avail_bool
Qch >= 0
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.
Hope this is helpful!
来源:https://stackoverflow.com/questions/62406319/pyomo-struggling-to-get-a-constraint-to-work