#+ setup,include=FALSE source("http://www.cs.utoronto.ca/~radford/csc121/options.r") #+ #' CSC 121, Jan-Apr 2017, Large Assignment #1. source("lga1-defs.R") #' PART 1: #' #' Tests of the simulate_queue and run_simulations functions. # Try the example in the assignment handout. set.seed(1) simulate_queue (10,0.7,1,2) # Some other tests of simulate_queue. set.seed(1) simulate_queue (10,5,1,2) # high arrival rate set.seed(1) simulate_queue (10,0.1,1,2) # low arrival rate set.seed(1) simulate_queue (10,0.01,1,2) # very low arrival rate - probably none served set.seed(1) simulate_queue (10,0.7,0.1,2.9) # wide service time distribution # Some tests of run_simulations. run_simulations (1:3,10,0.7,1,2) # first should be same as test above run_simulations (3:1,10,0.7,1,2) # should be the same in reversed order #' PART 2: #' #' Results from four groups of simulations with varying low, high, and rate. # Do the four groups of simulations. df1 <- run_simulations (101:150, open_time=100, rate=0.5, low=1.0, high=2.0) df2 <- run_simulations (201:250, open_time=100, rate=0.8, low=1.0, high=2.0) df3 <- run_simulations (301:350, open_time=100, rate=0.5, low=1.4, high=1.6) df4 <- run_simulations (401:450, open_time=100, rate=0.8, low=1.4, high=1.6) # Combine the four groups into one data frame, and show it. df <- rbind(df1,df2,df3,df4) print(df) # Produce the plots for rate=0.5 and rate=0.8. for (rate in c(0.5,0.8)) { # Extract the data for this rate, with wide and narrow range of service time wide <- df [df$rate==rate & df$low==1.0, ] narrow <- df [df$rate==rate & df$low==1.4, ] # Produce the plot, with red points for wide and green points for narrow plot (c(wide$served,narrow$served), c(wide$avewait,narrow$avewait), col = c (rep("red",nrow(wide)), rep("green",nrow(narrow))), xlab="Number served", ylab="Average wait time") # Add title identifying the rate and colour scheme title (paste ("Results with arrival rate", rate, "(red 1.0,2.0; green 1.4,1.6)")) } #' As one would expect, both the number served and the average wait time #' tends to be higher when the arrival rate is higher. Simulations in which #' a larger number were served tend to have a higher average wait time, again #' as one would expect. #' #' Whether the service time distribution is wide or narrow seems to have #' no noticeable effect, since in these plots, the distribution of the red #' dots seems to be about the same as the distribution of the green dots. #' #' There must be some difference, however, since when low=1.4, it's not #' possible for the average wait time to be less than 1.4, whereas this is #' possible (though unlikely) when low=1.0.