Skip to content

Commit

Permalink
<fix><func>delete batteryUB
Browse files Browse the repository at this point in the history
  • Loading branch information
QiuziChen committed Aug 9, 2023
1 parent 3a87bad commit e5dfa77
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 32 deletions.
2 changes: 1 addition & 1 deletion EVSPModel/Calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def calCharge(evsp:EVSP, k, y0):
"""
Calculate charging volume of one recharging activity.
"""
if evsp.nonlinear_charge == False:
if evsp.chargingFuncType == 'linear':
return min(evsp.E_k[k] - y0, evsp.v_k[k] * evsp.U * evsp.delta)
else:
E = evsp.E_k[k]
Expand Down
2 changes: 1 addition & 1 deletion EVSPModel/DutyClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def calCost(self):

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

# vehicle cost
if self.evsp.calVehCost == True:
self.vehicleCost = self.evsp.c_k[self.K]
Expand Down
32 changes: 18 additions & 14 deletions EVSPModel/EVSPClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ def __init__(
self,
timetable:pd.DataFrame,
batteryLB=0.2, # vehicle param, lower bound of battery level
batteryUB=1.0, # vehicle param, upper bound of battery level
# batteryUB=1.0, # vehicle param, upper bound of battery level
stationCap=-1, # model param, charging station capacity
delta=10, # operating param, minimum time interval / min
U=3, # operating param, number of delta in a fixed charging duration
lineChange=True, # operating param, whether line change activities are allowed for BEBs
nightCharge=False, # night charging mode
):
"""
[timetable]
Expand All @@ -35,16 +36,17 @@ def __init__(
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
nightCharge: whether night charging mode is adopted
"""

self.timetable = timetable
self.stationCap = stationCap
self.batteryLB = batteryLB
self.batteryUB = batteryUB
# self.batteryUB = batteryUB
self.delta = delta
self.U = U
self.lineChange = lineChange

self.nightCharge = nightCharge

def setVehTypes(
self,
Expand Down Expand Up @@ -156,11 +158,11 @@ def plotChargingFunc(self):
ax.set_ylabel("SOC", weight="bold")
ax.grid(linestyle=':')

for k in evsp.K:
E = evsp.E_k[k] # kWh
for k in self.K:
E = self.E_k[k] # kWh
y = np.array([0, 100])
x = y / 100 * E / evsp.v_k[k]
ax.plot(x, y, label="Veh Type: %d(%.1f kWh)" % (k, evsp.E_k[k]))
x = y / 100 * E / self.v_k[k]
ax.plot(x, y, label="Veh Type: %d(%.1f kWh)" % (k, self.E_k[k]))
ax.scatter(x, y)
ax.text(x[-1], y[-1], "(%d,%d)" % (x[-1], y[-1]), horizontalalignment='center')
plt.legend()
Expand All @@ -172,11 +174,11 @@ def plotChargingFunc(self):
ax.set_ylabel("SOC", weight="bold")
ax.grid(linestyle=':')

for k in evsp.K:
E = evsp.E_k[k] # kWh
x = np.array(evsp.c_kb[k][:-1])
y = np.array(evsp.a_kb[k][:-1]) * 100
ax.plot(x, y, label="Veh Type: %d(%.1f kWh)" % (k, evsp.E_k[k]))
for k in self.K:
E = self.E_k[k] # kWh
x = np.array(self.c_kb[k][:-1])
y = np.array(self.a_kb[k][:-1]) * 100
ax.plot(x, y, label="Veh Type: %d(%.1f kWh)" % (k, self.E_k[k]))
ax.scatter(x, y)
ax.text(x[-1], y[-1], "(%d,%d)" % (x[-1], y[-1]), horizontalalignment='center')
plt.legend()
Expand Down Expand Up @@ -302,6 +304,7 @@ def createModel(self):

# --- cost ---

c_e = self.c_e
self.c_e = {} # unit electricity cost
## time of use
if self.ToU:
Expand All @@ -311,7 +314,7 @@ def createModel(self):
pass
else:
for r in self.R:
self.c_e[r] = self.c_e # /kWh
self.c_e[r] = c_e # /kWh


def printParams(self):
Expand All @@ -322,9 +325,10 @@ def printParams(self):
"Number of Trips:", self.n, "\n",
"Number of Vehicle Types:", self.k_num, "\n",
"Battery Capacity:", self.E_k, "\n",
"Safe Range of Battery Level:", self.batteryLB, self.batteryUB, "\n",
"Lowest Battery Level:", self.batteryLB, "\n",
"Station Capacity:", "not considered" if self.stationCap==-1 else self.stationCap, "\n",
"Allow Line Change:", self.lineChange, "\n",
"Adopt Night Change:", self.nightCharge, "\n",
"Charging Function:", self.chargingFuncType, "\n",
"Time Interval:", self.delta, "\n",
"Fixed Recharging Time:", self.delta*self.U,
Expand Down
34 changes: 18 additions & 16 deletions EVSPModel/ScheduleClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,22 @@ def checkCapacityFeasibility(self):
Return True if the capacity constraints are satisfied, else Flase.
"""
feasibility = True
for r in set(self.R.values()):
num = [] # number of vehicle in the station before r when i is charging
for u in range(self.evsp.U): # 0, 1, 2...
index = int(r[1:])+u # index of r to check capacity, if r=r3, then index=3,4,5...
num_before = 0
for u in range(self.evsp.U):
index_before = index-u # index of r when vehicle is still being charged
if index_before > 0: # considering r1, r2...
num_before += sum(map(('r%d'%(index_before)).__eq__, self.R.values()))
num.append(num_before)
if (max(num) > self.evsp.capacity):
feasibility = False

return feasibility
if self.evsp.stationCap < 0:
return feasibility
else:
for r in set(self.R.values()):
num = [] # number of vehicle in the station before r when i is charging
for u in range(self.evsp.U): # 0, 1, 2...
index = int(r[1:])+u # index of r to check capacity, if r=r3, then index=3,4,5...
num_before = 0
for u in range(self.evsp.U):
index_before = index-u # index of r when vehicle is still being charged
if index_before > 0: # considering r1, r2...
num_before += sum(map(('r%d'%(index_before)).__eq__, self.R.values()))
num.append(num_before)
if (max(num) > self.evsp.stationCap):
feasibility = False
return feasibility


def calCost(self):
Expand All @@ -165,7 +167,7 @@ def calCost(self):
return self.totalCost


def printTable(self):
def printTimetable(self):
"""
Print out a table(DataFrame) of the schedule.
"""
Expand All @@ -179,7 +181,7 @@ def printTable(self):
# --- Plot ---


def displayTimetable(self):
def plotTimetable(self):
"""
Display timetable & schedule in form of Gantt Chart.
"""
Expand Down

0 comments on commit e5dfa77

Please sign in to comment.