Modeling a Car Wash¶
Faisal Qureshi
faisal.qureshi@ontariotechu.ca
http://www.vclab.ca
Copyright information¶
© Faisal Qureshi
License¶
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.
Setup¶
A carwash shop has a limited number of washing stations. Each car takes "some time" to be washed. The time that each car takes is bounded by some range, e.g., it may take a car to be washed any where between 3 and 7 minutes. Each washing station can only clean a single are at each time. Cars arrive at the carwash shop, wait for a wash station to become available, and gets washed.
Acknowledgements¶
This code is adapted from simpy examples.
In [29]:
import random
import simpy
In [30]:
class Carwash(object):
def __init__(self, env, num_wash_stations, washtimes):
self.env = env
self.wash_stations = simpy.Resource(env, num_wash_stations)
self.washtimes = washtimes
def wash(self, car):
12 13 9 8 13 12 14 11 11 14 12 7 8 9 11 12 7 14 12 9 8 10 11 14 11 13 12 12 14 13 11 8 12 12 11 14 12 11 11 10 12 8 13 11 11 8 11 13 10 11 10 9 11 9 11 12 12 14 12 7 14 10 7 12 13 12 11 10 14 12 12 9 9 8 11 11 7 7 8 10 9 11 10 8 13 11 12 9 10 9 10 7 10 13 12 13 13 11 10 9
a, b = washtimes
washtime = random.randint(a, b)
print(washtime)
yield self.env.timeout(washtime)
In [31]:
def car(env, name, cw):
print(f'{name} arrives at the carwash shop at {env.now}')
with cw.wash_stations.request() as request:
yield request
print(f'{name} enters the carwash at {env.now}')
yield env.process(cw.wash(name))
print(f'{name} leaves the carwash at {env.now}')
In [24]:
def setup(env,
num_wash_stations,
wash_times,
time_between_arrivals):
carwash_shop = Carwash(env, num_wash_stations, time_between_arrivals)
i = 0
while True:
a, b = time_between_arrivals
arrival_time = random.randint(a, b)
yield env.timeout( arrival_time )
i += 1
env.process( car(env, 'car %d' % i, carwash_shop) )
In [34]:
print('Carwash Simulation')
seed = 42
random.seed(seed)
num_wash_stations = 4
washtimes = (10,16)
time_between_arrivals = (2,3)
simulation_duration = 60
env = simpy.Environment()
env.process( setup(env, num_wash_stations, washtimes, time_between_arrivals) )
env.run(until=simulation_duration)
Carwash Simulation car 1 arrives at the carwash shop at 2 car 1 enters the carwash at 2 15 car 2 arrives at the carwash shop at 4 car 2 enters the carwash at 4 11 car 3 arrives at the carwash shop at 7 car 3 enters the carwash at 7 11 car 4 arrives at the carwash shop at 9 car 4 enters the carwash at 9 15 car 5 arrives at the carwash shop at 11 car 6 arrives at the carwash shop at 13 car 2 leaves the carwash at 15 car 5 enters the carwash at 15 10 car 7 arrives at the carwash shop at 16 car 1 leaves the carwash at 17 car 6 enters the carwash at 17 10 car 8 arrives at the carwash shop at 18 car 3 leaves the carwash at 18 car 7 enters the carwash at 18 11 car 9 arrives at the carwash shop at 20 car 10 arrives at the carwash shop at 22 car 11 arrives at the carwash shop at 24 car 4 leaves the carwash at 24 car 8 enters the carwash at 24 11 car 5 leaves the carwash at 25 car 9 enters the carwash at 25 13 car 12 arrives at the carwash shop at 27 car 6 leaves the carwash at 27 car 10 enters the carwash at 27 16 car 7 leaves the carwash at 29 car 11 enters the carwash at 29 16 car 13 arrives at the carwash shop at 30 car 14 arrives at the carwash shop at 32 car 15 arrives at the carwash shop at 34 car 8 leaves the carwash at 35 car 12 enters the carwash at 35 12 car 16 arrives at the carwash shop at 37 car 9 leaves the carwash at 38 car 13 enters the carwash at 38 11 car 17 arrives at the carwash shop at 40 car 18 arrives at the carwash shop at 42 car 10 leaves the carwash at 43 car 14 enters the carwash at 43 10 car 19 arrives at the carwash shop at 45 car 11 leaves the carwash at 45 car 15 enters the carwash at 45 13 car 20 arrives at the carwash shop at 47 car 12 leaves the carwash at 47 car 16 enters the carwash at 47 12 car 21 arrives at the carwash shop at 49 car 13 leaves the carwash at 49 car 17 enters the carwash at 49 14 car 22 arrives at the carwash shop at 52 car 14 leaves the carwash at 53 car 18 enters the carwash at 53 16 car 23 arrives at the carwash shop at 55 car 24 arrives at the carwash shop at 57 car 15 leaves the carwash at 58 car 19 enters the carwash at 58 14 car 16 leaves the carwash at 59 car 20 enters the carwash at 59 10
In [ ]: