I'm trying to use SimPy to simulate a bus that stops periodically in a station and then waits until it gets filled by N passengers (assume that the bus is empty each time it arrives at the station), being N the total amount of spots that the bus has; this means that, in the case the bus arrives and the amount of people waiting in queue is smaller than N, then the bus will fill the amount of seats equal to the amount of people what were in the queue at that moment and then wait for more people to arrive at the station until the entire N spots are filled.
Here's a portion of what I'm trying to do:
def arrival_bus(env, bus):
print("-----------------------------------")
print("<<<<<<<<<<<<< BUS ARRIVES TO STATION")
bus.free_spots = total_amount_of_spots
print("CURRENT PASSENGERS IN STATION: ",len(passengers_queue))
if(len(passengers_queue) < total_amount_of_spots):
bus.free_spots -= len(passengers_queue)
passengers_queue = []
print("BOARDED PASSENGERS, WAITING FOR MORE PASSENGERS TO FILL THE", bus.free_spots, "SPOTS REMAINING...")
while(len(passengers_queue) < bus.free_spots):
env.process(passenger_arrival(env))
def passenger_arrival(env):
while True:
time_between_arrivals = 5
yield env.timeout(time_between_arrivals)
print("PASSENGER ARRIVED")
passengers_queue(env.now)
print("PASSENGERS IN STATION: ",len(passengers_queue))
def bus_movement(env,bus):
while True:
time_between_arrivals = 20
yield env.timeout(time_between_arrivals)
arrival_bus(env, bus)
But it's not working. I think it has something to do with the while loop in arrival_bus that executes when the amount of people in queue is smaller than total_amount_of_spots (N), but I don't get how else I can do it, I'm pretty much a newbie using SimPy.
Any help would be much appreciated!