Processing math: 100%
Ask Your Question
0

Labeling vertices of a graph effectively

asked 2 years ago

vidyarthi gravatar image

updated 2 years ago

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?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 2 years ago

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)]
Preview: (hide)
link
0

answered 2 years ago

tmonteil gravatar image

You can have a look at the relabel method:

sage: k.relabel?
Preview: (hide)
link

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: 2 years ago

Seen: 492 times

Last updated: May 14 '22