-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab04_2_uneven_servers.m
76 lines (65 loc) · 1.55 KB
/
Lab04_2_uneven_servers.m
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
clc;
clear all;
close all;
pkg load queueing;
lambda = 1;
m1 = 0.8;
m2 = 0.4;
threshold_1a = lambda/(lambda+m1);
threshold_1b = lambda/(lambda+m2);
threshold_2_first = lambda/(lambda+m1+m2);
threshold_2_second = (m1+lambda)/(lambda+m1+m2);
current_state = 0;
arrivals = zeros(1,4);
total_arrivals = 0;
maximum_state_capacity = 2;
previous_mean_clients = 0;
delay_counter = 0;
time = 0;
while true
if mod(++time,1000) == 0
for i=1:1:4
P(i) = arrivals(i)/total_arrivals;
endfor
delay_counter += 1;
mean_clients = 0*P(1) + 1*P(2) + 1*P(3) + 2*P(4);
delay_table(delay_counter) = mean_clients;
if abs(mean_clients - previous_mean_clients) < 0.00001
break;
endif
previous_mean_clients = mean_clients;
endif
random_number = rand(1);
if current_state == 0
current_state = 1;
arrivals(1) += 1;
total_arrivals += 1;
elseif current_state == 1
if random_number < threshold_1a
current_state = 3;
arrivals(2) += 1;
total_arrivals += 1;
else
current_state = 0;
endif
elseif current_state == 2
if random_number < threshold_1b
current_state = 3;
arrivals(3) += 1;
total_arrivals += 1;
else
current_state = 0;
endif
else
if random_number < threshold_2_first
arrivals(4) += 1;
total_arrivals += 1;
elseif random_number < threshold_2_second
current_state = 2;
else
current_state = 1;
endif
endif
endwhile
printf("P(1) = %d\nP(2) = %d\n", P(1),P(2));
printf("P(3) = %d\nP(4) = %d\n", P(3),P(4));