Mesquite Software

Home
Products and FAQ
Customers
To Order
Contact Us
Site Map
Documentation
News & Events

Purchase & Download
Or, log in here to
access your account.
 
Documentation
User Guide: C++ : Introduction to CSIM 19 for C++ Programmers

Introduction

CSIM 19 is a library of routines, for use with C or C++ programs, which allows you to create process-oriented, discrete-event simulation models. This guide leads you through a simple model which uses the CSIM 19 routines. It closes with a brief discussion of the CSIM+ objects used to implement more complex models.

Example

The most basic simulation model is a single server and queue with arriving customers. With certain restrictions, this is the well-known M/M/1 queue. In the CSIM 19 version of this model, there is a facility consisting of a single server and a single queue. In addition, there is a source of customers. As a customer arrives, it either seizes (uses) the server if it is free (not in use) or it joins a queue of waiting customers if the server is already busy (in use). When one customer leaves the server, the next customer in the queue begins to use the server.

  • The key parameters in such a model are:
  • The intervals of time between customer arrivals
  • The intervals of server usage

The results of a study of such a model are:

  • The average customer response time (time of arrival to time of departure)
  • The customer throughput rate (customers served per unit time)
  • The server utilization (percentage of elapsed time that the server is busy)
  • The average queue length (number of customers at the facility)

Start C++ Figure 1

Figure 1: A Single Server Queue

A CSIM 19 program (in C) to model this simple system is as follows:

/*this CSIM program simulates an M/M/1 service center*/

#include <cpp.h> /*include the CSIM C++ header file*/

facility *f; /*the service center*/

extern "C" void sim() /*sim process*/
{

create("sim"); /*make this a process*/
f = new facility("f"); /*create the service center - f*/
while(simtime() < 5000.0) { /*loop until end of simulation*/
hold(exponential(1.0)); /*delay between customer arrivals*/
customer(); /*generate new customer*/
}

report(); /*produce statistics report*/

}
void customer()
{

create("customer"); /*make this a process*/
f->use(exponential(0.5)); /*obtain needed amount of service*/

}

The CSIM output for this example is as follows:

CSIM Simulation Report (Version 19 for MSVC++)
               
Mon May 13 13:42:39 1996
               
  Ending simulation time: 10001.909  
  Elapsed simulation time: 10001.909  
  CPU time used (seconds): 0.490  
               
FACILITY SUMMARY
facility name service disc service time util through-put queue length response time compl count
f fcfs 1.00954 0.512 0.50680 1.01983 2.01229 5069

This example shows most of the important features of a CSIM model:

1. In this example, there are two processes:
a. The base "sim" process which initializes the model and generates the customer arrivals at varying interarrival intervals, and
b. The "customer" process, which mimics the behavior of a customer of the f facility. Notice that there can be several customers (instances of the customer process) "active" at the same time: one using the server and others arriving and waiting in the queue.
2. A CSIM process is a C++ procedure which executes the "create" statement. Executing a create statement does two things:
a. Establishes the procedure which executes the statement as an independent, ready-to-run process, and
b. Returns control to the calling process.
3. A facility is declared with the "FACILITY" statement and is initialized by the "facility()" function.
4. The CSIM variable "clock" contains the current simulated time (the value of the simulated clock). In CSIM, time is a double precision, floating point value.
5. The "hold" statement causes time to pass for the process executing the statement; in the example, the "hold(exponential (1.0));" statement models the intervals of time between customer arrivals.
6. In many simulation models, it is appropriate to specify sequences of time intervals with probability distributions. In the M/M/1 queue, the interarrival intervals and the service intervals are "sampled" from negative exponential distributions. In CSIM, the exponential() function gives such samples.
7. Use of the facility is modeled by the "f->use(exponential (0.0)) statement (in this case, the facility being used is f).

8. To elaborate on an earlier point, there may be multiple instances of the customer process active and competing for use of the server at the same time. Modeling parallel activities such as this is a major feature of process-oriented models such as those implemented with CSIM.


The interactions among the processes in a model can be seen by looking at an activity (debug) trace which is generated by CSIM during the execution of a model (a trace is generated only upon request). A segment of the activity trace for the sample model is shown below:

