Capsim Block Documentation
This star models an M/M/1 queue
int i,j; int samples; float sampleOut; float x; float arrivalInterval; float minTimeNextEvent; float timeSinceLastEvent; float delay; |
---|
/* * store as state the number of input/output buffers */ if((ibufs = NO_INPUT_BUFFERS()) < 1) { fprintf(stderr,"server: no input buffers\n"); return(2); } if((obufs = NO_OUTPUT_BUFFERS()) < 1) { fprintf(stderr,"server: no output buffers\n"); return(3); } /* * Get seeds from expression */ phrtsd(expression,&seed1,&seed2); fprintf(stderr,"server: seed1=%d seed2=%d\n",seed1,seed2); setall(seed1,seed2); /* * Specify the number of events for the timing function */ numberEvents=3; time=0.0; serverStatus=IDLE; numberInQ = 0; timeLastEvent=0.0; /* * Initialize statistical counters */ numberCustomersDelayed =0; totalOfDelays=0.0; areaNumberInQ=0.0; areaServerStatus=0.0; /* * Initialize event list. Since no customers are present * the departure (service completion) event is eliminated * from consideration. The end-simulation event type (type 3) is * scheduled for time timeEnd. */ timeNextEvent_A[1] = time; timeNextEvent_A[2] = INFINITY; timeNextEvent_A[3]= timeEnd; |
---|
/* * read one sample from each input buffer */ for(samples = MIN_AVAIL(); samples >0; --samples) { /* * get a customer and arrival interval * from input buffer */ for(i=0; i |
---|
/* * Report results */ fprintf(stderr,"Single-server queueing system \n"); fprintf(stderr,"Mean service time %f \n", meanServiceTime); fprintf(stderr,"\n\nAverage delay in queue %11.3f minutes\n\n", totalOfDelays/numberCustomersDelayed); fprintf(stderr,"Average number in queue %10.3f\n\n", areaNumberInQ/time); fprintf(stderr,"Server utilization %15.3f\n\n", areaServerStatus/time); fprintf(stderr,"Number of delays completed %7d\n", numberCustomersDelayed); |
---|
/* Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks) Copyright (C) 1989-2017 Silicon DSP Corporation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA http://www.silicondsp.com Silicon DSP Corporation Las Vegas, Nevada */ |
---|
/* server.s */ /********************************************************************** server() *********************************************************************** This star models an M/M/1 queue The input buffer is the customer inter arrival times. Thus, each sample on the input buffer represents the arrival of a customer. The value of the sample is the customer inter arrival time. The server places the customer in a queue if necessary and processes the next available customer. The server does not need to output anything but we have chosen to output the current delay in the queue. Thus by connecting the output of the server star to the plot star, you can observe the delay in the queue over time. Many other output combinations are possible but this star is used to serve as an example. The server star implements the C code in "Simulation Modeling and Analysis" by Averill M. Law and W. David Kelton, Second Edition 1991. We have included original comments. The parameters are: (1) The type of distribution for the server (2) The mean service time (3) An expression for the random number generator seeds. (4) The time to end the simulation Notes: (1) The simulation will end when there are no more customers. However, the simulation can end using parameter 4 as a condition. (2) Presently, parameter 1 is ignored and exponential distribution is used. The input buffers are arbitrary so that in the future multiple customer sources may be modeled with a single server. The number of input buffers is arbitrary and determined at run time. The number of output buffers is also arbitrary (auto-fanout). |
---|