Ask Your Question

KaylaG's profile - activity

2023-06-10 18:53:32 +0200 received badge  Famous Question (source)
2023-05-21 23:31:28 +0200 received badge  Notable Question (source)
2020-12-08 09:20:44 +0200 received badge  Popular Question (source)
2019-07-10 14:50:18 +0200 received badge  Student (source)
2019-07-09 19:21:57 +0200 received badge  Editor (source)
2019-07-09 12:48:27 +0200 asked a question Does the set_embedding command have a bug?

We created a bipartite graph and called the set_embedding command by using a dictionary with vertices as keys and a list of neighboring vertices in clockwise order. The graph did not show the correct embedding. We expected the vertices to be in the correct clockwise order, but the order is not consistent. We also tried using the on_embedding command. Each time we run the code our vertices are randomly placed in different places.

EDIT:

#S0 and S1 are lists of lists


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)
        print("verts before flipped order:")
        print(verts)

        #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)
    print("verts after flipped order:")
    print(verts)

    #keep a certain ordering
    graph.set_embedding(verts)