-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIEEE Task 2.py
74 lines (49 loc) · 1.77 KB
/
IEEE Task 2.py
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
import random
import matplotlib.pyplot as plt
def getLowerandUpper():
lower = round(random.uniform(1, 3), 2)
upper = 0
while (upper <= lower):
upper = round(random.uniform(1, 20), 2)
return lower, upper
base_stations_name = [] # Storing Base Station Names
lower_limit_list = [] # Storing Lower Limit time
upper_limit_list = [] # Storing Upper Limit time
success_list = [] # Storing No. of Successful Itertions
ratios_list = [] # Storing Ratios
n = 10 # No. of Base Stations
total_iterations = 20 # Total Iterations
TIME = 5 # Time Limit for each task
# Assigning Lower Limit, Upper Limit and Name for Base Stations
for i in range(n):
lower, upper = getLowerandUpper()
lower_limit_list.append(lower)
upper_limit_list.append(upper)
base_stations_name.append("BS"+str(i+1))
for i in range(n): # Each Base Station
lower_limit = lower_limit_list[i]
upper_limit = upper_limit_list[i]
success = 0
for j in range(total_iterations): # Each Iteration
current_time = round(random.uniform(lower_limit, upper_limit), 2)
if current_time <= TIME:
success += 1
# Outside inner loop, we know no. of successful iterations
success_list.append(success)
ratios_list.append(success/total_iterations)
# Plotting the graph
# x-coordinates of left sides of bars
left = list(range(1, n+1))
# Heights of bars: ratios_list
# Labels for bars: base_stations_name
# Plotting a Bar Chart
plt.bar(left, ratios_list, tick_label=base_stations_name,
width=0.8, color=["blue"])
# Naming the x-axis
plt.xlabel("Base Stations")
# Naming the y-axis
plt.ylabel("Ratios")
# Plot Title
plt.title("Ratio v/s Base Station Bar Chart")
# function to show the plot
plt.show()