Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: PRiME 2019
Views: 175
def Graf(S0, S1): D={} #empty graph G={} #edited graph that we add to verts={} #opening an empty graph graph=Graph(D, multiedges=True) #adds edges and vertices to the graph #S0 and S1 are lists of lists def Dessin(S0, S1): numVertices = len(S0)+len(S1) #creating dictionary G of vertices with neighboring edges in counterclockwise order for i in range(numVertices): G[i]=(S0+S1)[i] verts[i]=[] #iterate over black vertices for i in range(len(S0)): #iterate over edges connected to black vertices for j in range(len(S0[i])): #iterate over white vertices for k in range(len(S1)): #check if black and white vertices have an edge in common if S0[i][j] in S1[k]: #if they have an edge in common connect the vertices with the correct edge labeling graph.add_edge(i,k+len(S0),S0[i][j]) print('dictionary of neighboring edges:') print(G) #creating dictionary with vertices as keys and neighboring vertices in counterclockwise order for i in range(numVertices): for j in range(len(G[i])): for k in range(numVertices): if i!=k: for l in range(len(G[k])): if G[i][j] in G[k]: if k not in verts[i]: verts[i].append(k) #flip order of vertices so that we're counterclockwise. for i in range(len(verts)): L=[] for j in range(len(verts[i])): L.append(verts[i][(len(verts[i]))-j-1]) verts[i]=L #all the vertices in S0 are black, all the vertices in S1 are white def color(S0, S1): grey=[] white=[] for i in range(len(S0)): grey.append(i) for i in range(len(S1)): white.append(i+len(S0)) return [grey,white] #call and color the graph Dessin(S0, S1) color(S0, S1) #keep a certain ordering graph.set_embedding(verts) graph.graphplot(edge_labels=True, vertex_colors={'grey': color(S0,S1)[0],'white':color(S0,S1)[1]}, vertex_labels=True, edge_labels_background='transparent').show() return(graph) ####### Degree N=1 Graf([[1]],[[1]]) ####### Degree N=2 Graf([[1,2]],[[1],[2]]) ####### Degree N=3 # Graf([[1,3,2]],[[1],[2],[3]]) ##Wrong Direction # Graf([[1],[2,3]],[[3],[1,2]]) ####### Degree N=4 # Graf([[1,4,3,2]],[[1],[2],[3],[4]]) ##Doesn't Work # Graf([[3],[1,4,2]],[[1],[2],[3,4]]) # Graf([[1,2],[3,4]],[[2],[4],[1,3]]) # Graf([[3],[1,4,2]],[[1,2],[3,4]]) ###MULTIEDGES # Graf([[4],[1,3,2]],[[3],[1,4,2]]) ###MULTIEDGES # Graf([[1,2],[3,4]],[[1,4],[2,3]]) ####### Degree N=5 # Graf([[1,5,4,3,2]],[[1],[2],[3],[4],[5]]) ###Doesn't Work # Graf([[4],[1,5,3,2]],[[1],[2],[3],[4,5]]) # Graf([[4,5],[1,3,2]],[[2],[3],[5],[1,4]]) # Graf([[3],[4],[1,5,2]],[[1],[2],[3,5,4]]) ###Wrong Vertices # Graf([[1],[3],[2,5,4]],[[5],[1,2],[3,4]]) # Graf([[4],[1,2],[3,5]],[[2],[1,3],[4,5]]) # Graf([[4],[1,5,3,2]],[[3],[1,2],[4,5]]) ###MULTIEDGES # Graf([[4],[1,2,5,3]],[[2],[1,3],[4,5]]) ###MULTIEDGES # Graf([[3],[1,2,5,4]],[[2],[5],[1,4,3]]) ###MULTIEDGES # Graf([[2,5],[1,4,3]],[[4],[1,5],[2,3]]) ###Wrong Vertices # Graf([[1,4],[2,5,3]],[[2],[3],[1,4,5]]) ###MULTIEDGES # Graf([[3,4],[1,2,5]],[[2],[4],[1,5,3]]) ###MULTIEDGES ####### Don't come out right ##Graf([[4],[1,2,5,3]],[[1],[2,3],[4,5]]) ## Graf([[3,5],[1,4,2]],[[2],[3],[1,4,5]]) #Graf([[1,2,3,4],[5,6]],[[1,2],[4,5],[3,6]]) ###MULTIEDGES