-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathother_measures.py
60 lines (30 loc) · 920 Bytes
/
other_measures.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
import pygraphviz as pgv
import networkx as nx
import math
def vertex_degree(G):
degree = sorted(dict(nx.degree(G)).values())[-1]
return degree
def areaerror(G, referenceArea=10):
area = computearea(G)
return abs(referenceArea-area)
def computearea(G):
(width, height) = boundingBox(G)
area = width*height
return area
def boundingBox(G):
all_pos = nx.get_node_attributes(G, "pos").values()
coo_x = sorted([float(p.split(",")[0]) for p in all_pos])
coo_y = sorted([float(p.split(",")[1]) for p in all_pos])
min_x = float(coo_x[0])
max_x = float(coo_x[-1])
min_y = float(coo_y[0])
max_y = float(coo_y[-1])
width = abs(max_x - min_x)
height = abs(max_y - min_y)
return (width, height)
def aspectRatio(G):
bb = boundingBox(G)
aspectRatio = bb[0]/bb[1]
return aspectRatio
def diameter(G):
return nx.diameter(G)