# NOT RUN {
# process 200 arrivals, R-provided seed (via NULL seed)
ssq(200, NULL)
ssq(maxArrivals = 200, seed = 54321)
ssq(maxDepartures = 200, seed = 54321)
ssq(maxTime = 100, seed = 54321)
############################################################################
# example to show use of seed = NA (default) to rely on current state of generator
output1 <- ssq(200, 8675309, showOutput = FALSE, saveAllStats = TRUE)
output2 <- ssq(300, showOutput = FALSE, saveAllStats = TRUE)
set.seed(8675309)
output3 <- ssq(200, showOutput = FALSE, saveAllStats = TRUE)
output4 <- ssq(300, showOutput = FALSE, saveAllStats = TRUE)
sum(output1$sojournTimes != output3$sojournTimes) # should be zero
sum(output2$sojournTimes != output4$sojournTimes) # should be zero
myArrFcn <- function() { vexp(1, rate = 1/4, stream = 1) } # mean is 4
mySvcFcn <- function() { vgamma(1, shape = 1, rate = 0.3) } # mean is 3.3
output <- ssq(maxArrivals = 100, interarrivalFcn = myArrFcn, serviceFcn = mySvcFcn,
saveAllStats = TRUE)
mean(output$interarrivalTimes)
mean(output$serviceTimes)
meanTPS(output$numInQueueT, output$numInQueueN) # compute time-averaged num in queue
meanTPS(output$serverStatusT, output$serverStatusN) # compute server utilization
############################################################################
# example to show use of (simple) trace data for arrivals and service times;
# ssq() will need one more interarrival (arrival) time than jobs processed
#
initTimes <- function() {
arrivalTimes <<- c(15, 47, 71, 111, 123, 152, 232, 245, 99999)
interarrivalTimes <<- c(arrivalTimes[1], diff(arrivalTimes))
serviceTimes <<- c(43, 36, 34, 30, 38, 30, 31, 29)
}
getInterarr <- function() {
nextInterarr <- interarrivalTimes[1]
interarrivalTimes <<- interarrivalTimes[-1] # remove 1st element globally
return(nextInterarr)
}
getService <- function() {
nextService <- serviceTimes[1]
serviceTimes <<- serviceTimes[-1] # remove 1st element globally
return(nextService)
}
initTimes()
numJobs <- length(serviceTimes)
output <- ssq(maxArrivals = numJobs, interarrivalFcn = getInterarr,
serviceFcn = getService, saveAllStats = TRUE)
mean(output$interarrivalTimes)
mean(output$serviceTimes)
############################################################################
# example to show use of (simple) trace data for arrivals and service times,
# allowing for reuse (recycling) of trace data times
initArrivalTimes <- function() {
arrivalTimes <<- c(15, 47, 71, 111, 123, 152, 232, 245)
interarrivalTimes <<- c(arrivalTimes[1], diff(arrivalTimes))
}
initServiceTimes <- function() {
serviceTimes <<- c(43, 36, 34, 30, 38, 30, 31, 29)
}
getInterarr <- function() {
if (length(interarrivalTimes) == 0) initArrivalTimes()
nextInterarr <- interarrivalTimes[1]
interarrivalTimes <<- interarrivalTimes[-1] # remove 1st element globally
return(nextInterarr)
}
getService <- function() {
if (length(serviceTimes) == 0) initServiceTimes()
nextService <- serviceTimes[1]
serviceTimes <<- serviceTimes[-1] # remove 1st element globally
return(nextService)
}
initArrivalTimes()
initServiceTimes()
output <- ssq(maxArrivals = 100, interarrivalFcn = getInterarr,
serviceFcn = getService, saveAllStats = TRUE)
mean(output$interarrivalTimes)
mean(output$serviceTimes)
############################################################################
# Testing with visualization
# }
# NOT RUN {
# Visualizing ssq with a set seed, infinite queue capacity, 20 arrivals,
# interactive mode (default), showing skyline for all 3 attributes (default)
ssq(seed = 1234, maxArrivals = 20, animate = TRUE)
# }
# NOT RUN {
# Same as above, but jump to final queue visualization
ssq(seed = 1234, maxArrivals = 20, animate = TRUE, plotDelay = 0)
# Perform simulation again with finite queue of low capacity. Note same
# variable generation but different outcomes due to rejection pathway
ssq(seed = 1234, maxArrivals = 25, animate = TRUE, maxInSystem = 5, plotDelay = 0)
# Using default distributions to make a default M/G/1 Queue
ssq(seed = 1234, maxDepartures = 10, interarrivalType = "M", serviceType = "G",
animate = TRUE, plotDelay = 0)
# }
Run the code above in your browser using DataLab