Sie sind auf Seite 1von 7

Objective:

1. To know about modeling and simulation 2. To know about single server queuing model 3. To learn about single server queuing system implementation

Theory:
Queuing theory Queuing theory deals with problems which involve queuing (or waiting). Typical examples might be:
y y y y

banks/supermarkets - waiting for service computers - waiting for a response failure situations - waiting for a failure to occur e.g. in a piece of machinery public transport - waiting for a train or a bus

As we know queues are a common every-day experience. Queues form because resources are limited. In fact it makes economic sense to have queues. For example how many supermarket tills you would need to avoid queuing? How many buses or trains would be needed if queues were to be avoided/eliminated? In designing queueing systems we need to aim for a balance between service to customers (short queues implying many servers) and economic considerations (not too many servers). In essence all queuing systems can be broken down into individual sub-systems consisting of entities queuing for some activity (as shown below).

Typically we can talk of this individual sub-system as dealing with customers queuing for service. To analyse this sub-system we need information relating to:
y

arrival process: o how customers arrive e.g. singly or in groups (batch or bulk arrivals) o how the arrivals are distributed in time (e.g. what is the probability distribution of time between successive arrivals (the interarrival time distribution)) o whether there is a finite population of customers or (effectively) an infinite number

The simplest arrival process is one where we have completely regular arrivals (i.e. the same constant time interval between successive arrivals). A Poisson stream of arrivals corresponds to arrivals at random. In a Poisson stream successive customers arrive after intervals which independently are exponentially distributed. The Poisson stream is important as it is a convenient mathematical model of many real life queuing systems and is described by a single parameter - the average arrival rate. Other important arrival processes are scheduled arrivals; batch arrivals; and time dependent arrival rates (i.e. the arrival rate varies according to the time of day).
y

service mechanism: o a description of the resources needed for service to begin o how long the service will take (the service time distribution) o the number of servers available o whether the servers are in series (each server has a separate queue) or in parallel (one queue for all servers) o whether preemption is allowed (a server can stop processing a customer to deal with another "emergency" customer) Assuming that the service times for customers are independent and do not depend upon the arrival process is common. Another common assumption about service times is that they are exponentially distributed.

queue characteristics: o how, from the set of customers waiting for service, do we choose the one to be served next (e.g. FIFO (first-in first-out) - also known as FCFS (first-come first served); LIFO (last-in first-out); randomly) (this is often called the queue discipline) o do we have:  balking (customers deciding not to join the queue if it is too long)  reneging (customers leave the queue if they have waited too long for service)  jockeying (customers switch between queues if they think they will get served faster by so doing)  a queue of finite capacity or (effectively) of infinite capacity Changing the queue discipline (the rule by which we select the next customer to be served) can often reduce congestion. Often the queue discipline "choose the customer with the lowest service time" results in the smallest value for the time (on average) a customer spends queuing.

Code:
#include<stdio.h> #include<math.h> #include<stdlib.h> #include"lcgrand.h" #define MODLUS 2147483647

#define #define #define #define #define #define #define #define int

MULT1 24112 MULT2 26143 MODLUS 2147483647 MULT1 24112 MULT2 26143 Q_LIMIT 100 BUSY 1 IDLE 0

next_event_type, num_custs_delayed, num_delays_required, num_events, num_in_q, server_status; float area_num_in_q, area_server_status, mean_interarrival, mean_service, sim_time, time_arrival[Q_LIMIT + 1], time_last_event, time_next_event[3], total_of_delays; FILE *infile; void void void void void void float initialize(void); timing(void); arrive(void); depart(void); report(void); update_time_avg_stats(void); expon(float mean);

int main() { clrscr(); infile = fopen("mm1.in", num_events = 2;

"r");

fscanf(infile, "%f %f %d", &mean_interarrival, &mean_service, &num_delays_required); printf("Single-server queueing system\n\n"); printf("Mean interarrival time%11.3f minutes\n\n",mean_interarrival); printf("Mean service time%16.3f minutes\n\n", mean_service); printf("Number of customers%14d\n\n", num_delays_required); initialize(); while (num_custs_delayed < num_delays_required) { timing(); update_time_avg_stats(); switch (next_event_type) { case 1: arrive(); break; case 2: depart(); break; } } report(); fclose(infile); getch();

} void initialize(void) sim_time = 0.0; server_status = IDLE; num_in_q = 0; time_last_event = 0.0; num_custs_delayed total_of_delays area_num_in_q area_server_status = = = = 0; 0.0; 0.0; 0.0;

