Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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.
- //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).
- int[int] buffer_queue;
- void select(int n, int k, int p, int q){
- int selection = -1;
- boolean in_queue;
- int rejection_roll = q;
- while(selection == -1){
- selection = random(n);
- in_queue = false;
- for i from 1 to k{
- if(selection == buffer_queue[i]){
- in_queue = true;
- }
- }
- if(in_queue){
- rejection_roll = random(q);
- if(rejection_roll < p){
- selection = -1;
- }
- }
- }
- for i from 2 to k {
- buffer_queue[i-1] = buffer_queue[i];
- }
- buffer_queue[k] = selection;
- }
- void generate_and_save_some_queue_data(int n, int k, int p, int q){
- //rolls will take values 0,...,n-1
- //queue will remember last k rolls.
- //rejection rolls will take values 0,...,q-1 and will reject selections if less than p.
- //rejection rate is effectively p/q
- //seed selection process with uniform distibution queue
- //let's see how long this takes to run
- int starting_gun = gametime_to_int();
- for i from 1 to k{
- buffer_queue[i] = random(k);
- }
- //seed queue with more queueily selected things
- for i from 1 to k*k {
- select(n,k,p,q);
- }
- //let's count some queues for some numerical analysis of steady state distributions
- float[string] queue_frequency;
- int progress = 0;
- for i from 1 to 10000000{
- select(n,k,p,q);
- string queuey_string = "";
- for j from 1 to k{
- if(j == 1){
- queuey_string += buffer_queue[j].to_string();
- }
- else{
- queuey_string += ","+buffer_queue[j].to_string();
- }
- }
- queue_frequency[queuey_string] += 1;
- if(i%1000000 == 0){
- progress++;
- int butts = (gametime_to_int()-starting_gun)/1000;
- print_html("we're "+i/1000000+"/10 done after "+butts+" seconds.");
- }
- }
- foreach i in queue_frequency{
- queue_frequency[i] /= 10000000;
- }
- //let's label the file in a way that is good.
- map_to_file(queue_frequency,"queue frequency data with n="+n+" k="+k+" p="+p+" q="+q+".txt");
- print_html("and we're done");
- }
- //number of entry values minus 1
- for a from 2 to 4{
- //number of queue slots
- for b from 3 to 6{
- //numerator of rejection rate
- for c from 0 to 9{
- generate_and_save_some_queue_data(a,b,c,10);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment