# Labeling vertices of a graph effectively

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 close merge delete

Sort by » oldest newest most voted

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)
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)]

more

You can have a look at the relabel method:

sage: k.relabel?

more