Repository navigation
Expand file tree
/
Copy pathsimcore.c
More file actions
executable file
·51 lines (46 loc) · 1.8 KB
/
Copy pathsimcore.c
File metadata and controls
executable file
·51 lines (46 loc) · 1.8 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
GetFeedback()
{
SelectStream(2);
if (Random() < BETA)
return (1);
else
return (0);
}
struct {
double arrival; /* next arrival time */
double completion; /* next completion time */
double current; /* current time */
double next; /* next (most imminent) event time */
double interval; /* time width of batch */
} t;
long *number; /* number in the node */
t.current = 0.0; /* set the clock */
t.arrival = t.current + GetInterarrival(); /* schedule first arrival */
t.completion = INFINITY; /* first event != completion */
t.next = Min(t.arrival, t.completion); /* next event time */
t.current = t.next; /* advance the clock */
if (t.current == t.arrival) { /* process an arrival */
aindex++;
/* store arrival time for this job */
wait[aindex] = t.arrival;
number++;
t.arrival = t.current + GetInterarrival();
if (number == 1)
t.completion = t.current + GetService();
}
else { /* process a completion */
if (GetFeedback())
t.completion = t.current + GetService();
else {
index++;
number--;
/* store wait time for this job */
wait[index] = t.completion - wait[index];
/* Welford's algorithm to compute batch mean of wait times */
aw += (wait[index] - aw)/(++j);
if (number > 0)
t.completion = t.current + GetService();
else
t.completion = INFINITY;
}
}