time_next_event[1] = sim_time + expon(mean_interarrival); time_next_event[2] = 1.0e+30; } void timing(void) { int i; float min_time_next_event = 1.0e+29; next_event_type = 0;

for (i = 1; i <= num_events; ++i) if (time_next_event[i] < min_time_next_event) { min_time_next_event = time_next_event[i]; next_event_type = i; } if (next_event_type == 0) {

printf("\nEvent list empty at time %f", sim_time); exit(1); } sim_time = min_time_next_event; } void arrive(void) { float delay;

time_next_event[1] = sim_time + expon(mean_interarrival);

if (server_status == BUSY) { ++num_in_q;

if (num_in_q > Q_LIMIT) { printf("\nOverflow of the array time_arrival at"); printf(" time %f", sim_time); exit(2); } time_arrival[num_in_q] = sim_time; } else { delay = 0.0; total_of_delays += delay; ++num_custs_delayed; server_status = BUSY;

time_next_event[2] = sim_time + expon(mean_service); } } void depart(void) { int i; float delay;

if (num_in_q == 0) {

server_status = IDLE; time_next_event[2] = 1.0e+30; } else { --num_in_q;

delay = sim_time - time_arrival[1]; total_of_delays += delay;

++num_custs_delayed; time_next_event[2] = sim_time + expon(mean_service); for (i = 1; i <= num_in_q; ++i) time_arrival[i] = time_arrival[i + 1]; } }

void report(void) { printf("\n\nAverage delay in queue%11.3f minutes\n\n", total_of_delays / num_custs_delayed); printf("Average number in queue%10.3f\n\n", area_num_in_q / sim_time); printf("Server utilization%15.3f\n\n", area_server_status / sim_time); printf("Time simulation ended%12.3f minutes", sim_time); } void update_time_avg_stats(void) { float time_since_last_event;

time_since_last_event = sim_time - time_last_event; time_last_event = sim_time;

area_num_in_q

+= num_in_q * time_since_last_event;

area_server_status += server_status * time_since_last_event; } float expon(float mean) { return -mean * log(lcgrand(1)); } staticlong zrng[] = { 1, 1973272912, 281629770, 20006270,1280689831,2096730329,1933576050, 913566091, 246780520,1363774876, 604901985,1511192140,1259851944, 824064364, 150493284, 242708531, 75253171,1964472944,1202299975, 233217322,1911216000, 726370533, 403498145, 993232223,1103205531, 762430696,1922803170,1385516923, 76271663, 413682397, 726466604, 336157058,1432650381,1120463904, 595778810, 877722890,1046574445, 68911991,2088367019, 748545416, 622401386,2122378830, 640690903, 1774806513,2132545692,2079249579, 78130110, 852776735,1187867272, 1351423507,1645973084,1997049139, 922510944,2045512870, 898585771, 243649545,1004818771, 773686062, 403188473, 372279877,1901633463, 498067494,2087759558, 493157915, 597104727,1530940798,1814496276, 536444882,1663153658, 855503735, 67784357,1432404475, 619691088, 119025595, 880802310, 176192644,1116780070, 277854671,1366580350, 1142483975,2026948561,1053920743, 786262391,1792203830,1494667770, 1923011392,1433700034,1244184613,1147297105, 539712780,1545929719, 190641742,1645390429, 264907697, 620389253,1502074852, 927711160, 364849192,2049576050, 638580085, 547070247 }; float lcgrand(int stream) { long zi, lowprd, hi31;

zrng[stream]; (zi & 65535) * MULT1; (zi >> 16) * MULT1 + (lowprd >> 16); ((lowprd & 65535) - MODLUS) + ((hi31 & 32767) << 16) + (hi31 >> 15); if (zi < 0) zi += MODLUS; lowprd = (zi & 65535) * MULT2; hi31 = (zi >> 16) * MULT2 + (lowprd >> 16); zi = ((lowprd & 65535) - MODLUS) + ((hi31 & 32767) << 16) + (hi31 >> 15); if (zi < 0) zi += MODLUS; zrng[stream] = zi; return (zi >> 7 | 1) / 16777216.0; }

zi lowprd hi31 zi

= = = =

Discussion:

In our last laboratory session we became familiar with the simulation of a single server queuing system. Now we are able to implement the single server queuing system in C program. But it was really a hard work for us to implement it. In fine we can say that our last lab was successful.

Das könnte Ihnen auch gefallen