ComenzarEmpieza gratis

Managing payment queues

A clothes shop becomes very busy at peak hours when people often queue to pay. Currently, there is only one cashier, and you have been asked to do a cost-benefit analysis to determine how many cashiers would be needed to reduce waiting times as much as possible to increase profitability.

You have decided to build a discrete-event model. You know that:

  • On average, a new customer joins the queue every 15 seconds during peak hours;
  • Customers usually bring several items with them, typically between 1 and 20; and
  • It takes an average of 3 seconds to scan an item in the cashier, and the payment generally takes another 20 seconds.

The argument counter stores the SimPy resource, and the argument customer_num tracks the number of customers.

Let's run the model and calculate how long it takes to serve 30 customers with a different number of cashiers.

Este ejercicio forma parte del curso

Discrete Event Simulation in Python

Ver curso

Ejercicio interactivo práctico

Prueba este ejercicio completando el código de muestra.

def customer(env, customer_num, counter):

    num_items = random.randint(1.0, 20)
    print(f"Time: {env.now:7.4f} sec | Customer {customer_num:02d} > Joining the queue with {num_items:02d} items!")

    # Open the resource counter request
    with counter.____() as request:

        yield request
        print(f"Time: {env.now:7.4f} sec | Customer {customer_num:02d} > Got to cashier!")
        time_counter = TIME_PAY + random.randint(1.0, 20) * TIME_SCAN_PER_ITEM

        # Yield the processing time
        yield env.____(time_counter)
        print(f"Time: {env.now:7.4f} sec | Customer {customer_num:02d} > Finished ")

env = simpy.Environment()

# Create resource
counter = simpy.Resource(env, capacity=____)
env.process(source(env, NEW_CUSTOMERS, INTERVAL_CUSTOMERS, counter))
env.run()
Editar y ejecutar código