Skip to content

Commit

Permalink
<update><func>Duty and Schedule Class
Browse files Browse the repository at this point in the history
  • Loading branch information
QiuziChen committed Jun 17, 2023
1 parent ea42684 commit b7a1d04
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 179 deletions.
57 changes: 30 additions & 27 deletions EVSPModel/DutyClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@
class Duty():

"""
A duty is schedule for a single vehicle which contains information of its vehicle type, trip chain
and charging time assignment.
A duty is schedule for a single vehicle.
It contains information of its vehicle type, trip chain and charging time assignment.
A feasible duty should not violate the energy constraint.
"""

__slots__ = ['K','S','R','vehicleCost','laborCost','chargingCost','totalCost','evsp']
__slots__ = ['K','S','R','vehicleCost','timeCost','chargingCost','totalCost','evsp']


def __init__(self, evsp:EVSP, type=1, tripChain=[], chargingTime={}) -> None:
"""
model: EVSP model storing data of nodes, arcs and params
evsp: EVSP model storing data of nodes, arcs and params
type: vehicle type
tripChain: trip chain, list
chargingTime: charging time assignment, dict
cost: total cost including vehicle, labor and charging cost
"""
self.K = type
self.S = tripChain
self.R = chargingTime
self.vehicleCost = 0
self.laborCost = 0
self.chargingCost = 0
self.totalCost = 0
self.K = type # vehicle type
self.S = tripChain # trip chain
self.R = chargingTime # charging time of charging events in the trip chain
self.vehicleCost = 0 # initial vehicle cost
self.timeCost = 0 # initial time-related cost
self.chargingCost = 0 # initial charging cost
self.totalCost = 0 # initial total cost
self.evsp = evsp

def __deepcopy__(self, memodict={}):
Expand All @@ -52,7 +52,7 @@ def checkEnergyFeasibility(self):
"""
feasibility = True

y = self.evsp.E_k[self.K] # start energy of each node
y = self.evsp.E_k[self.K] # remaining energy at the beginning of each node
for i, s in enumerate(self.S[:-1]):

if s in self.evsp.F:
Expand All @@ -61,28 +61,26 @@ def checkEnergyFeasibility(self):
else:
y = y - self.evsp.e_ki[self.K][s] - self.evsp.e_kij[self.K][(s,self.S[i+1])]

if y < self.evsp.batteryLB * self.evsp.E_k[self.K]: # if battery level less than safe level
if y < self.evsp.batteryLB * self.evsp.E_k[self.K]: # if battery level less than the safe level
feasibility = False
break
return feasibility

def calCost(self):
"""
Calculate cost of a duty.
Calculate the cost of a duty.
"""
self.vehicleCost = 0
self.laborCost = 0
self.vehicleCost = 0 # initialize whenever a new cost calculation procedure is performed
self.timeCost = 0
self.chargingCost = 0
self.totalCost = 0

# veh investemnt cost
self.vehicleCost = self.evsp.c_k[self.K]

# time and charging cost
y = self.evsp.E_k[self.K]
for i,s in enumerate(self.S[:-1]):

# labor cost
self.laborCost += (self.evsp.t_ij[(s, self.S[i+1])] + self.evsp.t_i[s]) * self.evsp.c_t
# time cost
self.timeCost += (self.evsp.t_ij[(s, self.S[i+1])] + self.evsp.t_i[s]) * self.evsp.c_t
if s in self.evsp.F:
# charging cost
chargeVolume = calCharge(self.evsp, self.K, y)
Expand All @@ -92,11 +90,16 @@ def calCost(self):
y = y - self.evsp.e_ki[self.K][s] - self.evsp.e_kij[self.K][(s,self.S[i+1])]

# charged to full after daily operation
self.chargingCost += (self.evsp.E_k[self.K] - y) * max(self.evsp.c_e.values())
self.chargingCost += (self.evsp.E_k[self.K] - y) * min(self.evsp.c_e.values())

if self.evsp.calLaborCost == True:
self.totalCost = self.vehicleCost + self.laborCost + self.chargingCost
else:
self.totalCost = self.vehicleCost + self.chargingCost # self.laborCost +
# vehicle cost
if self.evsp.calVehCost == True:
self.vehicleCost = self.evsp.c_k[self.K]
if self.evsp.calTimeCost == False:
self.timeCost == 0
if self.evsp.calElecCost == False:
self.chargingCost = 0

self.totalCost = self.vehicleCost + self.timeCost + self.chargingCost

return self.totalCost
14 changes: 7 additions & 7 deletions EVSPModel/EVSPClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def __init__(
timetable: DataFrame with columns=['ID','Route','StartTime','StartTimeMin','TravelTimeMin','Consumption']
[operating param]
batteryLB: [operating param] lower bound of battery level, default=0.2
batteryUB: [operating param] upper bound of battery level, default=1.0
stationCap: [operating param] charging station capacity, default=-1 means capacity constraints are not considered
delta: [operating param] minimum time interval, default=10(min)
U: [operating param] number of delta in a fixed charging duration, default=3 (delta=10, U=3 means the fixed charging duration=30min)
lineChange: [operating param] whether line change activities are allowed for BEBs, default=True
batteryLB: lower bound of battery level, default=0.2
batteryUB: upper bound of battery level, default=1.0
stationCap: charging station capacity, default=-1 means capacity constraints are not considered
delta: minimum time interval, default=10(min)
U: number of delta in a fixed charging duration, default=3 (delta=10, U=3 means the fixed charging duration=30min)
lineChange: whether line change activities are allowed for BEBs, default=True
"""

self.timetable = timetable
Expand Down Expand Up @@ -96,7 +96,7 @@ def setCosts(
if calVehCost or calElecCost or calElecCost:
self.calVehCost = calVehCost
self.calElecCost = calElecCost
self.calLaborCost = calTimeCost
self.calTimeCost = calTimeCost
else:
raise ValueError("At least one cost item should be considered.")

Expand Down
Loading

0 comments on commit b7a1d04

Please sign in to comment.