Help with Incorporating Battery Charging Behaviour into Model Constraints
ユーザーの入力を待っています。Hello, I am trying to self-teach myself how to solve linear programming problems for but i am stuck despite going through some of the beginners' resources here.
My problem is simple. Given a known table of ToU Tariff Prices and initial State of Charge of BEVs to be charged, find the optimal cheapest charging schedule.
I have considered the problem as such:
KNOWN PARAMETERS:
#define min & maxSoC which will later be used as constraints
minSoC = 0.1
maxSoC = 0.9
chargePower=11 #rate charging power of EV j, in kW
chargeEfficiency = 0.95
ratedBatteryCap=77.4 #rated battery capacity, in kWh
timeDur = 1 #length of time interval in h to account for each hourly timeslot
enterSoC = [0.1,0.2,0.3]
#Set of possible time intervals i
time_intervalStart = ['1800','1900','2000','2100','2200','2300','0000','0100','0200','0300','0400','0500','0600']
#Dictionary of ToU tariffs
touTariff = {'1800':52.998,
'1900':52.998 ,
'2000':21.78,
'2100':21.78,
'2200':13.717,
'2300':13.717,
'0000':13.717,
'0100':13.717,
'0200':13.717,
'0300':13.717,
'0400':13.717,
'0500':13.717,
'0600':13.717}
DECISION VARIABLE
There is only one binary decision variable (schedule) that captures charging decision within every hourly interval of the optimal charging schedule. There should be one such decision variable (schedule) for each incoming EV.
for a in range(len(enterSoC)):
schedule = m.addVars(time_intervalStart,vtype=GRB.BINARY, name = "schedule_%d"%(a+1)) #decision if interval is included in schedule
CONSTRAINTS
For simplicity, I considered the battery being charged at a constant rate of 11kW, and so State of Charge (SoC) increases by a constant value 11kWh in each hour. I would use the following code if I were coding in pure Python.
incrementSoC=chargePower*chargeEfficiency*timeDur/ratedBatteryCap
chargePeriod=0
enterSoC = [0.1,0.15,0.2,0.25,0.3]
#OUTER LOOP: Generates each EV's schedule placeholder
SoC=[]
for i in enterSoC:
holderSoC=i
#INNER LOOP: Generates hourly SoC
jthEV =[]
for i in time_intervalStart:
r = holderSoC +incrementSoC*chargePeriod #how to *schedule[i] ?
#CONDITION: if schedule[i] = 1, perform the following chargePeriod+1 step
chargePeriod = chargePeriod+1
jthEV.append(r)
chargePeriod=0
SoC.append(jthEV)
However, I am unsure of how to calculate these hourly changes in SoC through Gurobi, while also incorporating the decision variable?
Ignoring the hourly charging decisions for the moment, "r = holderSoC +incrementSoC*chargePeriod" is the linear expression that models the charging behaviour. Using time_intervalStart as the list of keys, I tried to use getVars to create a holderSoC equivalent variable, but I'm not sure if that was the right approach? Should I use an iterable list or np.array to update the hourly values instead? Again, each EV should have it's own SoC table. I also wanted to initialise the SoC table of each EV using the enterSoC data, but I couldn't get that to work either.
for a in enterSoC:
updatedSoC = m.addVars(time_intervalStart,lb=minSoC, ub=maxSoC, vtype=GRB.CONTINUOUS, name="updatedSoC_%d"%(a+1))
I don't have any other constraints defined because, aside from the lower and upper bounds, I don't know what they are..? I suppose I'd want my SoC at "0600" to be max ie close to maxSoC=0.9, does that mean I need a second objective function? Or can this be expressed via constraints? As it stands now, the only constraint i have defined is based off of a manual calculation I did to try to create an estimate.
m.addConstr(sum(schedule[i]*touTariff[i] for i in time_intervalStart) <= 176.99)
m.addConstr(sum(schedule[i]*touTariff[i] for i in time_intervalStart) >= 68.585)
OBJECTIVE
I want to minimise the cost of charging;
minCost = sum(schedule[i]*touTariff[i] for i in time_intervalStart)
m.setObjective(minCost,GRB.MINIMIZE)
m.optimize()
My biggest issue is that I don't know how to appropriately come up with the constraints for an optimisation problem so if anyone could help set me on the right path, that would be great.
-
You have to define this part
r = holderSoC +incrementSoC*chargePeriod #how to *schedule[i] ?
#CONDITION: if schedule[i] = 1, perform the following chargePeriod+1 step
chargePeriod = chargePeriod+1through a mathematical formulation, i.e., every relationship has to be defined by an (in)equality constraint. However, it is not really clear to me what you are trying to express.
Do you want to construct a relationship similar to
r = holderSoC +incrementSoC*schedule[i]
? I don't think that you need the chargePeriod variable because the \(\texttt{i}\) index of your schedule variable already gives you the chargePeriod value. If you really need conditional statements, then you can formulate them as discussed in the Knowledge Base article How do I model conditional statements in Gurobi? or directly through indicator constraints.
I would recommend having a look at some mathematical modeling tutorials. Maybe our webinar on Advanced Modelling is helpful here.
0
サインインしてコメントを残してください。
コメント
1件のコメント