Ticket #14859: trac_14859_addon1_fc.patch

File trac_14859_addon1_fc.patch, 3.0 KB (added by chapoton, 8 years ago)
  • sage/graphs/hypergraph.py

    # HG changeset patch
    # User Frederic Chapoton <chapoton at math.univ-lyon1.fr>
    # Date 1374152964 -7200
    # Node ID 5684abff2a6ddbc773fff5b6e7f21afe04ace308
    # Parent  c49cbb58cdfe6b9a0f8e9df0aabd907750b3bc6f
    trac 14859 proposal to split the function
    
    diff --git a/sage/graphs/hypergraph.py b/sage/graphs/hypergraph.py
    a b r""" 
    22Hypergraphs
    33
    44This module consists in a very basic implementation of :class:`Hypergraph`,
    5 whose only current purpose is to observe them : it can be used to compute
     5whose only current purpose is to observe them: it can be used to compute
    66automorphism groups and to draw them. The latter is done at the moment through
    77`\LaTeX` and TikZ, and can be obtained from Sage through the ``view`` command::
    88
    class Hypergraph: 
    192192            sage: sets = Set(map(Set,list(g.subgraph_search_iterator(C4))))
    193193            sage: H = Hypergraph(sets)
    194194            sage: view(H) # not tested
    195 
    196195        """
    197196        from sage.rings.integer import Integer
    198197        from sage.functions.trig import arctan2
    class Hypergraph: 
    252251        tex += "\\end{tikzpicture}"
    253252        return tex
    254253
     254    def to_bipartite_graph(self, with_partition=False):
     255        r"""
     256        Returns the associated bipartite graph
     257
     258        INPUT:
     259
     260        - with_partition -- boolean (default: False)
     261
     262        OUTPUT:
     263
     264        - a graph or a pair (graph, partition)
     265
     266        EXAMPLES::
     267
     268            sage: H = designs.steiner_triple_system(7).blocks()
     269            sage: H = Hypergraph(H)
     270            sage: g = H.to_bipartite_graph(); g
     271            Graph on 14 vertices
     272            sage: g.is_regular()
     273            True
     274        """
     275        from sage.graphs.graph import Graph
     276
     277        G = Graph()
     278        domain = list(self.domain())
     279        G.add_vertices(domain)
     280        for s in self._sets:
     281            for i in s:
     282                G.add_edge(s, i)
     283        if with_partition:
     284            return (G, [domain, list(self._sets)])
     285        else:
     286            return G
    255287
    256288    def automorphism_group(self):
    257289        r"""
    class Hypergraph: 
    269301            sage: g.is_isomorphic(groups.permutation.PGL(3,2))
    270302            True
    271303        """
    272         from sage.graphs.graph import Graph
    273304        from sage.groups.perm_gps.permgroup import PermutationGroup
    274305
    275         G = Graph()
    276         domain = list(self.domain())
    277         G.add_vertices(domain)
    278         for s in self._sets:
    279             for i in s:
    280                 G.add_edge(s,i)
     306        G, part = self.to_bipartite_graph(with_partition=True)
    281307
    282         ag = G.automorphism_group(partition=[domain,list(self._sets)])
     308        domain = part[0]
    283309
    284         gens =  [ [tuple(c) for c in g.cycle_tuples() if c[0] in domain]
    285                   for g in ag.gens()]
     310        ag = G.automorphism_group(partition=part)
     311
     312        gens =  [[tuple(c) for c in g.cycle_tuples() if c[0] in domain]
     313                 for g in ag.gens()]
    286314
    287315        return PermutationGroup(gens = gens, domain = domain)