queuecomputer icon indicating copy to clipboard operation
queuecomputer copied to clipboard

Simulation with dependent service time distribution

Open ikotoKun opened this issue 3 years ago • 5 comments

Hi there,

Just finished reading the paper “Computationally Efficient Simulation of Queues: The R Package queuecomputer.” and I really enjoyed it:) But I wonder if I can simulate a multi-server system with service time depending on the assigned server (i.e., the service time cannot be determined until the assigned server is known) with this package?

ikotoKun avatar Mar 26 '22 12:03 ikotoKun

Hi! Thanks!

The current version can't do this but it is something I was planning on doing very soon. You need something like an n_servers length vector that I will call server_effect. See https://github.com/AnthonyEbert/queuecomputer/blob/master/src/loops.cpp for comparison.

List qloop_numeric(NumericVector times, NumericVector service, int n_servers, NumericVector server_effect) {
  int n = times.size();
  vec output = vec(n);
  Col<int> server_output = Col<int>(n);
  int queue = 0;

  vec queue_times = vec(n_servers);
  queue_times.fill(0);

  for( int i=0; i < n; ++i)
  {
    queue = index_min(queue_times);
    queue_times[queue] = std::max(times[i], queue_times[queue]) + service[i] * server_effect[queue];
    output[i] = queue_times[queue];
    server_output[i] = queue + 1;
    if( i % 512 == 0 )
    {
      Rcpp::checkUserInterrupt();
    }
  }

Is this the kind of thing you wanted? If this is easy for you, go right ahead, otherwise I will make the change myself maybe this week.

AnthonyEbert avatar Mar 28 '22 08:03 AnthonyEbert

Hi Anthony, thank you for the reply!

Yes. What I expected was that the service time could be exponentially distributed with service rate being server-dependent in an M(t)/M(t)/n(t) system. So as you said, an n(t) length vector is something needed (e.g., the service rates input). You can make the changes yourself as planned. I'm still a beginner in C. Looking forward to any update:)

ikotoKun avatar Apr 01 '22 10:04 ikotoKun

The input would be the length of the number of servers. Eg if there are 4 servers the server_effect input is length 4. So server 1 might be faster than the other servers so server_effect = c(0.5, 1, 1, 1). It wouldn't be related to the number of customers. A customer taking server 1 would effectively have half the service time.

Making this changes is a lot more time consuming than I thought. Anyway I made an experimental branch just for you called server_effect.

To install

remotes::install_github("AnthonyEbert/queuecomputer", ref = "server_effect")

You can only use numeric servers (eg 1, 2, 3....). You should probably use queue rather than queue_step since I don't trust all the outputs (like waiting times etc...) for this branch. The function queue just gives the departure times, which I think are ok.

Example


library(queuecomputer)
arrivals = cumsum(rexp(20, 3.9))
service = rexp(20)

output = queue(arrivals, service, servers = 4, server_effect = c(1, 1, 1, 1), serveroutput = TRUE)

output
attributes(output)$server

output = queue(arrivals, service, servers = 4, server_effect = c(0.5, 1, 1, 1), serveroutput = TRUE)

output
attributes(output)$server

I probably won't work anymore on this branch, because I don't think that many people need this particular change. Plus, again, it's more work than I thought it was, to make sure all the outputs are perfect.

The serveroutput = TRUE is optional, it gives you the server assigned to each customer

AnthonyEbert avatar Apr 04 '22 08:04 AnthonyEbert

Hi Anthony,

The n(t) mentioned in my previous comment is actually K(t) in your paper, number of servers rostered-on for time t. Sorry for the confusion caused by my notation.

This is unfortunate that you won't work on the branch anymore but I understand the workload needed here. It's also been a pleasure discussing with you. Many thanks for the experimental branch and the example!

ikotoKun avatar Apr 07 '22 16:04 ikotoKun

Ah! Of course! I must be a more careful reader in future!

The other reason I didn't want to work more on this branch is that I think the way server allocation works in queuecomputer is kind of artificial. For instance if two servers are available, the customer will choose the server who has been available for the longest time.

This becomes even stranger with server effects. When there are server effects, the customer should probably pick the fastest available server, right? Or maybe even wait for an even faster sever? ... but that's a whole other algorithm - and it depends on what you're modelling.

AnthonyEbert avatar Apr 20 '22 11:04 AnthonyEbert