Date post: | 19-Dec-2015 |
Category: |
Documents |
View: | 217 times |
Download: | 0 times |
IntroductionCSIM19
A library of routinesProcess-oriented, discrete-event simulation package for use with C or C++ programs
A CSIM programIt models a system as a collection of CSIM processes which interact with each other
IntroductionCSIM provides the following simulation objects:
CSIM processes: processesCSIM objects: facilities, storages, buffers, events, mailboxesStatistics: tables, qtables, meters, …
Simulation timeCSIM maintains a simulation clock, with value equals to current time in the model
Different from the CPU time used or the “real world” timeStarts at zeroA double precision floating point
Simulation timeRetrieving the current time
1. Simtime functionPrototype: double simtime (void);Example: x = simtime ();
2. Reference the variable clockExample: x = clock;
Delaying for an amount of timePrototype: void hold (double amount_of_time);Example: hold (1.0);
ProcessIt is the active entities in a modelIt is a procedure which executes the create statementA process must be in four states
Active computing Ready to begin computingHoldingWaiting for an event
Initiating a processPrototype: void proc (arg1, … , argn);Example: my_proc (a, 64, “proc”);Note:
A create statement must appear in the initiated processA process cannot return a function value
Creating a processPrototype: void create (char* name);Example: create (“customer”);Note:
Executes at the beginning of a processProcess can initiate other processesNo simulation time passes
Process operationProcesses appear to operate simultaneously at the point in simulation timeProcesses execute until they suspend themselves by:
Execute a hold statementThe process is put into a queueExecute a csim_terminate statement
Terminating a processA process terminates when
A normal procedure exit, orExecutes a terminate statement
Prototype: void csim_terminate (void);Example: csim_terminate ();
Changing the process priority
Initial priority of a process is inherited from the initiator of that processDefault priority is 1Prototype: void set_priority (long new_priority);Example: set_priority (5);Note:
Must appear after the create statementLower values represent lower priorities
Reporting process statusPrint the status of each active processPrototype: void status_processes (void);Example: status_processes ();
Facilities It models a resource in a simulated systemProcesses are ordered in a facility queue by their priorities. A higher priority process is ahead of a lower priority process.
Declaring and initiating a facility
Declaring:Dynamic example: facility *fd;
Initiating:Prototype: facility::facility (char *name);Dynamic example: fd = new facility (“fac”);Static example: facility fs (“fac”);Note:
The facility name is only used only to identify the facility in output reports and trace messages
Using a facilityA process can use a facility for a specified interval of time.If the facility is free, then the process gains exclusive use of the server until the end of the usage intervalIf the facility is busy, then the process is put in a queue of waiting processes.
Prototype: void facility::use (double service_time);Example: fd->use(1.0);
Reserving and releasing a facility
In case a process acquires a server other than entering the usage interval
Reserve: to gain exclusive use of a serverRelease: to relinquish use of the server Prototype: void facility::reserve (void);
void facility::release (void);Dynamic example:
fd->reserve (); fd->release ();
Reserving and releasing a facility
Note:When a process executes a reserve, it either
1) gets use of the server, or 2) it is suspended and placed in a waiting queue
The process releasing a server must be the same process reserved it. Otherwise, use release_server ()“fd->reserve (f); hold (t); fd->release (f);”
= fd->use (t);“fd->reserve (f); hold (exponential(t)); fd->release (f);”
=!= fd->use (exponential(t));
Releasing a specific server at a facilityUsed when one process reserves a facility and then for another process to release
Prototype: void facility::release_server (long server_index);Dynamic example: server_index = fd->reserve ();fd->release_server (server_index);Note:
The first process has to save the index of the server and gives it to the second processThis is the same as release except the ownership is not checked
Declaring and initializing a multi-server facility
Prototype: facility_ms::facility_ms (char *name, long number_of_servers);Dynamic example: cpud = new facility_ms (“cpus”, 2);Static example: facility_ms cpus (“cpus”, 2);Note:
A process gains access to any free server when reserve()
Facility setsPrototype: facility_set::facility_set (char *name, long num_of_facilities);Dynamic example: facility_set *diskd; diskd = new facility_set (“disk”, 10);Static example:
facility_set disks (“disk”, 10); disks[i].use (exponential(1.0));
Events Used to synchronize the operations of CSIM processesAn event can only be in occurred or not occurred state
Declaring and initializing an event
Prototype: event::event (char *name);Dynamic example: event *ed; ed = new event (“done”);Static example: event es (“done)”;
Waiting for an eventWaiting for an event
Prototype: void event::wait (void);Dynamic example: e->wait ();
Waiting with a time-outPrototype: long event::timed_wait (double tout);Dynamic example: res = ed->timed_wait (100.0); if (res != TIMED_OUT) …
Queuing for an eventPrototype: void event::queue (void);Dynamic example: ed->queue ();Note:
This behaves like wait function, except that at each time event is set only one queued process is resumed.
Setting an eventPrototype: void event::set (void);Dynamic example: ed->set ();Note:
It causes all waiting processes and one queue process to be resumedIf there is no waiting event, the event will be in occurred state upon return from set function
Clearing an eventPrototype: void event::clear (void);Dynamic example: ed->clear ();Note:
Clearing an event that is in not occurred state has no effect
Event setsPrototype: event_set::event_set (char *name, long number_of_events);Dynamic example: event_set *ed_set;
ed_set = new event_set (“events”, 10);Static example:
event_set es_set (“events”, 10); es_set[3].set ();
Producing Report Status report
Prototype: void status_events (void);Dynamic example: status_events ();
TablesTo gather statistics on a sequence of discrete values such as interarrival times, service times, …It does not actually store the recorded values, it just simply updates the statisticsThe statistics maintained include: min, max, range, mean, var, std dev, coef of varCan add histogram, calculation of confidence intervals
Declaring and initializing a table
Prototype: table::table (char *name);Dynamic example: table *td;td = new table (“response time”);Static example: table ts (“response time”);
Tabulating valuesPrototype: void table::record (double value);Dynamic example: td->record (1.0);Note:
Tables are designed to maintain statistics on data type of type double only
Producing reportsPrototype: void table::report (void);Dynamic example: td->report ();Note:
report_tables () to produce reports for all tables