time process .id priority status
0.000 sim 1 1 create sim 1
0.000 sim 1 1 join class default
0.000 sim 1 1 facility f with 1 server
0.000 sim 1 1 sched proc: t = 0.000, id = 2
0.000 sim 1 1 create customer 2
0.000 customer 2 1 join class default
0.000 sim 1 1 hold 1.332
0.000 sim 1 1 sched proc: t = 1.332, id = 1
0.000 customer 2 1 use facility f, t = 1.739
0.000 customer 2 1 reserve f
0.000 customer 2 1 hold 1.739
0.000 customer 2 1 sched proc: t = 1.739, id = 2
1.332 sim 1 1 sched proc: t = 0.000, id = 3
1.332 sim 1 1 create customer 3
1.332 customer 3 1 join class default
1.332 sim 1 1 hold 2.351
1.332 sim 1 1 sched proc: t = 2.351, id = 1
1.332 customer 3 1 use facility f, t = 0.626
1.332 customer 3 1 dequeue facility f
1.739 customer 2 1 terminate
1.739 customer 3 1 hold 0.626
1.739 customer 3 1 sched proc: t = 0.626, id = 3
2.365 customer 3 1 release f
2.365 customer 3 1 terminate

In this activity trace segment, we can see the following sequence of simulated activities:

  • The base (first) process, sim, starts at time 0.000 by initializing the facility (named f), starts the first customer process and then does a hold of 1.332 time units (the interval until the next customer arrival which is generated by using a negative exponential distribution with a mean of 2.0). Since this example doesn't divide its processes into different classes for reporting purposes, all processes are shown as joining the default class. This example also does not assign explicit priorities to processes, so they all default to priority 1.
  • Because sim has "suspended" execution, the first customer process can begin execution, also at time 0.000 (the id of this instance of customer is 2, so we will refer to it as customer.2). Upon arrival, customer.2 executes a "use", which reserves the facility f. Since f is free, customer.2 gets it and then does a hold, simulating its service interval of 1.739 time units (generated by using a negative exponential distribution with a mean of 1.0).
  • At time 1.332, the hold for sim expires, so sim resumes execution and generates the arrival of the next customer, customer.3. sim then does a hold of 2.351 units of time, the interval until the next customer arrival.
  • Customer.3 begins execution at 1.332. It tries to use f, but f is busy (it is being held by customer.2), so customer.3 must wait until customer.2 completes its service interval.
  • At time 1.739, customer.2 finishes its service interval, so it releases f. This frees f for use by the next customer in the queue of waiting customers. Since customer.2 is finished, it terminates. Termination for a process is automatic when the process (procedure) does a normal procedure exit.
  • Customer.3 is able to proceed (its reserve has succeeded), so does a hold for its service interval (0.626 time units).
  • At time 2.365, customer.3 completes its service interval, releases f and terminates.
  • Sim is still holding, simulating the interval until the arrival of the next customer.
  • The model will continue this sequence of activities (customer arrivals, requesting the facility, etc.) until the value of clock exceeds 10000.0 (the length of the simulated experiment specified by the define constant SIM_TIME). When the experiment finishes, the CSIM report is printed (by the report() procedure) and sim exits, causing the program to end.

The CSIM report in this example gives a statistical summary of the usage of the f facility by the 5069 customer processes which completed service during the 10001.909 simulated time units covered by the experiment. In the report, we can see the following:

  • The mean service interval at the facility is 1.010 time units. The fact that it is not 1.0 results from the use of the samples from the negative exponential probability distribution with mean 1.0.
  • The utilization of the facility is 0.512. This is the percentage of the elapsed time during which the server at f was busy (in use).
  • The throughput rate is 0.5 customers per unit time.
  • The mean queue length is 1.020. This is the average number of customers at the facility, including both customers at the server and in the queue of waiting customers.
  • The average response time experienced by customers at the facility (resp) is 2.012 time units. The response time includes both time in the queue and time at the server.
  • The number of completed customers at the facility is 5069.

CSIM Objects

CSIM provides a complete set of objects which can be used to construct models of almost any kind of system, at any level of complexity and detail. The objects supported by CSIM are:

  • Process - used to model elements of the workload, clients and servers, or any other active components of the system
  • Facility - used to model resources which are seized (used) by processes
  • Storage - used to model resources which are are partially allocated to processes
  • Buffer- uses to model buffers with finite capacity
  • Event - used to synchronize and control interactions between processes
  • Mailbox - used to exchange information between processes
  • Tables, Qtables, Meters, and Boxes - used to collect explicit statistics (note: statistics on usage of facilities and storage blocks are collected automatically)
  • Process class - used to segregate facility usage statistics
  • Stream of random numbers - used to generate multiple streams of samples from specified probability distributions

These objects can be created and used by the program to give accurate and detailed insights into the structure, organization and behavior of complex systems.
For more information on how to do this and how to derive many benefits from building and using CSIM models, contact Mesquite Software, Inc.

 
Home | Products/FAQ | Customers | To Order | Contact Us | Site Map | Documentation
© copyright 2005, Mesquite Software, all rights reserved.