|
28 | 28 | :meth:`~DiGraphGenerators.ImaseItoh` | Return the digraph of Imase and Itoh of order `n` and degree `d`.
|
29 | 29 | :meth:`~DiGraphGenerators.Kautz` | Return the Kautz digraph of degree `d` and diameter `D`.
|
30 | 30 | :meth:`~DiGraphGenerators.nauty_directg` | Return an iterator yielding digraphs using nauty's ``directg`` program.
|
| 31 | + :meth:`~DiGraphGenerators.nauty_posetg` | Return an iterator yielding Hasse diagrams of posets using nauty's ``genposetg`` program. |
31 | 32 | :meth:`~DiGraphGenerators.Paley` | Return a Paley digraph on `q` vertices.
|
32 | 33 | :meth:`~DiGraphGenerators.Path` | Return a directed path on `n` vertices.
|
33 | 34 | :meth:`~DiGraphGenerators.RandomDirectedAcyclicGraph` | Return a random (weighted) directed acyclic graph of order `n`.
|
@@ -758,6 +759,63 @@ def nauty_directg(self, graphs, options='', debug=False):
|
758 | 759 | if line and line[0] == '&':
|
759 | 760 | yield DiGraph(line[1:], format='dig6')
|
760 | 761 |
|
| 762 | + def nauty_posetg(self, options='', debug=False): |
| 763 | + r""" |
| 764 | + Return a generator which creates all posets using ``nauty``. |
| 765 | +
|
| 766 | + Here a poset is seen through its Hasse diagram, which is |
| 767 | + an acyclic and transitively reduced digraph. |
| 768 | +
|
| 769 | + INPUT: |
| 770 | +
|
| 771 | + - ``options`` -- string (default: ``""``); a string passed to |
| 772 | + ``genposetg`` as if it was run at a system command line. |
| 773 | + At a minimum, you *must* pass the number of vertices you desire |
| 774 | + and a choice between ``o`` and ``t`` for the output order. |
| 775 | +
|
| 776 | + - ``debug`` -- boolean (default: ``False``); if ``True`` the first line |
| 777 | + of ``genposetg``'s output to standard error is captured and the first |
| 778 | + call to the generator's ``next()`` function will return this line as a |
| 779 | + string. A line leading with ">A" indicates a successful initiation of |
| 780 | + the program with some information on the arguments, while a line |
| 781 | + beginning with ">E" indicates an error with the input. |
| 782 | +
|
| 783 | + The possible options, obtained as output of ``genposetg --help``:: |
| 784 | +
|
| 785 | + n: the number of vertices, between 0 and 16 |
| 786 | + o: digraph6 output in arbitrary order |
| 787 | + t: digraph6 output in topological order |
| 788 | +
|
| 789 | + EXAMPLES:: |
| 790 | +
|
| 791 | + sage: gen = digraphs.nauty_posetg("5 o") |
| 792 | + sage: len(list(gen)) |
| 793 | + 63 |
| 794 | +
|
| 795 | + This coincides with :oeis:`A000112`. |
| 796 | + """ |
| 797 | + import shlex |
| 798 | + from sage.features.nauty import NautyExecutable |
| 799 | + geng_path = NautyExecutable("genposetg").absolute_filename() |
| 800 | + sp = subprocess.Popen(shlex.quote(geng_path) + f" {options}", shell=True, |
| 801 | + stdin=subprocess.PIPE, stdout=subprocess.PIPE, |
| 802 | + stderr=subprocess.PIPE, close_fds=True, |
| 803 | + encoding='latin-1') |
| 804 | + msg = sp.stderr.readline() |
| 805 | + if debug: |
| 806 | + yield msg |
| 807 | + elif msg.startswith('>E'): |
| 808 | + raise ValueError('wrong format of parameter option') |
| 809 | + gen = sp.stdout |
| 810 | + while True: |
| 811 | + try: |
| 812 | + s = next(gen) |
| 813 | + except StopIteration: |
| 814 | + # Exhausted list of graphs from nauty genposetg |
| 815 | + return |
| 816 | + G = DiGraph(s[1:-1], format='dig6') |
| 817 | + yield G |
| 818 | + |
761 | 819 | def Complete(self, n, loops=False):
|
762 | 820 | r"""
|
763 | 821 | Return the complete digraph on `n` vertices.
|
@@ -1486,7 +1544,9 @@ def RandomDirectedGNM(self, n, m, loops=False):
|
1486 | 1544 | sage: D.num_verts()
|
1487 | 1545 | 10
|
1488 | 1546 | sage: D.loops()
|
1489 |
| - [(0, 0, None), (1, 1, None), (2, 2, None), (3, 3, None), (4, 4, None), (5, 5, None), (6, 6, None), (7, 7, None), (8, 8, None), (9, 9, None)] |
| 1547 | + [(0, 0, None), (1, 1, None), (2, 2, None), (3, 3, None), |
| 1548 | + (4, 4, None), (5, 5, None), (6, 6, None), (7, 7, None), |
| 1549 | + (8, 8, None), (9, 9, None)] |
1490 | 1550 |
|
1491 | 1551 | TESTS::
|
1492 | 1552 |
|
|
0 commit comments