-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_simulation_qlearning.py
More file actions
279 lines (235 loc) · 15.1 KB
/
run_simulation_qlearning.py
File metadata and controls
279 lines (235 loc) · 15.1 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
from create_constants import *
from constants import *
from misc_sim_funcs import *
import os
def run_simulation(DataSet, Day_Or_NumMules, Round, Protocol, Band, t, ts, v, generate_LE, Max_Nodes, pkl_fold_num, perfect_knowledge,src_dst,speed, num_mes, num_chan, num_puser, smart_setting, num_fwd, msg_round, puser_round, msg_mean, ttl, max_mem, replicas, priority_queue_active, routing_opt, wei_param, num_trans, is_boot_round):
# a bunch of variables for the constant file
dir = "DataMules/" # Starting Directory
num_messages = num_mes # not needed anymore
debug_message = 257 # if a certain msg # needs to be debugged put it here and include if statement in area to debug
debug_mode = -1 # same as above but for more general debug purposes
metric_interval = 30 # interval in which metrics should be generated: every "metric interval" tau
limited_time_to_transfer = True # finite resources enabled
restrict_band_access = False # for xchants, forget how it works
restrict_channel_access = True # is there a limited amount of channels
dataset = DataSet #UMass or Lexington
day_or_numMules = Day_Or_NumMules #date (UMass) or number of mules (Lexington)(for lexington this number really doesn't mean anything it is just needed for the file structure)
round = Round #Round number (also not too important anymore, but can be used to keep information from current simulation settings if you want to regenerate a link exist without losing current metrics)
protocol = Protocol # not used anymore, didn't take out in case it is needed again for xchants
band = Band #bands to use in set of [ALL, TV, LTE, ISM, CBRS]
T = t #Length of Simulation
V = v #Number of dataMules
NoOfSources = src_dst[0] # # of sources
NoOfDataCenters = src_dst[1] # # of destinations
start_time = ts # start time
max_nodes = Max_Nodes #All nodes include src and des
geo_routing = False
broadcast = False
num_nodes_to_fwd = -1
# creates a list of spectrums based on bands being used and the current smart setting
if band == "ALL":
S = [0, 1, 2, 3]
# else:
# w1 = wei_param
# w2 = 1 - wei_param
# S = get_suitable_spectrum_list(smart_setting, w1, w2)
elif band == "TV":
S = [0, 0, 0, 0]
elif band == "ISM":
S = [1, 1, 1, 1]
elif band == "LTE":
S = [2, 2, 2, 2]
elif band == "CBRS":
S = [3, 3, 3, 3]
else:
S = []
print("Invalid Band Type")
# if band != "ALL":
protocol_path = protocol + "_" + band
if protocol == "q_learning":
protocol_path = protocol_path + "/" + str(round_q_learn)
#dataset is the "LEX" or "UMass", day_or_numMules is the "2007-11-01", and round is the simulation round.
dataMule_path = dir + dataset + "/" + str(day_or_numMules) + "/" + str(round) + "/"
# creates multiple file paths based on the dataset and the variables assigned above
if dataset == "UMass":
link_exists_path = dataMule_path + "Link_Exists/" + "LE_" + str(start_time) + "_" + str(T) + "/"
path_to_folder = link_exists_path + protocol_path + "/mules_" + str(V) + "/channels_" + str(num_chan) + "/P_users_" + str(num_puser)
path_to_metrics = path_to_folder + "/msgfile_" + str(msg_round) + "_" + str(msg_mean) + "/puserfile_" \
+ str(puser_round) + "/TTL_" + str(ttl) + "/BuffSize_" + str(mem_size) +"/" + "numTransceivers_"\
+ str(num_trans) + "/"
path_to_save_LLC = link_exists_path
if pkl_fold_num == 1:
path_to_day1_LLC = link_exists_path
else:
boot_round_length = 180
path_to_day1_LLC = dataMule_path + "Link_Exists/LE_" + str(start_time - boot_round_length) + "_" + str(boot_round_length) + "/"
elif dataset == "Lexington":
if pkl_fold_num == 1:
link_exists_path = dataMule_path + "Link_Exists/" + "LE_1_" + str(T) + "/"
path_to_day1_LLC = link_exists_path
path_to_folder = link_exists_path + protocol_path + "/mules_" + str(V) + "/channels_" + str(num_chan) + "/P_users_" + str(num_puser)
path_to_metrics = path_to_folder + "/msgfile_" + str(msg_round) + "_" + str(msg_mean) + "/puserfile_" \
+ str(puser_round) + "/TTL_" + str(ttl) + "/BuffSize_" + str(mem_size) +"/" + "numTransceivers_"\
+ str(num_trans) + "/"
else:
link_exists_path = dataMule_path + "Link_Exists/" + "LE_2_" + str(T) + "/"
path_to_folder = link_exists_path + protocol_path + "/mules_" + str(V) + "/channels_" + str(num_chan) + "/P_users_" + str(num_puser)
path_to_metrics = path_to_folder + "/msgfile_" + str(msg_round) + "_" + str(msg_mean) + "/puserfile_" \
+ str(puser_round) + "/TTL_" + str(ttl) + "/BuffSize_" + str(mem_size) + "/" + "numTransceivers_"\
+ str(num_trans) + "/"
path_to_day1_LLC = dataMule_path + "Link_Exists/LE_1_" + str(T) + "/"
path_to_save_LLC = link_exists_path
else:
print("Invalid Dataset")
return -1
# create the constants file based on all of these parameters
create_constants(T, V, S, start_time, dataset, max_nodes, dataMule_path, path_to_folder, path_to_metrics, link_exists_path,
debug_message, protocol, NoOfDataCenters, NoOfSources, generate_LE, generate_messages, num_messages,
pkl_fold_num, path_to_day1_LLC, perfect_knowledge, speed, limited_time_to_transfer, restrict_band_access,
restrict_channel_access, generate_new_primary_users, num_chan, num_puser, path_to_save_LLC, smart_setting,
priority_queue_active, broadcast, geo_routing, num_nodes_to_fwd, msg_round, puser_round, debug_mode, metric_interval,
msg_mean, ttl, max_mem, replicas, num_trans)
# if proto == "q_learning" and generate_LE == True : # bootstrap round.
# os.system(
# "python3 GenerateMessages_qlearning.py") # P_comment : Use GenerateMessages : because you find least latency cost path using Q-learning
# generate a link exists if needed
if generate_LE == True and max_nodes == V + NoOfSources + NoOfDataCenters:
if dataset == "UMass":
# os.system("python3 create_pickles.py")
os.system("python3 computeLINKEXISTS_UMass.py") # P_comment : needed for q learning
os.system("python3 STB_main_path.py")
elif dataset == "Lexington":
# os.system("python3 readLexingtonData_Fixed.py")
# os.system("python3 create_pickles_Lex.py")
# os.system("python3 computeLINKEXISTS_Lex.py")
os.system("python3 computeLINKEXISTS_random.py")
os.system("python3 computeSpecBW.py")
os.system("python3 STB_main_path.py")
# run the simulation and metrics if you are not generating link exists
if generate_LE == False:
if dataset == "UMass" and is_boot_round == False:
print("Compute round 2 link exists\n")
os.system("python3 computeLINKEXISTS_UMass.py") # P_comment : Why do this again?
os.system("python3 STB_main_path.py") # P_comment : Is this needed?
os.system("python3 main.py") # P_comment : Operational round.
os.system("python3 metrics.py")
# function to run simulations for ISC2 paper
def run_various_sims(sim_round, num_mules, num_channels, num_Pusers, msg_round, msg_mean, ttl, mem_size, num_replicas):
for band in bands:
# print("Band:", band, "MSG round:", msg_round, "MSG mean:", msg_mean)
#For all bands, do smart epidemic and Geographic routing (1 stands for geo, and 0 for epidemic)
if band == "ALL":
priority_queue_active = True
for routing_opt in ["Geo"]:
print("Routing:", routing_opt)
#print("Weighted")
run_simulation(data, day, sim_round, proto, band, len_T, start_time, num_mules, generate_LE, max_v,
pkl_ID, perfect_knowledge, src_dst, speed, num_messages, num_channels, num_Pusers,
"weighted", nodes_tofwd, msg_round, puser_round, msg_mean, ttl, mem_size,
num_replicas, priority_queue_active, routing_opt)
# print()
# print("Optimistic")
run_simulation(data, day, sim_round, proto, band, len_T, start_time, num_mules, generate_LE, max_v,
pkl_ID, perfect_knowledge, src_dst, speed, num_messages, num_channels, num_Pusers,
"optimistic", nodes_tofwd, msg_round, puser_round, msg_mean, ttl, mem_size, num_replicas, priority_queue_active, routing_opt)
# print()
# print("Pessimistic")
run_simulation(data, day, sim_round, proto, band, len_T, start_time, num_mules, generate_LE, max_v,
pkl_ID, perfect_knowledge, src_dst, speed, num_messages, num_channels, num_Pusers,
"pessimistic", nodes_tofwd, msg_round, puser_round, msg_mean, ttl, mem_size, num_replicas, priority_queue_active, routing_opt)
else:
priority_queue_active = False
#For single bands, lets only do basic epidemic routing - 0 stands for epidemic routing
for routing_opt in ["Epi"]:
print("Band:", band, "Routing:", routing_opt)
run_simulation(data, day, sim_round, proto, band, len_T, start_time, num_mules, generate_LE, max_v,
pkl_ID, perfect_knowledge, src_dst, speed, num_messages, num_channels, num_Pusers,
band, nodes_tofwd, msg_round, puser_round, msg_mean, ttl, mem_size, num_replicas, priority_queue_active, routing_opt)
# (DataSet, Day_Or_NumMules, Round, Protocol, Band, t, ts, v, Gen_LE, Max_Nodes, pkl_fold_num, perfect_knowledge,
# src_dst_arr, speed_arr, num messages, num channels, num primary users, smart setting (optional))
# RF parameter setting
# Freq: TV = 600 MHz, LTE = 900 MHz, ISM = 2.4 GHz, and CBRS = 3.5 GHz
# Path loss factor = 2.8 (sub-urban, LEXINGTON) and 2.5 (rural UMass)
# Receiver Sensitivity = -95 dBm
# White noise = -100 dB
# SNR = 5 dB
# Transmitter Antenna Gain = 0 dBi
# Receiver Antenna Gain = 0 dBi
# Transmit power = TV, and LTE = 4 Watt, ISM = 1 Watt, CBRS = 100 Watt
# Channel Bandwidth = Tv = 6 MHz, LTE = 20 MHz, ISM = 8 MHz, and CBRS = 40 MHz
# Computed Range = TV : 1452 meter, LTE = 840 meter, ISM = 133 meter, and CBRS = 188 meter
# Resultant Bit rate = TV: 12 Mbps, LTE = 41 Mbps, ISM = 16 Mbps, and CBRS = 82 Mbps
#### For Day 2
#1. start_time = 840,
#2. pkl_ID = 2
#3. is_boot_round = False
#4. len_T = 240
start_time = 1 # start time (to find Link Exists)
is_boot_round = True # which day or round
pkl_ID = 1 # pkl folder ID if Link Exists is being generated
len_T = 480
generate_LE = False # generate Link Exists
data = "Lexington"
day = "50"
# length of simulation
# bands = ["ALL", "LTE", "TV", "CBRS", "ISM"] # which bands to use
band = "ALL"
num_mules = 24 # number of data mules to use
perfect_knowledge = False # Xchant only
src_dst = [3, 3] # num src and dst # P_comment : Reduce source and destination data 3 source and 3 dest.
max_v = num_mules + src_dst[0] + src_dst[1] # max number of datamules + src + dst
speed = [135, 400] # Lex data only
proto = "XChant" # [Epidemic_Smart, XChant, SprayNWait (in progress)]
num_Pusers = 0 # P_comment : How many Primary users do we assume?
num_channels = 6
nodes_tofwd = -1
routing_opt = "Epi"
msg_round = 1
puser_round = 0
msg_mean = 15
ttl = 60
mem_size = -1 # not more than 50.
num_replicas = 1 # number of replicas/copies for geographic SnW
sim_round = 1
priority_queue_active = False
compute_spec_BW = False
num_transceivers = 1
round_q_learn = 0
if compute_spec_BW == True:
os.system("python3 computeSpecBW.py")
else:
if generate_LE == False :
# for num_transceivers in [1, 8]:
if proto == "XChant":
for num_Pusers in [0, 25, 50, 75, 100, 125, 150]:
print("Num Transceivers:", num_transceivers)
run_simulation(data, day, sim_round, proto, band, len_T, start_time, num_mules, generate_LE, max_v,
pkl_ID, perfect_knowledge, src_dst, speed, num_messages, num_channels, num_Pusers,
"optimistic", nodes_tofwd, msg_round, puser_round, msg_mean, ttl, mem_size, num_replicas,
priority_queue_active, routing_opt,0, num_transceivers, is_boot_round)
else:
# for band in ["ALL", "TV", "ISM", "LTE", "CBRS"]:
for round_q_learn in range(20):
for band in ["ALL"]:
for num_Pusers in [0, 25, 50, 75, 100, 125, 150]:
print("Num Transceivers:", num_transceivers)
run_simulation(data, day, sim_round, proto, band, len_T, start_time, num_mules, generate_LE, max_v,
pkl_ID, perfect_knowledge, src_dst, speed, num_messages, num_channels, num_Pusers,
"optimistic", nodes_tofwd, msg_round, puser_round, msg_mean, ttl, mem_size,
num_replicas,
priority_queue_active, routing_opt, 0, num_transceivers, is_boot_round)
#Generate Link exists
else:
if data == "Lexington":
run_simulation(data, day, sim_round, proto, band, len_T, start_time, num_mules, generate_LE, max_v,
1, perfect_knowledge, src_dst, speed, num_messages, num_channels, num_Pusers,
"optimistic", nodes_tofwd, msg_round, puser_round, msg_mean, ttl, mem_size, num_replicas, priority_queue_active, routing_opt, 0, num_transceivers, is_boot_round)
# run_simulation(data, day, sim_round, proto, "ALL", len_T, start_time, num_mules, generate_LE, max_v,
# 2, perfect_knowledge, src_dst, speed, num_messages, num_channels, num_Pusers,
# "optimistic", nodes_tofwd, msg_round, puser_round, msg_mean, ttl, mem_size, num_replicas,
# priority_queue_active, routing_opt, 0, num_transceivers, is_boot_round)
else:
run_simulation(data, day, sim_round, proto, band, len_T, start_time, num_mules, generate_LE, max_v,
pkl_ID, perfect_knowledge, src_dst, speed, num_messages, num_channels, num_Pusers,
"optimistic", nodes_tofwd, msg_round, puser_round, msg_mean, ttl, mem_size, num_replicas,
priority_queue_active, routing_opt, 0, num_transceivers, is_boot_round)