ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 05 Jul 2019 09:49:58 +0200How to count face on a bipartite graph?https://ask.sagemath.org/question/47057/how-to-count-face-on-a-bipartite-graph/I am graphing a bipartite graph but I need to rearrange the graph. The graph is generated by a list of list. One of the rearrangement guidelines is that the faces have to be surrounded by a certain amount of "white" vertices. Therefore, I wanted to create a checker function that can count the faces of the graph and count the "white" vertices around that face. If the graph doesn't have the correct amount of faces and/or the number of "white" vertices then the program will rearrange the graph. I would like some guidance on this task, what code/math I should use or if I should use a different approach. I have attached the code. If more information is needed to help, please contact me at cameron.dthomas@morehouse.edu
Thanks for your time,
Cameron Thomas
D={}
graph=Graph(D, multiedges=True)
def Dessin(S0, S1):
numVertices = len(S0)+len(S1)
G={}
#adds keys to G
for i in range(numVertices):
G[i]=(S0+S1)[i]
for i in range(len(S0)):
#print(S0[i])
for j in range(len(S0[i])):
#print(S0[i][j])
for k in range(len(S1)):
if S0[i][j] in S1[k]:
graph.add_edge(i,k + len(S0),S0[i][j])
print(G)
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]
Dessin(S0, S1)
color(S0, S1)
graph.graphplot(edge_labels=True, vertex_colors={'grey': color(S0,S1)[0],'white':color(S0,S1)[1]}, vertex_labels=True).show()
return(graph)
Graf([[1,5,4,3,2]],[[1],[2],[3],[4],[5]])Thu, 04 Jul 2019 06:18:28 +0200https://ask.sagemath.org/question/47057/how-to-count-face-on-a-bipartite-graph/Comment by FrédéricC for <p>I am graphing a bipartite graph but I need to rearrange the graph. The graph is generated by a list of list. One of the rearrangement guidelines is that the faces have to be surrounded by a certain amount of "white" vertices. Therefore, I wanted to create a checker function that can count the faces of the graph and count the "white" vertices around that face. If the graph doesn't have the correct amount of faces and/or the number of "white" vertices then the program will rearrange the graph. I would like some guidance on this task, what code/math I should use or if I should use a different approach. I have attached the code. If more information is needed to help, please contact me at <a href="mailto:cameron.dthomas@morehouse.edu">cameron.dthomas@morehouse.edu</a>
Thanks for your time,
Cameron Thomas </p>
<pre><code>D={}
graph=Graph(D, multiedges=True)
def Dessin(S0, S1):
numVertices = len(S0)+len(S1)
G={}
#adds keys to G
for i in range(numVertices):
G[i]=(S0+S1)[i]
for i in range(len(S0)):
#print(S0[i])
for j in range(len(S0[i])):
#print(S0[i][j])
for k in range(len(S1)):
if S0[i][j] in S1[k]:
graph.add_edge(i,k + len(S0),S0[i][j])
print(G)
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]
Dessin(S0, S1)
color(S0, S1)
graph.graphplot(edge_labels=True, vertex_colors={'grey': color(S0,S1)[0],'white':color(S0,S1)[1]}, vertex_labels=True).show()
return(graph)
</code></pre>
<p>Graf([[1,5,4,3,2]],[[1],[2],[3],[4],[5]])</p>
https://ask.sagemath.org/question/47057/how-to-count-face-on-a-bipartite-graph/?comment=47072#post-id-47072What about using
sage: RibbonGraph?Fri, 05 Jul 2019 09:49:58 +0200https://ask.sagemath.org/question/47057/how-to-count-face-on-a-bipartite-graph/?comment=47072#post-id-47072