CiwPython / Ciw

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

Server priorities bug #200

Open srinath-radhakrishnan opened 2 years ago

srinath-radhakrishnan commented 2 years ago

Hi, when using server priorities by individual - I'm facing 2 issues. 1) The model works fine for first few instances as long as there is no state change. For example: I want class 0 (apple) to be prioritized first by server1 and then by server 2 and server 3 equally and class 1 (orange) to be prioritized by server 2 and 3 equally and then later by server 1 if both server 2 and 3 are busy. For this scenario, as long as server 1 is available for apples model works perfectly. The moment server 1 is busy and servers 2 and 3 start picking apples, the priority completely changes when next apple/orange comes into the queue. It goes to the point where beyond a stage, even if server 1 could wait to pick up the next apple, it assigns server 2 and 3 to apples. 2) within the allocation, the model randomly allocates customers rather than first come first serve. For example, I have 2 customers 1 apple customer at 11a and 1 orange customer at 11:30a and server 1 is busy during both arrivals . Server 2 is assigned. Server 2 just finished a customer at 11:20am. Now ideally the server 2 should work on apple customer at 11a (which has a 15 minute wait time) but instead it works on orange customer at 11:30a, finishes that first and then goes back to 11a apple customer. Due to this, my wait time/ customer is getting skewed and the simulation approach itself isn't right.

Can someone please help me here?

MichalisPanayides commented 2 years ago

Hi there @srinath-radhakrishnan

I am not sure I fully understand what your model looks like. Correct me if I'm wrong but my understanding is that you have two classes of customers:

and you want to prioritise your servers for both classes in such a way so that if:

One way of doing that is:

import random
import ciw

def custom_server_priority(srv, ind):
    if ind.customer_class == 0:
        priorities = {1: 0, 2: random.random(), 3: random.random()}
        return priorities[srv.id_number]

    if ind.customer_class == 1:
        priorities = {1: 1, 2: random.random(), 3: random.random()}
        return priorities[srv.id_number]

N = ciw.create_network(
    arrival_distributions={
        "Class 0": [ciw.dists.Exponential(1)],
        "Class 1": [ciw.dists.Exponential(1)],
    },
    service_distributions={
        "Class 0": [ciw.dists.Exponential(2)],
        "Class 1": [ciw.dists.Exponential(2)],
    },
    number_of_servers=[3],
    server_priority_functions=[custom_server_priority],
)

Is that similar to what you have? If not, can you show me how you defined your network object?