-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab4_2_MM2.m
81 lines (67 loc) · 1.76 KB
/
lab4_2_MM2.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
77
78
79
80
81
clc;
clear all;
close all;
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 = (lambda+m1)/(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 1 > 0
time = time + 1;
if mod(time,1000) == 0
for i=1:1:4
P(i) = arrivals(i)/total_arrivals;
endfor
delay_counter = 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.0001
break;
endif
previous_mean_clients = mean_clients;
endif
random_number = rand(1);
if current_state == 0
current_state = 1;
arrivals(1) = arrivals(1) + 1;
total_arrivals = total_arrivals + 1;
elseif current_state == 1
if random_number < threshold_1a
current_state = 3;
arrivals(2) = arrivals(2) + 1;
total_arrivals = total_arrivals + 1;
else
current_state = 0;
endif
elseif current_state == 2
if random_number < threshold_1b
current_state = 3;
arrivals(3) = arrivals(3) + 1;
total_arrivals = total_arrivals + 1;
else
current_state = 0;
endif
else
if random_number < threshold_2_first
arrivals(4) = arrivals(4) + 1;
total_arrivals = total_arrivals + 1;
elseif random_number < threshold_2_second
current_state = 2;
else
current_state = 1;
endif
endif
endwhile
display(P(1));
display(P(2));
display(P(3));
display(P(4));