I studying the R programming. But I can not understant at all............ could
ID: 3848429 • Letter: I
Question
I studying the R programming.
But I can not understant at all............
could you explain each line the below r code??
# initializes global variables specific to this app
mm1initglbls <- function(apppars) {
mm1glbls <<- list()
mm1glbls$arrvrate <<- apppars$arrvrate
mm1glbls$srvrate <<- apppars$srvrate
mm1glbls$srvq <<- vector(length=0)
mm1glbls$njobstodo <<- 0 # jobs to do so far
mm1glbls$njobsdone <<- 0 # jobs done so far
mm1glbls$totwait <<- 0.0 # total wait time so far
arrvtime <- sim$currtime + rexp(1,mm1glbls$arrvrate)
schedevnt(arrvtime,"arrv",list(arrvtime=arrvtime))
if (arrvtime<=maxsim)
{mm1glbls$njobstodo<<-mm1glbls$njobstodo+1}
# cat("arrvtime:", arrvtime, " ")
}
Explanation / Answer
# initializes global variables specific to this app
mm1initglbls <- function(apppars) {
mm1glbls <<- list()
#simula tion parameters
mm1glbls$arrvrate <<- apppars$arrvrate
mm1glbls$srvrate <<- apppars$srvrate
#here the server queue, consisting of arrival times of queued jobs
mm1glbls$srvq <<- vector(length=0)
#the statistics
mm1glbls$njobstodo <<- 0 # jobs to do so far
mm1glbls$njobsdone <<- 0 # jobs done so far
mm1glbls$totwait <<- 0.0 # total wait time so far
# here we have to set up the set up first event, an arrival; the application-specific data for
# each event will consist of its arrival time, which we need to
# record in order to later calculate the job's residence time in the
# system
arrvtime <- sim$currtime + rexp(1,mm1glbls$arrvrate)
schedevnt(arrvtime,"arrv",list(arrvtime=arrvtime))
# application-specific event processing function called by dosim()
# in the general DES library
if (arrvtime<=maxsim)
{mm1glbls$njobstodo<<-mm1glbls$njobstodo+1}
# cat("arrvtime:", arrvtime, " ")
}