-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.py
72 lines (59 loc) · 1.67 KB
/
driver.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
import itertools
from settings import get_settings
from settings import write_settings
import time
from one_simulator import run
from one_simulator import get_results_of_simulation
import os
import csv
TTLs = range(20, 340, 20)
BUFFER_SIZES = range(100, 1800, 100)
NAME = "Epidemic_b{bufferSize}_ttl{ttl}"
def write_out_csv(results):
with open("results.csv", "w") as f:
writer = csv.DictWriter(f, results[0].keys())
writer.writeheader()
writer.writerows(results)
# Iterate through permutations of TTL and buffer size.
results = []
n = len(TTLs) * len(BUFFER_SIZES)
i = 0
for ttl, bufferSize in itertools.product(TTLs, BUFFER_SIZES):
i += 1
start = time.time()
print(
"Completion := {0:.0%}\n"
"TTL := {1}\n"
"BUF := {2}\n".format(float(i)/n, ttl, bufferSize)
)
scenarioName = NAME.format(bufferSize=bufferSize, ttl=ttl)
# Feed pair into settings generator.
settings = get_settings(
size_in_bytes=bufferSize,
ttl=ttl,
scenario_name=scenarioName
)
write_settings(settings)
# Run the ONE simulation.
try:
run()
except:
print("Problem with TTL := {0}, BUF := {1}".format(ttl, bufferSize))
else:
# Grab the results from the simulation and append to a single file.
results_from_sim = get_results_of_simulation(
os.path.join(
"reports",
"{scenarioName}_MessageStatsReport.txt".format(
scenarioName=scenarioName
)
))
duration = int(time.time() - start)
results_from_sim.update({
"TTL": ttl,
"bufferSize": bufferSize,
"RunningTime": duration
})
results.append(results_from_sim)
print("Done! {0} seconds".format(duration))
write_out_csv(results)