-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualize.py
More file actions
47 lines (35 loc) · 1.22 KB
/
visualize.py
File metadata and controls
47 lines (35 loc) · 1.22 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
# visualize.py — Network visualization for UrbanFlow
from igraph import Graph, plot
def visualize_network(network, output_file):
"""
Takes a network dictionary and saves a directed graph image.
Nodes = intersections/roads
Edges = connections with capacity labels
"""
g = Graph(directed=True)
nodes = list(network.keys())
g.add_vertices(nodes)
edges = []
capacities = []
for src, connections in network.items():
for dst, cap in connections.items():
edges.append((src, dst))
capacities.append(cap)
g.add_edges(edges)
g.es["capacity"] = capacities
layout = g.layout("kamada_kawai")
plot(
g,
layout=layout,
vertex_label=g.vs["name"],
edge_label=g.es["capacity"],
bbox=(600, 600),
margin=50,
target=output_file
)
print(f"Saved: {output_file}")
if __name__ == "__main__":
from network import create_weak_network, create_resilient_network
visualize_network(create_weak_network(), "results/project1_structure.png")
visualize_network(create_resilient_network(), "results/project2_structure.png")
visualize_network(create_resilient_network(), "results/project3_structure.png")