Ask Your Question
0

Labeling vertices of a graph effectively

asked 2022-05-13 20:21:30 +0100

vidyarthi gravatar image

updated 2022-05-13 20:55:46 +0100

tmonteil gravatar image

Suppose I have $k$ copies of the $5$- cliques formed by using the following code:

def Sier(n,k):
    l=list(range(1,k))
    g=graphs.CompleteGraph(n)
    for i in l:
        g=g.disjoint_union(graphs.CompleteGraph(n))
    return g
k=Sier(5,5)

How do I label the vertices in the manner $ij$ where $i$ stands for the $i$-th copy and $j$ for the $j$-th vertex in the $i$-th copy of the clique?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2022-05-14 09:19:03 +0100

To get what you want, it's best to relabel the vertices of each copy of the cliques and then add edges to the result. This way, you know exactly what's going on.

def Sier(n, k):
    g = graphs.CompleteGraph(n)
    h = Graph()
    for i in range(1, k + 1):
        perm = {u: (i, u) for u in g}
        gg = g.relabel(perm=perm, inplace=False)
        h.add_edges(gg.edges())
    return h

You get

sage: h = Sier(3, 4)
sage: h.vertices()
[(1, 0),
 (1, 1),
 (1, 2),
 (2, 0),
 (2, 1),
 (2, 2),
 (3, 0),
 (3, 1),
 (3, 2),
 (4, 0),
 (4, 1),
 (4, 2)]
edit flag offensive delete link more
0

answered 2022-05-13 20:55:30 +0100

tmonteil gravatar image

You can have a look at the relabel method:

sage: k.relabel?
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-05-13 20:21:30 +0100

Seen: 383 times

Last updated: May 14 '22