Ask Your Question

Revision history [back]

Here is a way:

from sage.graphs.digraph import DiGraph
class MyCayleyGraph(DiGraph):
    def __init__(self, *args, **kwargs):
        group = kwargs.get('group', None)
        gens = kwargs.get('gens', None)
        if group and gens:
            self._group = group
            self._gens = gens
            super().__init__(group.cayley_graph(generators = gens))
        else:
            super().__init__(*args, **kwargs)
    def group(self):
        return self._group
    def gens(self):
        return self._gens

Example:

sage: G = DihedralGroup(5)
sage: CG = MyCayleyGraph(group=G, gens=[G.gen(0), G.gen(1)])
sage: CG.group()
Dihedral group of order 10 as a permutation group
sage: CG.gens()
[(1,2,3,4,5), (1,5)(2,4)]
sage: CG.vertices(sort=False)
[(),
 (1,5,4,3,2),
 (1,4,2,5,3),
 (1,3,5,2,4),
 (1,2,3,4,5),
 (2,5)(3,4),
 (1,5)(2,4),
 (1,4)(2,3),
 (1,3)(4,5),
 (1,2)(3,5)]

I did the constructor that way to keep CG.show() working; maybe there's a better way.