-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomm_patterns.py
More file actions
31 lines (27 loc) · 985 Bytes
/
comm_patterns.py
File metadata and controls
31 lines (27 loc) · 985 Bytes
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
import networkx as nx
from itertools import product
from aux_funcs import update_weight
def shortest_path(G, transfer_size, capacity_scaler):
paths_lst = []
hosts = [x for x in G.nodes() if "Host" in x]
for h_i, h_j in product(hosts, hosts):
if h_i != h_j:
s_path = nx.shortest_path(G, source=h_i, target=h_j)
paths_lst.append((
h_i,
h_j,
s_path))
update_weight(G, s_path, transfer_size, capacity_scaler)
return paths_lst
def weighted_shortest_path(G, transfer_size, capacity_scaler):
paths_lst = []
hosts = [x for x in G.nodes() if "Host" in x]
for h_i, h_j in product(hosts, hosts):
if h_i != h_j:
s_path = nx.dijkstra_path(G, source=h_i, target=h_j)
paths_lst.append((
h_i,
h_j,
s_path))
update_weight(G, s_path, transfer_size, capacity_scaler)
return paths_lst