Repository navigation
Expand file tree
/
Copy pathbackup.tar
More file actions
executable file
·1138 lines (973 loc) · 43.5 KB
/
Copy pathbackup.tar
File metadata and controls
executable file
·1138 lines (973 loc) · 43.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
qnsim-ss.c 0100600 0000062 0000062 00000025624 06332465655 0012626 0 ustar 00rljones 0000040 0000021 /******************************************************************************
* Module: qnsim-ss.c *
* *
* Author: Rob Jones *
* *
* Purpose: CSci 726 Discrete-Event Simulation: PROJECT #3 *
* Provides main simulation program for a general-purpose *
* STEADY-STATE SIMULATION of a queuing network consisting *
* of single server nodes. *
* *
* Version: 5-02-97 *
* *
* Note: Even though this simulator is capable of simulating an *
* open or closed queuing network, the statistics are currently *
* applicable for an open network and are referrenced to node 0. *
* Also, the within-batch sample index (count) is counting the *
* number of departures from network. If a closed network is *
* simulated without using a reference other than node 0, the *
* simulation will not terminate. *
* *
*******************************************************************************/
#include "qnet.h"
#include "queue.h"
#include "misc.h"
/* SIMULATION PARAMETERS: */
#define MAX_BATCHES 1000 /* maximum number of batches */
#define BATCH_SIZE 1000 /* batch size (must be > 1) */
#define INTERVAL_WIDTH 0.05 /* interval half width in percent */
#define LOC 0.95 /* level of confidence */
#define INFINITY 1e300 /* a large number */
double *future_events; /* future-events list */
void ProcessArrival(long i, double time)
/******************************************************************************
Auxilary function used to service the arrival of a job to node 'i' at the
current 'time' if the node is idle, otherwise the job is put into the queue.
If the job is serviced, the job's departure is also scheduled.
*******************************************************************************/
{
extern rv_func *random_time; /* sample function */
extern actvty *status; /* server status */
extern queue_type *queue; /* service queue */
double job_time = 0; /* job service time */
if (status[i] == IDLE) { /* if idle then service job */
status[i] = BUSY;
SelectStream(i);
future_events[i] = time + random_time[i].func();
} else { /* otherwise, add job to queue */
#ifdef SJF_QUEUE /* if SJF then sample/store service time */
SelectStream(i);
job_time = random_time[i].func();
#endif
Insert(&queue[i],job_time);
}
}
void ServiceJob(long i, double time)
/******************************************************************************
Auxilary function used to service the next job in the queue of node 'i' at
the current 'time' thereby scheduling the departure of the job.
*******************************************************************************/
{
extern rv_func *random_time; /* sample function */
extern actvty *status; /* server status */
extern queue_type *queue; /* service queue */
double job_time = 0; /* job service time */
Remove(&queue[i],&job_time);
#ifdef SJF_QUEUE /* if SJF then service time is already stored */
future_events[i] = time + job_time;
#else /* otherwise sample service-time function */
SelectStream(i);
future_events[i] = time + random_time[i].func();
#endif
status[i] = BUSY;
}
int main(void)
/******************************************************************************
MAIN PROGRAM
*******************************************************************************/
{
extern qnt type; /* either OPEN or CLOSED */
extern int num_nodes; /* number of service nodes */
extern rv_func *random_time; /* service time random variate functions */
extern queue_type *queue; /* queue for each service node */
extern actvty *status; /* status of each server: {IDLE,BUSY} */
int node; /* service node index */
double clock; /* current simulation time */
double prev_clock; /* previous sim time */
double init_clock; /* time at start of batch */
long i, j; /* general-purpose indices */
long batch; /* batch index */
long count; /* sample counter within a batch */
long current, next; /* service node indices */
long seed = 123456789; /* random number seed */
long n; /* number of samples */
double u = 1.0 - 0.5*(1.0 - LOC); /* interval parameter */
double s, t, diff; /* used to compute interval estimate */
long num_arrivals = 0; /* counts # of external job arrivals */
long num_jobs = 0; /* total number of jobs in system */
double arrival_rate; /* average external arrival rate */
double area_number; /* time-averaged number of jobs in system */
double mean_num_jobs = 0.0; /* E[number of jobs in system] */
double sumsqr_num_jobs = 0.0; /* sum of squares to compute variance */
double w; /* confidence interval half width */
/*=============================*/
long jobs;
long num = 0;
long events;
double mean = 0.0;
double sumsqr = 0.0;
double ww;
/*=============================*/
/* initialize */
Network(); /* get specification of queuing network */
Init(); /* initialize of network data structures */
/* create future-event list */
future_events = (double *)calloc(num_nodes,sizeof(double));
if (future_events == NULL) {
error(MEM_ERR);
}
PlantSeeds(seed);
Initialize(); /* set the initial state of network */
clock = 0.0;
/* schedule first events */
if (type == OPEN) {
SelectStream(0);
future_events[0] = random_time[0].func();
} else {
future_events[0] = INFINITY;
}
for (i = 1; i < num_nodes; i++) {
if (IsEmpty(&queue[i]) == FALSE) {
num_jobs += Number(&queue[i]);
ServiceJob(i,clock);
} else {
status[i] = IDLE;
future_events[i] = INFINITY;
}
}
/* begin simulation */
for (batch = 1; batch <= MAX_BATCHES; batch++) {
/* re-initialize the statistics only */
init_clock = clock;
prev_clock = clock;
area_number = 0.0;
count = 0;
/*=====================================*/
jobs = 0;
events = 0;
/*=====================================*/
while (count < BATCH_SIZE) {
/* get next (most imminent) event */
current = 0;
for (j = 0; j < num_nodes; j++) {
if (future_events[j] < future_events[current]) {
current = j;
}
}
clock = future_events[current]; /* advance the clock */
/* if event was an outside arrival then schedule a new one */
if (current == 0) {
SelectStream(0);
future_events[current] = clock + random_time[current].func();
area_number += num_jobs*(clock - prev_clock);
prev_clock = clock;
num_arrivals++;
num_jobs++; /* one more job in system */
} else { /* process the departure */
if (IsEmpty(&queue[current]) == FALSE) {
ServiceJob(current,clock); /* service next job in queue */
} else {
status[current] = IDLE;
future_events[current] = INFINITY;
}
}
/* place job in a destination service node */
next = GetNextNode(current);
if (next == 0) { /* if departure from system then */
area_number += num_jobs*(clock - prev_clock);
prev_clock = clock;
count++;
num_jobs--; /* one less job in system */
} else {
ProcessArrival(next,clock);
}
#ifdef METHOD1
/* compute mean number of jobs in system */
diff = num_jobs - mean_num_jobs;
sumsqr_num_jobs += diff*diff*(batch - 1.0)/batch;
mean_num_jobs += diff/batch;
#endif
} /*end while*/
#ifdef METHOD2
/* compute mean number of jobs in system */
diff = area_number/(clock-init_clock) - mean_num_jobs;
sumsqr_num_jobs += diff*diff*(batch - 1.0)/batch;
mean_num_jobs += diff/batch;
#endif
/* to reduce some overhead, check on how we're doing every 10 samples */
if (batch % 10 == 0) {
n = batch; /* the number of samples */
t = idfStudent(n - 1,u); /* critical value of t */
s = sqrt(sumsqr_num_jobs/n); /* standard deviation */
w = t*s/sqrt(n - 1); /* interval half width */
if (w/mean_num_jobs <= INTERVAL_WIDTH) {
break; /* exit for loop when desired interval is achieved */
}
}
/*=================================================*/
#ifdef DEBUG
printf("%ld \t",batch);
printf("%f \t",area_number/(clock-init_clock));
printf("%f \n",area_number/count);
#endif
/*=================================================*/
}/* end for */
/* print results */
#ifndef DEBUG
/*
* need to compute width if "for loop" was exited
* because the maximum number of batched were reached
*/
if (batch > MAX_BATCHES) {
n = MAX_BATCHES; /* the number of samples */
t = idfStudent(n - 1,u); /* critical value of t */
s = sqrt(sumsqr_num_jobs/n); /* standard deviation */
w = t*s/sqrt(n - 1);
}
arrival_rate = num_arrivals/clock;
printf("\nSteady-State Simulation\n");
printf(" sample points......: %ld\n",n);
printf(" confidence level...: %g%%\n",LOC*100.0);
printf(" confidence interval: +/- %g%%\n",INTERVAL_WIDTH*100.0);
if (w/mean_num_jobs > INTERVAL_WIDTH) {
printf("\nMeasures did not reach desired interval width.\n");
}
printf("\n");
printf("Expected number of jobs in the system: %.4f +/- %.4f\n",
mean_num_jobs, w);
printf("Expected wait time of a job..........: %.4f +/- %.4f\n",
mean_num_jobs/arrival_rate, w/arrival_rate);
#endif /* endif DEBUG */
return(0);
}
the *
* simulation will not terminate. *
* qnsim-ts.c 0100600 0000062 0000062 00000023311 06332461226 0012604 0 ustar 00rljones 0000040 0000021 /******************************************************************************
* Module: qnsim-ts.c *
* *
* Author: Rob Jones *
* *
* Purpose: CSci 726 Discrete-Event Simulation: PROJECT #3 *
* Provides main simulation program for a general-purpose *
* TRANSIENT-STATE SIMULATION of a queuing network consisting *
* of single server nodes. *
* *
* Version: 5-02-97 *
*******************************************************************************/
#include "qnet.h"
#include "queue.h"
#include "misc.h"
/* SIMULATION PARAMETERS: */
#define MAX_REPLICATIONS 1000 /* max number of replications */
#define MAX_EVENTS 100000 /* maximum events per replication */
#define LOC 0.95 /* level of confidence */
#define PREC 1.0e-2 /* for rounding data to 1/1000 */
#define INFINITY 1e300 /* a large number */
double *future_events; /* future-events list */
void ProcessArrival(long i, double time)
/******************************************************************************
Auxilary function used to service the arrival of a job to node 'i' at the
current 'time' if the node is idle, otherwise the job is put into the queue.
If the job is serviced, the job's departure is also scheduled.
*******************************************************************************/
{
extern rv_func *random_time; /* sample function */
extern actvty *status; /* server status */
extern queue_type *queue; /* service queue */
double job_time = 0; /* job service time */
if (status[i] == IDLE) { /* if idle then service job */
status[i] = BUSY;
SelectStream(i);
future_events[i] = time + random_time[i].func();
} else { /* otherwise, add job to queue */
#ifdef SJF_QUEUE /* if SJF then sample/store service time */
SelectStream(i);
job_time = random_time[i].func();
#endif
Insert(&queue[i],job_time);
}
}
void ServiceJob(long i, double time)
/******************************************************************************
Auxilary function used to service the next job in the queue of node 'i' at
the current 'time' thereby scheduling the departure of the job.
*******************************************************************************/
{
extern rv_func *random_time; /* sample function */
extern actvty *status; /* server status */
extern queue_type *queue; /* service queue */
double job_time = 0; /* job service time */
Remove(&queue[i],&job_time);
#ifdef SJF_QUEUE /* if SJF then service time is already stored */
future_events[i] = time + job_time;
#else /* otherwise sample service-time function */
SelectStream(i);
future_events[i] = time + random_time[i].func();
#endif
status[i] = BUSY;
}
int main(void)
/******************************************************************************
MAIN PROGRAM
/******************************************************************************
*******************************************************************************/
{
extern qnt type; /* either OPEN or CLOSED */
extern int num_nodes; /* number of service nodes */
extern rv_func *random_time; /* service time random variate functions */
extern queue_type *queue; /* queue for each service node */
extern actvty *status; /* status of each server: {IDLE,BUSY} */
int node; /* service node index */
double clock; /* current simulation time */
long i, j; /* general-purpose indices */
long index; /* replication index */
long current, next; /* service node indices */
long seed = 123456789; /* random number seed */
long n; /* number of samples */
double u = 1.0 - 0.5*(1.0 - LOC); /* interval parameter */
double s, t, diff; /* used to compute interval estimate */
long num_arrivals = 0; /* counts # of external job arrivals */
long num_departures = 0; /* counts # of external job departures */
long num_jobs; /* total number of jobs in system */
double arrival_rate; /* average external arrival rate */
double departure_rate; /* average external departure rate */
double mean_arrivals = 0.0; /* mean # of arrivals until steady state */
double sumsqr_arrivals = 0.0; /* sum of squares to compute variance */
double w; /* confidence interval half width */
/* initialize */
Network(); /* get specification of queuing network */
Init(); /* initialize of network data structures */
/* create future-event list */
future_events = (double *)calloc(num_nodes,sizeof(double));
if (future_events == NULL) {
error(MEM_ERR);
}
/* begin simulation */
for (index = 1; index <= MAX_REPLICATIONS; index++) {
/* re-initialize the state and statistics for each replication */
/* pick a different seed for each replication */
SelectStream(0); GetSeed(&seed); PlantSeeds(seed);
Initialize(); /* reset the initial state of network */
clock = 0.0;
num_arrivals = 0;
num_departures = 0;
arrival_rate = 0.0; /* to get started, make arrival rate */
departure_rate = 1.0; /* different from departure_rate */
/* schedule first events */
if (type == OPEN) {
SelectStream(0);
future_events[0] = random_time[0].func();
} else {
future_events[0] = INFINITY;
}
num_jobs = 0;
for (i = 1; i < num_nodes; i++) {
if (IsEmpty(&queue[i]) == FALSE) {
num_jobs += Number(&queue[i]);
ServiceJob(i,clock);
} else {
status[i] = IDLE;
future_events[i] = INFINITY;
}
}
/*
* To estimate the number of external arrivals before the network
* reaches steady state, the stopping criteria "flow in = flow out"
* will be used. To do the comparison, the average arrival rate
* and average departure rate are both rounded to 1/100 precision.
*/
while ((arrival_rate != departure_rate) && (num_arrivals < MAX_EVENTS)) {
/* get next (most imminent) event */
current = 0;
for (j = 0; j < num_nodes; j++) {
if (future_events[j] < future_events[current]) {
current = j;
}
}
clock = future_events[current]; /* advance the clock */
/* if event was an outside arrival then schedule a new one */
if (current == 0) {
SelectStream(0);
future_events[current] = clock + random_time[current].func();
num_arrivals++;
num_jobs++; /* one more job in system */
} else { /* process the departure */
if (IsEmpty(&queue[current]) == FALSE) {
ServiceJob(current,clock); /* service next job in queue */
} else {
status[current] = IDLE;
future_events[current] = INFINITY;
}
}
/* place job in a destination service node */
next = GetNextNode(current);
if (next == 0) { /* if departure from system then */
num_departures++;
num_jobs--; /* one less job in system */
} else {
ProcessArrival(next,clock);
}
/* compute/round arrival/departure rates */
arrival_rate = (double)num_arrivals/clock;
arrival_rate = (double)(((long)(arrival_rate/PREC + 0.5))*PREC);
departure_rate = (double)num_departures/clock;
departure_rate = (double)(((long)(departure_rate/PREC + 0.5))*PREC);
/*======================================================*/
#ifdef DEBUG
printf("%ld \t %ld \t %f \t %f \t",
num_arrivals,num_departures,arrival_rate,departure_rate);
printf("[%ld:%ld:%ld:%ld:%ld]",
Number(&queue[1]),
Number(&queue[2]),
Number(&queue[3]),
Number(&queue[4]),
Number(&queue[5]));
printf("\t %ld",index);
printf("\t %f",mean_arrivals);
printf("\n");
#endif
/*======================================================*/
} /*end while*/
if (num_arrivals == MAX_EVENTS) {
error("Maximum number of events was reached!\n");
exit(1);
}
/* compute mean number of external arrivals until steady state */
diff = num_arrivals - mean_arrivals;
sumsqr_arrivals += diff*diff*(index - 1.0)/index;
mean_arrivals += diff/index;
}/* end for */
/* print results */
n = index-1; /* the number of samples */
t = idfStudent(n - 1,u); /* critical value of t */
s = sqrt(sumsqr_arrivals/n); /* standard deviation */
w = t*s/sqrt(n - 1); /* interval half width */
#ifndef DEBUG
printf("\nTransient Simulation:\n\n");
printf("Expected time to steady state: %.4f +/- %.4f\n\n",
mean_arrivals,w);
#endif
return(0);
}
e, otherwise the job is put into the queue.
If the job is serviced, the job's departure is also scheduled.
*******************************************************************************/
{
extern rv_func *random_time; /* sample function */
extern actvty *status; /* server status */
qnet.c 0100600 0000062 0000062 00000014646 06332414661 0012014 0 ustar 00rljones 0000040 0000021 /******************************************************************************
* Module: qnet.c *
* *
* Author: Rob Jones *
* *
* Purpose: CSci 726 Discrete-Event Simulation: PROJECT #3 *
* Provides the data structures and operations for the *
* construction and simulation of a general queuing network. *
* *
* Version: 4-14-97 *
*******************************************************************************/
#include "qnet.h"
#include "queue.h"
#include "misc.h"
/* GLOBAL DATA: */
qnt type = CLOSED; /* assume closed network */
int num_nodes = 0; /* number of service nodes */
queue_type *queue = NULL; /* no. jobs in each service queue */
actvty *status = NULL; /* status of each service node */
double **P = NULL; /* commulative prob matrix */
rv_func *random_time = NULL; /* list of functions that return the */
/* arrival/service time for each node */
char Use_Error[]
= "Must first define the number of nodes with function \"Nodes\"\n";
void Init()
/******************************************************************************
called by main program to initialize data structures
*******************************************************************************/
{
int i, j;
if (num_nodes > 0) {
/* consistency check */
if (type == OPEN && random_time[0].func == NULL) {
error("Must specify an arrival-time function for open networks.");
}
for (i = 1; i <= num_nodes; i++) {
if (random_time[i].func == NULL) {
error("Must specify a service-time function for every service node.");
}
}
/* compute cumulative probabilities across each row of P matrix */
for (i = 0; i < num_nodes; i++) {
for (j = 1; j < num_nodes; j++) {
P[i][j] += P[i][j-1];
}
}
} else { /* function Network was not used properly */
error("Must specify queuing network with function \"Network\".\n");
}
}
void Initialize()
{
long i;
/* empty out each queue */
for (i = 1; i < num_nodes; i++) {
FlushQueue(&queue[i]);
}
/* re-initialize each queue */
InitialState();
}
void Nodes(int n)
/******************************************************************************
declares the number of service nodes and allocates/initializes
the required data structures
*******************************************************************************/
{
int i;
/* constraint checks */
if (n <= 0) {
error("Must declare at least 1 service node.\n");
}
num_nodes = n + 1; /* additional node for external I/O */
/*
* create probability matrix
*/
P = (double **)calloc(num_nodes,sizeof(double *)); /* allocate the rows */
if (P == NULL) {
error(MEM_ERR);
}
for (i = 0; i < num_nodes; i++) { /* allocate the columns */
P[i] = (double *)calloc(num_nodes,sizeof(double));
if (P[i] == NULL) {
error(MEM_ERR);
}
}
/*
* create list of random variate functions to call to compute
* the arrival/service time of each node
* note: calloc initializes random_time[] to NULL
*/
random_time = (rv_func *)calloc(num_nodes,sizeof(rv_func));
if (random_time == NULL) {
error(MEM_ERR);
}
/*
* create list indicating the status of each service node
* note: calloc initializes status[] to IDLE
*/
status = (actvty *)calloc(num_nodes,sizeof(actvty));
if (status == NULL) {
error(MEM_ERR);
}
/*
* create list of pointers to each service queue
*/
queue = (queue_type *)calloc(num_nodes,sizeof(queue_type));
if (queue == NULL) {
error(MEM_ERR);
}
/* initialize each queue */
for (i = 1; i < num_nodes; i++) {
CreateQueue(&queue[i]);
}
}
void Connect(int i, int j, double p)
/******************************************************************************
user function that connects service node 'i' to node 'j' with probability 'p'
*******************************************************************************/
{
if (P != NULL) {
P[i][j] = p;
} else {
error(Use_Error);
}
}
void Arrival(double (*func)())
/******************************************************************************
user function that specifies the external inter-arrival time function
*******************************************************************************/
{
if (random_time != NULL) {
type = OPEN;
random_time[0].func = func;
} else {
error(Use_Error);
}
}
void Service(int i, double (*func)())
/******************************************************************************
user function that assigns a service-time function to node 'i'
*******************************************************************************/
{
if (i <= 0) {
error("Service node identifiers must be greater than zero.");
} else if (random_time == NULL) {
error(Use_Error);
} else {
random_time[i].func = func;
}
}
void Initial(int i, long j)
/******************************************************************************
user function that initializes service node 'i' with 'j' jobs
*******************************************************************************/
{
double job_time = 0; /* job service time */
long k;
if (queue == NULL) {
error(Use_Error);
} else {
#ifdef SJF_QUEUE /* if SJF then sample/store service time */
SelectStream(i);
for (k = 0; k < j; j++) {
job_time = random_time[i].func();
Insert(&queue[i],job_time);
}
#else /* otherwise, just store the number of jobs */
Insert(&queue[i],j);
#endif
}
}
int GetNextNode(int i)
/******************************************************************************
returns the destination node that receives the output of service node 'i'
*******************************************************************************/
{
int j;
double u;
SelectStream(i);
u = Random();
j = 0;
while (u > P[i][j]) {
j++;
}
return(j);
}