CiwPython / Ciw

Ciw is a simulation library for open queueing networks.
http://ciw.readthedocs.io
MIT License
146 stars 42 forks source link

[Question]: What happens when service discipline returns None? #222

Closed galenseilis closed 7 months ago

galenseilis commented 7 months ago

I am contemplating what would happen if I had a service discipline that sometimes returns None. As an extreme case to get a sense of the behaviour of Ciw I created a service discipline that always returns None. Here is the minimum reproducible example:

import ciw
import pandas as pd

def just_none(individuals):
    return None

N = ciw.create_network(
    arrival_distributions=[ciw.dists.Exponential(rate=5)],
    service_distributions=[ciw.dists.Exponential(rate=5)],
    service_disciplines=[just_none],
    number_of_servers=[1]
)

ciw.seed(2018)
Q = ciw.Simulation(N)
Q.simulate_until_max_time(1)

df = pd.DataFrame(
    Q.get_all_records()
    )

print(df.to_markdown(index=False))

The output (below) suggests that customers are being served. I had assumed the opposite would occur.

id_number customer_class original_customer_class node arrival_date waiting_time service_start_date service_time service_end_date time_blocked exit_date destination queue_size_at_arrival queue_size_at_departure server_id record_type
1 Customer Customer 1 0.152353 0 0.152353 0.00561602 0.157969 0 0.157969 -1 0 0 1 service
2 Customer Customer 1 0.349852 0 0.349852 0.141531 0.491383 0 0.491383 -1 0 1 1 service
4 Customer Customer 1 0.5283 0 0.5283 0.0537462 0.582046 0 0.582046 -1 1 2 1 service

What is the behaviour of Ciw when a service discipline returns None?

geraintpalmer commented 7 months ago

Good questions! I did not anticipate this the service disciplines being used like this.

Service discipline functions gives the next customer be be served from the queue.

So any customer that arrives when the server is free always gets served. They are never selected from the queue.

In your case, when customers 1, 2 and 4 arrived there was no one in service, and so they all began service straight away. When customer 3 arrived there was someone in service, they joined the queue, but never left because of the service discipline returning None. When customer 4 arrived, customer 3 was waiting, but not in service, and the server was free, to they began service immediately.

Hope that helps.