bs_selection_algorithm.ipynb
4.98 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
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Unnamed: 0 gridID Internet Activity Prediction\n",
"0 0 1 9952.919155\n",
"1 0 2 10007.809479\n",
"2 0 3 12864.899626\n"
]
}
],
"source": [
"import pandas as pd\n",
"df = pd.read_csv('predictions.csv')\n",
"#sort internet activity prediction\n",
"df.sort_values(by=['Internet Activity Prediction'],inplace=True)\n",
"print(df)\n"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"g1 cache remainder size 137\n",
"g2 cache remainder size 582\n",
"g3 cache remainder size 867\n",
"contents size 821\n",
"[[3, 867]]\n"
]
}
],
"source": [
"from random import seed\n",
"from random import randint\n",
"seed(1)\n",
"g1_cache=randint(0,1000)\n",
"g2_cache=randint(0,1000)\n",
"g3_cache=randint(0,1000)\n",
"\n",
"contents_cache=randint(0,1000)\n",
"\n",
"print(\"g1 cache remainder size\" , g1_cache)\n",
"print(\"g2 cache remainder size\" ,g2_cache)\n",
"print(\"g3 cache remainder size\" ,g3_cache)\n",
"print(\"contents size\" ,contents_cache)\n",
"\n",
"l_bs_cache=[]\n",
"if(contents_cache<g1_cache):\n",
" arr=[1,g1_cache]\n",
" l_bs_cache.append(arr)\n",
"if(contents_cache<g2_cache):\n",
" arr=[2,g2_cache]\n",
" l_bs_cache.append(arr)\n",
"if(contents_cache<g3_cache):\n",
" arr=[3,g3_cache]\n",
" l_bs_cache.append(arr)\n",
"\n",
"print(l_bs_cache)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1, 9.18594536053351, 45.47304470082458]\n",
"[2, 9.193139700323409, 45.46987577194055]\n",
"[3, 9.195377006955539, 45.46770952221271]\n"
]
}
],
"source": [
"import random\n",
"import sys\n",
"import math\n",
"#milan lat,lon\n",
"latitude = 45.4654219\n",
"longitude = 9.1859243\n",
"bs_locations=[]\n",
"def generate_random_data(lat, lon):\n",
" for i in range(1,4):\n",
" dec_lat = random.random()/100\n",
" dec_lon = random.random()/100\n",
" arr=[i, lon+dec_lon, lat+dec_lat]\n",
" print(arr)\n",
" bs_locations.append(arr)\n",
"\n",
"generate_random_data(latitude, longitude)\n"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(9.194398637369373, 45.466765542441124)\n",
"[[3, 0.1499061393976395, 867]]\n",
" gridID distance internet traffic prediction\n",
"0 3 0.149906 867\n",
"0.1499061393976395\n",
"bs selection result: 3\n"
]
}
],
"source": [
"import geopy.distance\n",
"seed(1)\n",
"dec_lat = random.random()/100\n",
"dec_lon = random.random()/100\n",
"request_location=(longitude+dec_lon, latitude+dec_lat)\n",
"print(request_location)\n",
"\n",
"bs_distances=[]\n",
"for bs in l_bs_cache:\n",
" grid_num=bs[0]\n",
" for l in bs_locations:\n",
" if(l[0]==grid_num):\n",
" coords_1=(l[1],l[2])\n",
" dist=geopy.distance.geodesic(coords_1, request_location).km\n",
" arr=[grid_num,dist,bs[1]]\n",
" bs_distances.append(arr)\n",
"#[gridID, distance, traffic]\n",
"print(bs_distances)\n",
"\n",
"#sort bs_distances\n",
"col=['gridID','distance','internet traffic prediction']\n",
"df=pd.DataFrame(bs_distances, columns=col)\n",
"df.sort_values(by=['distance'], inplace=True)\n",
"print(df)\n",
"\n",
"min_value=df['distance'][0]\n",
"grid_num=df['gridID'][0]\n",
"print(min_value)\n",
"count_row=df.shape[0]\n",
"for x in range(count_row):\n",
" if(df.loc[x]['distance']<min_value):\n",
" min_value=df.loc[x]['distance']\n",
" grid_num=df.loc[x]['gridID']\n",
" \n",
"print(\"bs selection result: \",grid_num)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}