CSIM automatically collects some usage
statistics. In order to allow the user
to collect other statistics describing
different aspects of the behavior of
the system, CSIM supplies several objects:
-
A histogram can
be specified for a table in order
to obtain more detailed information
about the recorded values. A histogram
has a user-defined number of intervals
and minimum and maximum values. The
histogram will actually create two
more intervals than specified, one
for values less than the minimum and
one for values greater than or equal
to the maximum. A histogram report
consists of a line of output for each
interval, as shown:
Tables can be defined to be either
permanent or non-permanent. A permanent
table is not affected by requests to
reset statistics or rerun the model,
and can thus be used to gather data
across multiple runs of a model.
Each table must be given a name, which
is used solely for output (reports,
status, and traces). The tables can
be printed using various report statements.
The following examples show how tables
and qtables can be used:
table *tbl; /*declare
table variable tbl */
...
tbl = new table("tbl"); /*initialize
a table named tbl */
tbl->add_histogram(10,0.0,20.0);
/*add a historgram to a table named
tbl */
...
t = clock; /*get current time */
single_server->reserve(); /*reserve
a single server facility */
x = clock - t; /*calculate time spent
on queue (delay interval)*/
tbl->record(x); /*record delay interval
in table */
...
qtable *qtbl; /*declare
queue histogram and table variable hst*/
...
qtbl=qtable("qtbl");
qtbl->add_histogram(20,0,20);
qtbl->note_entry(); /*record entry
onto queue for facility */
single_server->reserve(); /*reserve
a single server facility */
qtbl->note_exit(); /* record exit
from queue for facility */
hold(exponential(2.5));
table_confidence(tbl);
/* add confidence interval */
qtable_confidence(qtbl); /* add confidence
interval */
Meters are used to gather statistics
on the rate at which entities flow past
a point as well as the times between
passages. Meters can be used to measure
arrival rates, completion rates, allocation
rates, and interpassage times.
A box conceptually encloses part or
all of a model. This box gathers statistics
on the number of entities in the box
and on how much time they spend in the
part of the model deliniated by the
box. Boxes are used to gather statistics
on queue lengths, response times, and
populations.
-
A box report gives
the following information:
Statistics on elapsed times (see tables):
Statistics on population
variation (see qtables):
-
Histograms can
be added to boxes, (for both elapsed
times and population).
-
Confidence intervals
can also be used with boxes, (for
both elapsed time and population).
meter *mtr; /* declare
meter variable m */
mtr = new meter("mtr"); /*
initialize a meter named mtr */
mtr->note_passage(); /* note passage
of process */
box *b; /* declare
box variable b */
b = new box("b") /* initialize
a box named b */
timestamp = b->enter(); /* note enter
box */
b->exit(timestamp); /* note exit
*/
A confidence interval for a statistic
is a range of values in which the true
"answer" is believed to lie
with a high probability. In a simulation
model, the outputs, e.g.. system response,
are an important statistic and we would
like to calculate a confidence interval
for this statistic so that we can access
it's statistical accuracy. In CSIM 19
we can add confidence interval calculations
to tables, qtables, meters, and boxes.
The confidence intervals are calculated
for the confidence levels 90%, 95%,
and 99%.
Calculating confidence intervals is
complicated by the fact that many commonly
collected statistics (e.g.., response
times) are not independent. The algorithim
used to calculate confidence intervals
in CSIM 19 groups the observations into
batches, where the number of batches
depends on the correlation found in
the statistic. If a report is based
on an insufficient number of batches,
a message appears (instead of the calculated
confidence intervals).
CSIM 19 provides a mechanism for running
a model until a desired confidence level
has been achieved for a specified statistic.
However, it is possible that the model
may require an excessive amount of computing
time before the desired confidence level
is achieved, so a maximum CPU time parameter
is used to limit the execution time.
The output report makes clear the terminating
condition of the model.
The automatic run length control can
be used with tables, qtables, meters,
and boxes.
main routine
(sim):
const double CPU_TIME = 1 000.0;
const double CONF_LEVEL = 0.90;
const double ACCURACY = 0.01;
table
*tbl;
extern "C" void sim()
{
tbl = new table("tbl");
tbl->run_length(ACCURACY, CONF_LEVEL,
CPU_TIME);
...
converged.wait()
report();
}
Note: "Converged" is a built-in
event that does not need to be declared
or initialized.
In some models, it is convenient to
be able to segregate different instances
of a process (or processes) into classes
for the purpose of reporting facility
usage data (and possibly other statistics).
Further information on this can be found
in the CSIM Users' Guide.
CSIM provides a set of functions that
produce samples drawn from different
probability distributions. These are
all derived from a "random number
generator". In the standard case,
there is one random number generator
function (one random number stream)
used by all of the probability distributions.
In some cases, it is convenient to have
multiple streams of random numbers,
so that each stream operates in a repeatable
manner, even when the structure of the
model is changed. The CSIM object "stream"
serves this purpose.
The following example shows how random
numbers and streams can be used:
const double SERVICE_TIME
= 10.0 ;/*declare the mean service time
*/
float x; /*declare variables to contain
random numbers */
...
...
x = exponential(SERVICE_TIME); /* use
standard random number stream with a
negative exponential distribution on
a mean of 10.0 */
const double
SERVICE_TIME = 10.0;
stream *s
float x;
s = new stream();
x = s->exponential(SERVICE_TIME);
Successive streams are created with
initial values (seeds) which are 100,080
values apart.
The seed of a stream can be changed
by using the reseed function. The current
value of the seed can be retrieved using
the stream_state
function.
CSIM 19 includes the following built-in
random number distribution functions:
uniform(min,
max)
triangular(min, max, mode)
beta(min, max, shape1, shape2)
exponential(mean)
gamma(mean, stddev)
erlang(mean, var)
hyperx(mean, var)
weibull(shape, scale)
normal(mean, stddev)
lognormal(mean, stddev)
cauchy(alpha, beta)
random_int(min, max)
bernoulli(prob_success)
binomial(prob_success, num_trials)
geometric(prob-success)
negative_binomial(success_num, prob_succes)
poisson(mean)
There is also a capability for generating
random samples from an empirical distribution
defined by a table.
double prob[4]
= {0.30, 0.60, 0.10, 0.0};
double value[4] = {1.0, 5.0, 9.0, 0.0};
double cutoff[4];
long alias[4];
...
setup_empirical(3, prob, cutoff, alias);
...
x = empirical(3, cutoff, alias, value);
This tutorial has focused on the objects
provided in the CSIM 19 library. There
are many other functions and procedures
that help the CSIM user implement a
simulation model. These include:
-
Inspector functions
that return the state of an object,
the number of customers or messages
waiting at the object and other important
information about the object
-
Status procedures
(for most object types) that print
a report on the status of all objects
of that type. This can be useful in
debugging a model.
-
Report procedures
which print summaries of statistics
on the usage of facilities and storage
as well summaries based on tables,
histograms, qtables, and qhistograms
-
More inspector
functions that retrieve a number of
items, including every item provided
by CSIM reports, so that customized
reports can be produced
-
Routines to help
with the management and execution
of the model itself:
-
A procedure that
resets all of the statistics being
gathered, except for permanent tables
which are never reset.
-
A "rerun"
procedure that lets a model be destroyed
and then rebuilt, possibly with some
different features
-
A "debug"
event trace can be "turned on",
either by executing the "trace_on()"
procedure or by providing an input
argument when execution of the program
is initiated
-
Functions that
allow the user to change the maximum
number of objects that can be active
in a model (the maximums are by object
type)
-
All of the files
generated by the model (output, error
and trace) can be directed to files
under program control
A CSIM 19 model can be embedded in another
application. The user just has to provide
a main routine that calls "sim".
All of the routines in the CSIM library
have been optimized to support efficient
execution of the model. All data structures
are dynamically allocated, so there
are no pre-determined limits to the
sizes of models. The library does not
have to be recompiled to handle large
models.
CSIM 19 has been designed to empower
C++ programmers who need to build and
use simulation models of complex systems.
The programming approach to model building
means that models of arbitrary levels
of complexity and detail can be readily
constructed and verified. CSIM 19 does
not embody any preconceived notions
of how simulation models should be constructed
(other than using the process-oriented
paradigm).
Analysts and programmers interested
in finding out more about CSIM 19 and
how it can be obtained should contact
Mesquite Software, Inc.
Back to Documentation
Index
|
|