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++ : CSIM 19 Tutorial (C++ Version), Part 2

Tables and Qtables

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:

  • Table - collects floating point values and then gives a statistical summary consisting of, as shown:
TABLE 1: table
       
minimum 0.000016 mean 1.000040
maximum 10.336942 variance 0.999862
range 10.336926 standard deviation 0.999931
observations 10000 coefficient of var 0.999890
  • 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:
lower limit frequency proportion cumulative
proportion
0.00000 6322 0.632200 0.632200 ********************
1.00000 2288 0.228800 0.861000 *******
2.00000 878 0.087800 0.948800 ***
3.00000 322 0.032200 0.981000 *
4.00000 112 0.011200 0.992200
5.00000 48 0.004800 0.997000
6.00000 22 0.002200 0.999200
7.00000 5 0.000500 0.999700
8.00000 1 0.000100 0.999800
9.00000 1 0.000100 0.999900
>= 10.00000 1 0.000100 1.000000
  • Confidence intervals can also be specified for a table (see page 31).
  • Qtable - tracks state changes (for example the number of processes in a queue). The qtable reports on the following items:

QTABLE 1: qtable
           
initial 0 minimum 0 mean 0.795029
final 0 maximum 7 variance 0.802270
entries 10000 range 7 standard deviation 0.895696
exits 10000     coeff of variation 1.126620
  • A histogram can be specified for a qtable. It gives more detail on the time spent in each state.
  • Confidence intervals can be specified for a qtable (see page 33).
number total time proportion cumulative
proportion
       
0 3523.17812 0.352291 0.352291 **************
1 5078.27616 0.507790 0.860081 ********************
2 1306.88320 0.130679 0.990759 *****
3 90.75115 0.009074 0.999834
4 1.66151 0.000166 1.000000

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:

  • To declare, initialize, and use a non-permanent table with a histogram:

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 */
...

  • To declare, initialize, and use a non-permanent qtable with a histogram:

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));

  • To add confidence intervals to a table and to a qtable:

table_confidence(tbl); /* add confidence interval */
qtable_confidence(qtbl); /* add confidence interval */

Meters and Boxes

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 meter report gives the following information:
METER 1: meter
       
count 10000 rate 0.989904
       
interpassage time statistics
       
minimum 0.000144 mean 0.999140
maximum 9.135145 variance 1.010617
range 9.135002 standard deviation 1.005294
observations 10000 coefficient of var 1.006159
  • Histograms can be added to meters.
  • Confidence intervals can also be used with meters.

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):

    • minimum, etc.

    Statistics on population variation (see qtables):

    • initial, etc.

  • 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).

BOX 1: box
           
statistics on elapsed times
           
minimum 0.000037 mean 0.784577
maximum 6.498131 variance 0.622643
range 6.498094 standard deviation 0.789077
observations 10000 coefficient of var 1.005736
           
statistics on population
           
initial 0 minimum O mean 0.776656
final 0 maximum 6 variance 0.775737
entries 10000 range 6 standard deviation 0.880759
exits 10000     coeff of variation 1.134040
  • The following example shows how to declare, initialize, and use a meter:

meter *mtr; /* declare meter variable m */

mtr = new meter("mtr"); /* initialize a meter named mtr */

mtr->note_passage(); /* note passage of process */

  • The following example shows how to declare, initialize, and then use a box

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 */

Confidence Intervals

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 report for a data collection object with confidence intervals is as shown:

confidence intervals for the mean after 10000 observations
     
level confidence interval rel. error
     
90 % 1.005900 +/- 0.015530 = [0.990370, 1.021429] 0.015681
95 % 1.005900 +/- 0.018559 = [0.987341, 1.024458] 0.018796
98 % 1.005900 +/- 0.022116 = [0.983784, 1.028015] 0.022480

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).

Run Length Control

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.

  • To declare, initialize, and use a table with run length control:

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.

Process Classes

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.

Random Numbers and Streams

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:

  • To obtain a random number from the standard stream:

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 */

  • To declare, initialize, and use a stream:

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.

  • To initialize and use randomly derived values specified as follows:
value
frequency
1
.30
5
.60
9
.10

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);

Other Features

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.

Summary

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

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