
Products/FAQ : Introduction to CSIM
Introduction
CSIM is a library of routines for
use by C, C++, or Java programmers; these
routines are used to implement process-oriented,
discrete-event simulation models of
complex systems. Such models can be
used to gain insight into the operation
and performance of the modeled systems.
A model consists of structures (which
simulate the resources of the model
system) and processes (which simulate
the active entities of the model system).
CSIM has mechanisms for implementing
both processes and resources.
A CSIM model is a computer program,
written in the C, C++, or Java programming
language. Some knowledge of C++ is
being assumed for readers of this
primer.
Processes
Processes are used to model the active
entities of a system. Depending on
the type of model, processes represent
many kinds of entities; examples include:
-
customers, in a model of a bank,
-
transactions, in a model of an on-line transaction processing system,
-
messages, in a model of a computer network, and
-
TV sets, in a model of an assembly line.
In CSIM, a CSIM process is a procedure
which executes the create statement.
Thus, a typical CSIM process has
the form:
void customer()
// defines customer
{
create("cust");
// other statements
}
A CSIM process is started (invoked)
by another process; it is called using
the usual procedure call:
void otherProcess()
{
create("other");
// other statements
customer(); // starts customer process
// other statements
}
CSIM processes are different from
normal procedures in several important
ways:
-
Processes operate in a "simulated environment", being under the control of the CSIM execution supervisor with respect to the passage of simulated time.
-
Many instances of the same process can be "active" at the same time in this simulated environment.
-
Processes are in one of four process states:
- Computing - using the real CPU
-
Ready to start computing,
-
Holding - allowing simulated time to pass, and
-
Waiting - for something outside of the process to happen.
-
A process remains in the Computing state (executing) until it voluntarily takes one of the following actions:
-
enter the Hold state (for a specified interval of simulated time)
-
enter the Wait state (waiting for some external event to occur), or
-
terminate (remove itself from the simulated environment).
-
A process cannot return control to its caller (or return a functional value to its caller); rather a process must "terminate" (this is handled automatically by the CSIM execution supervisor).
-
A process is able to suspend execution (leave the Computing state) and then later resume execution (enter the Ready state and then reenter the Computing state) an unlimited number of times and in no predictable pattern; the CSIM execution supervisor manages all of these activities.
-
Each instance of an "active" process has its own "execution context"; there are separate copies of the local variables, registers contents, etc. for each active process. All of these process contexts are also handled automatically by the execution supervisor.
The flow of control (the "semantics")
of invoking processes is illustrated
in the following example:
void otherProcess()
// the starting process
{
long i;
create("other");
for(i = 0; i < 10; i++) // invoke
10 instances of cust
customer();
hold(25.0);
// other statements
}
void customer() // the started process
{
create("customer"); // <---
Focus of discussion
// other statements
}
Understanding the operation of the
create statement in the customer()
process is critical to understanding
the operation of CSIM processes.
When this create statement executes,
the following actions take place:
-
A process context for the new customer process is created,
-
This new process context is put in the Ready state (eligible to enter the Computing state), and
-
Control returns to the calling (invoking) process (otherProcess in the example).
In this example, the "otherProcess"
process invokes 10 instances of the
"customer" process. At the
end of the "for" loop, there
are 10 instances of "customer",
each Ready to enter the Computing
state. When "otherProcess"
executes the hold(25.0) statement,
it is suspended and the first "customer"
process enters the Computing state
and continues computing until it suspends
itself. At this point, the second
"customer" process starts
computing, and so on.
The hold(25.0) statement really both
suspends "otherProcess"
and schedules it to enter the Ready
state when 25.0 units of simulated
time have passed. It should be noted
that simulated time passes only as
the result of processes executing
hold statements. It should also be
noted that "computing" take
no simulated time; in other words,
computing is "free", in
the sense that computing time does
not require simulated time.
The remainder of this note discusses
the simulated resources and other
structures which are used to control
the processes of a model and the interactions
between these processes.
Resources
In many systems, processes must visit
and use (occupy) a succession of resources.
CSIM offers two kinds of resources:
facilities and storages. A facility
consists of a single queue (for waiting
processes) and one or more servers.
Facilities are used to represent resources
where entities (processes) "use"
servers "one-at-a-time".
The operations which are applied to
facilities by processes include:
-
reserve - wait for and then gain access to a "free" server
-
release - release a reserved server, and
-
use - a combination of a reserve, hold, and release.
In addition to the queue and server(s),
a facility also has provisions for
collecting data on the delays associated
with gaining access to a server and
on using the servers. This data collection
is automatic; a report summarizing
these collected data can be produced
at any time during the execution of
the model.
A storage consists of a queue and
a pool of storage units (sometimes
called tokens). A process can allocate
one or more storage units; if there
is not a sufficient number of units
to satisfy an allocation request,
the process is suspended and placed
in the queue. When other processes
have deallocated their storage units,
queued processes are given units to
satisfy their requests. As with facilities,
there are data which summarize the
delays for and use of these storage
units.
Process
Interactions
CSIM provides two structures to
facilitate and control interactions
and communications between different
processes. These structures are:
-
events
-
mailboxes
An event can be in either the OCCURRED
state or the NOT_OCCURRED state. A
process can wait for a specified event
to "occur". Another process
can set an event, causing it to be
placed in the OCCURRED state and allowing
all of the waiting processes to resume
(enter the Ready state).
A mailbox is a place where processes
can exchange information (messages).
One process can send a message to
a mailbox. Another process can attempt
to receive a message from a mailbox;
if a message is "in" the
mailbox, the receiving process gets
that message and continues computing;
if there are no messages in the mailbox,
each receiving process must wait until
a message is sent to that mailbox.
An Example
As an example, consider an assembly
line, where TV sets pass through an
assembly station and then are inspected.
About 20% of the inspected sets fail
and are sent back to the assembly
station for rework. If a set fails
inspection a second time, it is scrapped.
The parameters of the model are the
arrival rate of sets to this station,
the time required to assemble or rework
a set, the number of workers (servers)
at the assembly station, the number
of inspectors and the inspection failure
rate. The goal is to determine the
number of workers and inspectors required
to insure that this station is not
a "bottleneck" in the operation
of the factory.
A complete CSIM model of this system
follows as Figure 1; the report output
for this model appears in Figure 2.
The model is a C++ program which utilizes
the classes, methods and procedures
of the CSIM library.
// Model TV
Set Assembly and Inspection Stations
#include "cpp.h"
const double simTime = 8*60.0; //
parameters, constants
const long numberWorkers = 5;
const long numberInspectors = 2;
const double arrTime = 2.0;
const double assemblyTime = 3.0;
const double reworkTime = 1.5;
const double inspectTime = 2.0;
const double failRate = 0.20;
facility initialPrep("initial");
// facilities
facility_ms assembly("assmbly",
numberWorkers);
facility_ms inspect("inspect",
numberInspectors);
facility finalPrep("final");
facility scrapPrep("scrap");
FILE *fp;
void generate(); // prototypes
void TVSet();
extern "C" void sim() //
main process
{
fp = fopen("xxx.out", "w");
set_output_file(fp);
create("sim");
generate(); // start generate process
hold(simTime); // lengthof run
report(); // producereport
}
void generate()
// generator process
{
create("gen");
while(1) {
TVSet(); // start TV Set process
hold(exponential(arrTime)); // timebetween
TV Sets
}
}
void TVSet() // TV Set process
{
long inspectCt = 0;
double stationTime;
long exitCond = 0;
create("TVSet");
initialPrep.use(0.5); // prep station
stationTime = assemblyTime;
do {
assembly.use(exponential(stationTime));
// assembly station
inspect.use(exponential(inspectTime));
// inspect station
inspectCt++;
if(bernoulli(failRate) == 0) { //
outcome of inspection
finalPrep.use(0.5); // passed ->
final prep
exitCond = 1;
}
else {
if(inspectCt < 2) {
stationTime = reworkTime; // failed
1st, rework
}
else {
scrapPrep.use(0.5); // failed 2nd,
-> scrap
exitCond = 1;
}
}
} while(exitCond == 0);
}
Figure
1: Listing of Example Model (TV Sets)
CSIM Simulation Report (Version 19
for MS Visual C++)
Tue Apr 08 13:25:46 1997
Ending simulation time: 480.000
Elapsed simulation time: 480.000
CPU time used (seconds): 0.160
| Facility Summary | |||||||
| facility name |
service disk |
service time |
util. | through-put | queue length |
response time |
compl count |
| initial | fcfs | 0.50000 | .0263 | 0.52500 | 0.30024 | 0.57199 | 252 |
| assembly | fcfs | 2.70720 | 1.686 | 0.62292 | 1.69512 | 2.72126 | 299 |
| >server | 0 | 3.05139 | 0.661 | 0.21667 | 104 | ||
| >server | 1 | 2.38099 | 0.486 | 0.20417 | 98 | ||
| >server | 2 | 2.92460 | 0.299 | 0.10208 | 49 | ||
| >server | 3 | 2.70011 | 0.196 | 0.06875 | 33 | ||
| >server | 4 | 1.75744 | 0.055 | 0.03125 | 15 | ||
| inspect | fcfs | 2.03109 | 1.261 | 0.62083 | 1.98357 | 3.19500 | 298 |
| >server | 0 | 2.10837 | 0.685 | 0.32500 | 156 | ||
| >server | 1 | 1.94619 | 0.576 | 0.29583 | 142 | ||
| final | fcfs | 0.50000 | 0.250 | 0.50000 | 0.29389 | 0.58777 | 240 |
| scrap | fcfs | 0.50000 | 0.010 | 0.02083 | 0.0142 | 0.50000 | 10 |
Figure
2: Report Output for TV Set Example
The model has two kinds of processes
(in addition to the initial "sim"
process): the "generate"
process injects TVSet processes into
the model at varying intervals which
model the arrivals of TV Sets at this
station. The probability distribution
of these interarrival intervals is
a negative exponential distribution
with mean as specified by the arrTime
constant. The TVSet process models
the behavior of a TV set as it progresses
through the set of stations. The facilities
(representing the stations of the
system) are declared and constructed
a global, static objects. Each TVSet
process uses (visits), in turn, the
initialPrep station, the assembly
station and the inspection station.
The times spent at each station are
all sampled from negative exponential
probability distributions, with means
specified by the appropriate constants.
CSIM provides a variety of probability
driven random number functions, so
that it is likely that an appropriate
function can be found for any modeling
situation.
The outcome of the inspection is determined
by a Bernoulli function; the parameter
is the mean failure rate. Thus, a
successful outcome of the Bernoulli
function is a failed TV set and an
unsuccessful outcome of the Bernoulli
function is a passed TV set. Passed
sets go to the finalPrep station and
then exit the model. Failed sets can
return to the assembly station for
a rework cycle, but only one time.
Thus, a unit failing for the second
time is sent to the scrapPrep station
and then exits.
The report output shows that with
five assembly workers and two inspectors,
the model predicts "acceptable"
performance. Other runs of the model,
for example with one inspector, show
that the number of inspectors can
be critical to successful operation.
With one inspector, the response time
at the inspector station climbs to
about 20 minutes per TV set.
Other Features
CSIM includes many features which
were not described above. For example,
there are extensive capabilities for
collecting specialized data, which
are needed to gain insight into specific
aspects of the operation of the model.
Both real-valued items, such as response
times, and time-based, integer-valued
items (such as queue lengths) can
be collected. Included in these data
gathering features are special mechanisms
for producing confidence intervals
for output values. There is also a
"automatic run-length control"
feature, which lets a model execute
until desired levels of statistical
accuracy for specified output values
are achieved.
All of the data collected at facilities,
storages, tables (for real valued
data) and qtables (for time-based,
integer-valued data) are accessible
via a group of inspector functions.
These can be used to produce output
reports tailored to specific reporting
needs.
There are capabilities for testing
the status of the simulated resources
and for modifying the characteristics
of these resources. These can be used
to produce very accurate representations
of many different kinds of system
resources.
All of the features and capabilities
of all of the classes, methods and
procedures in the CSIM library
are described in the CSIM User's Guide.
Summary
This Primer has described some of
the features and capabilities of the
CSIM simulation software toolkit.
The Primer has focused on CSIM processes,
as these are critical to implementing
robust models of complex systems.
A fairly detailed example illustrated
the use of processes and facilities
to model a section of a TV set assembly
line. The interested reader is referred
to the CSIM User's Guides and the
CSIM Getting Started manuals for
additional information.

