# 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""" |
2 | 2 | Hypergraphs |
3 | 3 | |
4 | 4 | This 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 |
| 5 | whose only current purpose is to observe them: it can be used to compute |
6 | 6 | automorphism groups and to draw them. The latter is done at the moment through |
7 | 7 | `\LaTeX` and TikZ, and can be obtained from Sage through the ``view`` command:: |
8 | 8 | |
… |
… |
class Hypergraph: |
192 | 192 | sage: sets = Set(map(Set,list(g.subgraph_search_iterator(C4)))) |
193 | 193 | sage: H = Hypergraph(sets) |
194 | 194 | sage: view(H) # not tested |
195 | | |
196 | 195 | """ |
197 | 196 | from sage.rings.integer import Integer |
198 | 197 | from sage.functions.trig import arctan2 |
… |
… |
class Hypergraph: |
252 | 251 | tex += "\\end{tikzpicture}" |
253 | 252 | return tex |
254 | 253 | |
| 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 |
255 | 287 | |
256 | 288 | def automorphism_group(self): |
257 | 289 | r""" |
… |
… |
class Hypergraph: |
269 | 301 | sage: g.is_isomorphic(groups.permutation.PGL(3,2)) |
270 | 302 | True |
271 | 303 | """ |
272 | | from sage.graphs.graph import Graph |
273 | 304 | from sage.groups.perm_gps.permgroup import PermutationGroup |
274 | 305 | |
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) |
281 | 307 | |
282 | | ag = G.automorphism_group(partition=[domain,list(self._sets)]) |
| 308 | domain = part[0] |
283 | 309 | |
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()] |
286 | 314 | |
287 | 315 | return PermutationGroup(gens = gens, domain = domain) |