-
Notifications
You must be signed in to change notification settings - Fork 4
/
zhopkinsNetworkxCode.py
77 lines (51 loc) · 1.72 KB
/
zhopkinsNetworkxCode.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
72
73
74
75
76
import networkx as nx
import matplotlib.pyplot as plt
from string import ascii_uppercase
tetrahedron = [
[1,1,1,0],
[1,0,1,1],
[1,1,0,1],
[0,1,1,1]
]
sqaure = [
[1,1,1,1,0,0,0,0],
[1,1,0,0,1,1,0,0],
[0,1,1,0,0,1,1,0],
[0,0,1,1,0,0,1,1],
[1,0,0,1,1,0,0,1],
[0,0,0,0,1,1,1,1]
]
def edgeCreator(graph, startingPoint, arrEndingPoints, vertName):
if arrEndingPoints == []:
return graph
for face in arrEndingPoints:
graph.add_edge(startingPoint, face, label=vertName)
newStartingPoint = arrEndingPoints.pop(0)
return edgeCreator(graph, newStartingPoint, arrEndingPoints,vertName)
def crazyGraphMaker(shapeMatrix):
#sets up the Graph
shapeGraph = nx.Graph()
#puts all the nodes into the graph
for i in range(0,len(shapeMatrix)):
shapeGraph.add_node(ascii_uppercase[i])
#loop through the vertices
for i in range(0,len(shapeMatrix[0])):
#loops through and logs all faces a vertex is touching
arrTouchingFaces = []
for j in range(0,len(shapeMatrix)):
if shapeMatrix[j][i] == 1:
arrTouchingFaces.append(ascii_uppercase[j])
#takes the first face and the array of the rest to compute all edges related to this vertx
startingFace = arrTouchingFaces.pop(0)
edgeCreator(shapeGraph, startingFace, arrTouchingFaces, i+1)
return shapeGraph
# In[81]:
tetraGraph = crazyGraphMaker(tetrahedron)
nx.draw(tetraGraph, with_labels=1)
# In[82]:
squareGraph = crazyGraphMaker(sqaure)
nx.draw(squareGraph, with_labels=1)
# In[94]:
squareGraph.edges()
edge_labels = nx.get_edge_attributes(squareGraph,"label")
print(edge_labels)