CiwPython / Ciw

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

Batching at the second node #168

Open lec00q opened 4 years ago

lec00q commented 4 years ago

When creating a network with two nodes, and the second node has a batching distribution set to more than one customer, I would expect that the customers arrive in batches (at the same time) at the second node, but this seems not the case.

That is, if I create a network like this:

N = ciw.create_network(
    arrival_distributions=[ciw.dists.Deterministic(1), ciw.dists.NoArrivals()],
    service_distributions=[ciw.dists.Deterministic(1), ciw.dists.Deterministic(2)],
    batching_distributions=[ciw.dists.Deterministic(1), ciw.dists.Deterministic(3)],
    routing=[[0.0, 1.0],
             [0.0, 0.0]],
    number_of_servers=[1, 1]
)

I would expect that:

In reality I observe the following:

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

recs = Q.get_all_records()
df = pd.DataFrame(recs)
df
Screenshot 2020-02-04 at 15 17 06

It this the expected behaviour? If so, I can I simulate the behaviour I want?

Many thanks

geraintpalmer commented 4 years ago

Dear @lec00q

You are correct, and this is the expected behaviour. In Ciw, "batching" only applies to external arrivals. Arrivals from another node are not batched.

I am note sure immediately how to model the behaviour you want. It may be possible to use Ciw's custom node feature: https://ciw.readthedocs.io/en/latest/Guides/behaviour.html to overwrite the node's release methods (line 394 in https://github.com/CiwPython/Ciw/blob/master/ciw/node.py), so that if there are less than three individuals reasy to be released it passes, but once there are 3 individuals waiting to be released then all three are released simultaneously.

I hope that helps somewhat.

lec00q commented 4 years ago

Dear @geraintpalmer,

thank you for your suggestion and sorry for the delayed answer. I have managed to obtain the behaviour described by inheriting from the custom node, as you said.

However, it came out a bit complicated and I had to modify quite a lot of methods: begin_service_if_possible_change_shift, begin_service_if_possible_accept, begin_service_if_possible_release, detatch_server. Not sure if I have made something wrong and if it could have been easier (probably!) but if you need some hints on how I did let me know. I think that for many real cases this can be a very nice add-on functionality.

Thanks!