newsim,schedevnt,getnextevnt,mainloop,newqueue,appendfcfs,delfcfs,cancelevnt,exparrivals {DES}R Documentation

Discrete-event simulation routines.

Description

Main simulation routines.

Usage

newsim(timelim,maxesize,appcols=NULL,aevntset = FALSE,dbg=FALSE) 
schedevnt(simlist,evnttime,evnttype,appdata=NULL)
getnextevnt(simlist)
mainloop(simlist) 
newqueue(simlist) 
appendfcfs(queue,jobtoqueue)
delfcfs(queue)
cancelevnt(rownum,simlist)
exparrivals(simlist,meaninterarr,batchsize = 10000)

Arguments

appcols

Names of columns in the event set for application-specific data.

aevntset

If TRUE, exparrivals will be used for arrivals and an arrivals event set will be maintained.

dbg

If TRUE, use debug mode, action pausing for each new event occurrence.

simlist

An R environment containing the simulation, produced by newsim.

evnttime

Occurrence time for an event.

evnttype

Event type.

appdata

Application-specific data.

timelim

Time limit for simulation.

maxesize

Maximum number of rows needed in the event set matrix, excluding separate arrival event rows in the case aevntset = TRUE. (The matrix can be expanded dynamically if needed.)

queue

A queue. Must be in a simlist environment.

jobtoqueue

Job to be placed in a queue.

rownum

Number of the row to be deleted from the event set.

meaninterarr

Mean time between arrivals.

batchsize

Number of arrivals to generate in one call to rexp.

Details

Discrete event simulation, using the event-oriented approach.

Here is an overview of the functions:

Reaction Functions

These are user-defined. The DES function mainloop will make the call

simlist$reactevent(head, simlist)

where the user has initially set simlist$reactevent to his/her application-specific code. Here head is the event just now removed from the head of the event set, and simlist is the event set Let's call this function the "event handler," but note that within it there are if/else cases, one for each event type.

The For example, consider simulation of a single-server queue. When a job arrives, the arrivals section of the event handler will run (coded by the event type, again user-defined). It will record the arrival, update any application-specific totals, and see if service can be started for this job. If so, the code will schedule an event for completion of the service; if not, the code will add the job to the queue.

Outline of Typical Application Code

    mysim <- newsim()    # create the simlist
    set reactevent in mysim
    set application-specific variables in mysim, if any
    set the first event(s) in mysim$evnts
    mainloop(mysim,mysimtimelim)
    print results

Author(s)

Norm Matloff

Examples

# from MachRep.R in examples/ 

# create a sim list that will run for 100000 simulated time, with 3
# rows allocated for the event set, and application-specific columns
# named 'startqtime' and 'startuptime'
simlist <- newsim(100000,3,appcols=c('startqtime','startuptime'))
# create a queue
simlist$queue <- newqueue(simlist)  

[Package DES version 1.0.0 Index]