-
Notifications
You must be signed in to change notification settings - Fork 49
/
Electric_vehicle_simulation.py
32 lines (29 loc) · 1.45 KB
/
Electric_vehicle_simulation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import simpy
from random import seed, randint
seed(23)
class EV:
def __init__(self, env):
self.env = env
self.drive_proc = env.process(self.drive(env))
self.bat_ctrl_proc = env.process(self.bat_ctrl(env))
self.bat_ctrl_reactivate = env.event()
def drive(self, env):
while True:
# Drive for 20-40 min
yield env.timeout(randint(20, 40))
# Park for 1–6 hours
print('Start parking at', env.now)
self.bat_ctrl_reactivate.succeed() # "reactivate"
self.bat_ctrl_reactivate = env.event()
yield env.timeout(randint(60, 360))
print('Stop parking at', env.now)
def bat_ctrl(self, env):
while True:
print('Bat. ctrl. passivating (stop charging) at', env.now)
yield self.bat_ctrl_reactivate # "passivate"
print('Bat. ctrl. reactivated (start Charging) at', env.now)
# Intelligent charging behavior here …
yield env.timeout(randint(30, 90))
env = simpy.Environment()
ev = EV(env)
env.run(until=150)