yojimbos_law

steady state queue simulator thingy

Dec 12th, 2017
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. //script simulates encounter selection with a range of user-specified values for # of encounters, length of queue, and rejection rate and records the distribution of queue states for 10m trials with each set of parameters.
  2. //this script should have no practical applications; it exists solely to generate numerical data to look into the veracity of a conjecture of mine that I've had considerable difficulty proving over the last several years (i.e. that the probability of encountering queue state A is equal to that of queue state B whenever queues A and B have the same number of distinct things in them).
  3.  
  4. int[int] buffer_queue;
  5.  
  6. void select(int n, int k, int p, int q){
  7. int selection = -1;
  8. boolean in_queue;
  9. int rejection_roll = q;
  10. while(selection == -1){
  11. selection = random(n);
  12. in_queue = false;
  13. for i from 1 to k{
  14. if(selection == buffer_queue[i]){
  15. in_queue = true;
  16. }
  17. }
  18. if(in_queue){
  19. rejection_roll = random(q);
  20. if(rejection_roll < p){
  21. selection = -1;
  22. }
  23. }
  24. }
  25. for i from 2 to k {
  26. buffer_queue[i-1] = buffer_queue[i];
  27. }
  28. buffer_queue[k] = selection;
  29. }
  30.  
  31.  
  32. void generate_and_save_some_queue_data(int n, int k, int p, int q){
  33. //rolls will take values 0,...,n-1
  34. //queue will remember last k rolls.
  35. //rejection rolls will take values 0,...,q-1 and will reject selections if less than p.
  36. //rejection rate is effectively p/q
  37. //seed selection process with uniform distibution queue
  38. //let's see how long this takes to run
  39. int starting_gun = gametime_to_int();
  40. for i from 1 to k{
  41. buffer_queue[i] = random(k);
  42. }
  43.  
  44. //seed queue with more queueily selected things
  45. for i from 1 to k*k {
  46. select(n,k,p,q);
  47. }
  48. //let's count some queues for some numerical analysis of steady state distributions
  49. float[string] queue_frequency;
  50. int progress = 0;
  51. for i from 1 to 10000000{
  52. select(n,k,p,q);
  53. string queuey_string = "";
  54. for j from 1 to k{
  55. if(j == 1){
  56. queuey_string += buffer_queue[j].to_string();
  57. }
  58. else{
  59. queuey_string += ","+buffer_queue[j].to_string();
  60. }
  61. }
  62. queue_frequency[queuey_string] += 1;
  63. if(i%1000000 == 0){
  64. progress++;
  65. int butts = (gametime_to_int()-starting_gun)/1000;
  66. print_html("we're "+i/1000000+"/10 done after "+butts+" seconds.");
  67. }
  68. }
  69. foreach i in queue_frequency{
  70. queue_frequency[i] /= 10000000;
  71. }
  72.  
  73. //let's label the file in a way that is good.
  74. map_to_file(queue_frequency,"queue frequency data with n="+n+" k="+k+" p="+p+" q="+q+".txt");
  75.  
  76. print_html("and we're done");
  77. }
  78.  
  79. //number of entry values minus 1
  80. for a from 2 to 4{
  81. //number of queue slots
  82. for b from 3 to 6{
  83. //numerator of rejection rate
  84. for c from 0 to 9{
  85. generate_and_save_some_queue_data(a,b,c,10);
  86. }
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment