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 : Sample Program

25. Sample Program

A sample CSIM program follows. This program is a model of an M/M/1 queueing system. The process sim includes a for loop, which generates, at appropriate intervals (exponentially distributed with mean IATM) arriving customers. These customers contend for the facility on a first-come-first-served basis. As each customer gains exclusive use of the facility, they delay for a service period (again exponentially distributed, but with mean SVTM) and then depart. The individual response times (time of arrival to time of departure) are collected in a table. The program also makes use of the histogram feature to collect the frequency distribution of the queue length.

Sample Program to Simulate Single Server Facility
/* simulate an M/M/1 queue
(an open queue with exponential service times and interarrival intervals)
*/

#include csim.h
#include <stdio.h>

#define SVTM 1.0 /* mean of service time distribution */
#define IATM 2.0 /* mean of inter-arrival time distribution */
#define NARS 5000 /* number of arrivals to be simulated*/

FACILITY f; /* pointer for facility */
EVENT done; /* pointer for counter */
TABLE tbl; /* pointer for table */
QTABLE qtbl; /* pointer for qhistogram */
int cnt; /* number of active tasks*/
FILE *fp;

void init();
void generateCustomers();
void cust();

void sim() /* 1st process - named sim */
{

init(); /* initialize file, model */
create(sim); /* required create statement */
generateCustomers(); /* invoke process to generate customers */
wait(done); /* wait until all done */
report(); /* print report */
mdlstat(); /* print operational statistics */

}

void generateCustomers()
{

int i;

create(gen); /* create statement */
for(i = 1; i <= NARS; i++) {

hold(exponential(IATM)); /* hold interarrival */
cust(); /* initiate process cust */

}

}

void cust() /* process customer */
{

TIME t1;

create(cust); /* create statement */

t1 = clock; /* time of arrival */
note_entry(qtbl); /* note arrival */
reserve(f); /* reserve facility f */
hold(exponential(SVTM));/* hold service time */
release(f); /* release facility f */
record(clock-t1, tbl); /* record response time */
note_exit(qtbl); /* note departure */
cnt--; /* decrement cnt */
if(cnt == 0)
set(done); /*if last arrival, signal done*/

}

void init()
{

fp = fopen(csim.out, w);
set_output_file(fp);
set_trace_file(fp);
set_error_file(fp);
set_model_name(M/M/1 Queue);

f = facility(facility); /* initialize facility */
done = event(done); /* initialize event */
tbl = table(resp tms); /* initialize table */
qtbl = qhistogram(num in sys, 10l); /* initialize qhistogram */
cnt = NARS; /* initialize cnt */

}

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