Repository navigation
Expand file tree
/
Copy pathsimulate_sequentially.py
More file actions
58 lines (50 loc) · 1.73 KB
/
Copy pathsimulate_sequentially.py
File metadata and controls
58 lines (50 loc) · 1.73 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
from EONTools import *
from threading import Thread, Lock
# Loading EON
nodes_csv = 'input/rnp/rnpBrazil_nodes.csv'
eon = EON(name='EON without links')
eon.loadCSV(nodes_csv, None)
# Getting modulation levels
modulation_levels = ModulationLevel.loadModulationLevels('input/modulation_levels.csv')
# Calculating and generating list of new links
n = len(eon.nodes())
full = int(n*(n-1)/2)
lock = Lock()
# Simulation method
def simulate(modulation_levels, thread_id):
# Loading dependencies
global n, full, lock
# Getting number of links (mutex)
n_links = None
lock.acquire()
if n <= full:
n_links = n
n += 1
lock.release()
if n_links is None:
return
# Loading EON
nodes_csv = 'input/rnp/rnpBrazil_nodes.csv'
eon = EON(name='EON without links')
eon.loadCSV(nodes_csv, None)
# Creating random demands
demands = Demand.createRandomDemands(eon, random_state=0)
csv_name = '%d'%n_links
folder = 'results/simulate_sequentially/'
id = Report.getIdOrCreateCSV(csv_name, folder=folder)
count = 0
print('Thread %d: simulating for %d links'%(thread_id, n_links))
possible_eons = Combinations.getPossibleEONsWithNewLinks(eon, n_links=n_links, k_edge_connected=2)
for possible_eon in possible_eons:
if count >= id:
Simulation.simulateDemands(possible_eon, modulation_levels, demands)
Report.writeCSV(possible_eon, demands, csv_name, id=count, folder=folder)
count += 1
simulate(modulation_levels, thread_id)
print('Thread %d: finished'%thread_id)
# Starting threads
n_threads = 8
threads = [None]*n_threads
for i in range(n_threads):
threads[i] = Thread(target=simulate, args=(modulation_levels, i))
threads[i].start()