Next: The generator class
Up: Program structure
Previous: The entity class
The primitives and methods for running and ending the simulation are
provided by the simulation class.
The simulation class has the following interface :
interface simulation
{
simulation();
virtual ~simulation();
void run(); // run until no events left
void run(double t); // run for t time units
void run(int count); // run for count terminated events
void quit(); // quit simulation
void terminate(event* e); // terminate e
int schedule(event* e,double t); // schedule e at t
int wait(double t); // schedule current
int passivate(event* e); // passivate e
int activate(event* e); // activate e
int hold(event* e); // add e to conditional
int withdraw(event* e); // put e on closed
int reinstate(event* e); // put e on conditional
void reset(); // reset the simulation
double clock(); // return clock
void init(char* options = ""); // initialize
int cancel(); // cancel events
screen* format(char* p,char* options = ""); // statistics
screen* format(widget* w,char* p,char* options = "");
void postscript(char* fn); // generate postscript
friend ostream& operator<<(ostream& os,simulation& s);
};
The simulation object should be created before
other objects participating in the program are created.
The method run is used to run the simulation for t time units,
for count terminated events or until no scheduled events are left.
The simulation can be stopped by calling quit.
The primitives are described in section 3.2.
Reset clears the scheduler and conditional list, resets the clock
to 0 and resets the reports and widgets (if set) to their original state.
The function clock returns the current simulation time.
The init method handles the following options :
- -realtime (double) - default 0
- -scan (yes,no) - default no
- -suppress (none,reports,statistics,both) - default none
If the constructor takes the -realtime argument the library runs in real
time mode. A run then ends if the simulation time divided by the double
is greater then the actual time (in seconds) that elapsed.
If the -scan option is set to yes, the list with the
conditional events is traversed, even between events with the same activation time.
Setting -suppress has as effect that generated reports and/or statistics are not printed after a run.
The method cancel removes and deletes every event from the
scheduler and conditional list that receives FALSE from its
event::verify method. This method can be used to model the
breakdown of a server for example, departure events should be canceled
then.
The format method creates a screen with the
specified path for the statistics and handles the following options :
- -foreground (color) - default black
- -background (color) - default white
- -width (int) - default 400
- -height (int) - default 120
The size can be adjusted but the pre condition is that width/400 is
equal to height/120. If format is not used the statistics are
printed on a default toplevel screen (if in hush mode).
The function postscript writes the window of the simulation
object (if created) in postscript format to the specified file.
The operator<< function can be used when debugging a program.
It prints the contents of the scheduler and conditional list.
Next: The generator class
Up: Program structure
Previous: The entity class
A Eliens
Tue Oct 31 09:27:21 MET 1995