Ask Your Question

Revision history [back]

One could construct the list by using nauty's generator and filtering by the desired conditions.

sage: gg = [g for g in graphs.nauty_geng("8 -c") if g.size() == 9
....:       and g.laplacian_matrix().eigenvalues()[1] == 1]

There are 30 such graphs:

sage: len(gg)
30

To show them:

sage: for g in gg:
....:     g.show()

One could construct the list by using nauty's generator and filtering by the desired conditions.

sage: gg = [g for g in graphs.nauty_geng("8 -c") if g.size() == 9
....:       and g.laplacian_matrix().eigenvalues()[1] == 1]

There are 30 such graphs:

sage: len(gg)
30

To show them:

sage: for g in gg:
....:     g.show()

To list their edges:

sage: for g in gg:
....:     print(g.edges(labels=None))
....:
[(0, 5), (0, 6), (0, 7), (1, 6), (1, 7), (2, 7), (3, 7), (4, 7), (6, 7)]
[(0, 5), (0, 6), (1, 6), (1, 7), (2, 6), (2, 7), (3, 7), (4, 7), (5, 7)]
[(0, 5), (0, 6), (1, 6), (1, 7), (2, 6), (2, 7), (3, 7), (4, 7), (6, 7)]
[(0, 5), (0, 6), (0, 7), (1, 6), (2, 6), (3, 7), (4, 7), (5, 7), (6, 7)]
[(0, 5), (0, 6), (1, 6), (1, 7), (2, 6), (3, 7), (4, 7), (5, 7), (6, 7)]
[(0, 5), (0, 6), (0, 7), (1, 6), (2, 7), (3, 7), (4, 7), (5, 6), (6, 7)]
[(0, 5), (0, 6), (1, 6), (1, 7), (2, 6), (2, 7), (3, 6), (4, 7), (5, 7)]
[(0, 5), (0, 6), (0, 7), (1, 5), (1, 6), (2, 7), (3, 7), (4, 7), (5, 7)]
[(0, 5), (0, 6), (0, 7), (1, 5), (1, 7), (2, 6), (3, 7), (4, 7), (5, 7)]
[(0, 5), (0, 6), (0, 7), (1, 5), (1, 6), (2, 6), (2, 7), (3, 7), (4, 7)]
[(0, 5), (0, 6), (1, 5), (1, 6), (2, 6), (2, 7), (3, 7), (4, 7), (5, 7)]
[(0, 5), (0, 7), (1, 5), (1, 7), (2, 6), (2, 7), (3, 6), (4, 6), (5, 7)]
[(0, 5), (0, 7), (1, 5), (2, 6), (2, 7), (3, 6), (3, 7), (4, 6), (6, 7)]
[(0, 5), (0, 7), (1, 5), (1, 7), (2, 6), (2, 7), (3, 6), (4, 7), (5, 6)]
[(0, 5), (0, 7), (1, 5), (1, 7), (2, 6), (3, 6), (4, 7), (5, 6), (5, 7)]
[(0, 4), (0, 6), (1, 5), (1, 7), (2, 6), (2, 7), (3, 7), (4, 7), (5, 7)]
[(0, 4), (0, 6), (0, 7), (1, 5), (1, 7), (2, 6), (3, 7), (5, 7), (6, 7)]
[(0, 4), (0, 6), (0, 7), (1, 5), (1, 7), (2, 7), (3, 7), (4, 6), (4, 7)]
[(0, 4), (0, 6), (1, 5), (1, 7), (2, 6), (2, 7), (3, 6), (4, 7), (5, 7)]
[(0, 4), (0, 6), (0, 7), (1, 5), (1, 7), (2, 6), (3, 6), (5, 7), (6, 7)]
[(0, 4), (0, 6), (0, 7), (1, 5), (1, 6), (1, 7), (2, 7), (3, 7), (4, 6)]
[(0, 4), (0, 6), (1, 5), (1, 7), (2, 6), (2, 7), (3, 7), (4, 6), (5, 7)]
[(0, 4), (0, 5), (0, 7), (1, 5), (1, 6), (2, 6), (2, 7), (3, 7), (4, 7)]
[(0, 4), (0, 5), (0, 7), (1, 5), (1, 7), (2, 6), (3, 6), (4, 7), (6, 7)]
[(0, 4), (0, 7), (1, 5), (1, 6), (2, 5), (2, 7), (3, 6), (4, 7), (5, 7)]
[(0, 4), (0, 6), (1, 5), (1, 6), (2, 5), (2, 7), (3, 6), (4, 7), (5, 7)]
[(0, 4), (0, 6), (0, 7), (1, 5), (2, 5), (3, 6), (3, 7), (4, 6), (5, 7)]
[(0, 4), (0, 5), (0, 7), (1, 6), (2, 6), (3, 7), (4, 5), (4, 7), (6, 7)]
[(0, 4), (0, 5), (1, 4), (1, 6), (2, 5), (2, 6), (2, 7), (3, 7), (4, 7)]
[(0, 3), (0, 6), (1, 4), (1, 6), (2, 5), (2, 7), (3, 6), (4, 7), (5, 7)]

One could construct the list by using nauty's generator and filtering by the desired conditions.

There are 236 bicyclic graphs on 8 vertices:

sage: gg bg8 = [g for g in graphs.nauty_geng("8 -c") if g.size() == 9
....:       and 9]
sage: len(bg8)
236

Out of those, 30 have second smallest eigenvalue equal to 1:

sage: gg = [g for g in bg8 if g.laplacian_matrix().eigenvalues()[1] == 1]

There are 30 such graphs:

sage: len(gg)
30

To show them:

sage: for g in gg:
....:     g.show()

To list their edges:

sage: for g in gg:
....:     print(g.edges(labels=None))
....:
[(0, 5), (0, 6), (0, 7), (1, 6), (1, 7), (2, 7), (3, 7), (4, 7), (6, 7)]
[(0, 5), (0, 6), (1, 6), (1, 7), (2, 6), (2, 7), (3, 7), (4, 7), (5, 7)]
[(0, 5), (0, 6), (1, 6), (1, 7), (2, 6), (2, 7), (3, 7), (4, 7), (6, 7)]
[(0, 5), (0, 6), (0, 7), (1, 6), (2, 6), (3, 7), (4, 7), (5, 7), (6, 7)]
[(0, 5), (0, 6), (1, 6), (1, 7), (2, 6), (3, 7), (4, 7), (5, 7), (6, 7)]
[(0, 5), (0, 6), (0, 7), (1, 6), (2, 7), (3, 7), (4, 7), (5, 6), (6, 7)]
[(0, 5), (0, 6), (1, 6), (1, 7), (2, 6), (2, 7), (3, 6), (4, 7), (5, 7)]
[(0, 5), (0, 6), (0, 7), (1, 5), (1, 6), (2, 7), (3, 7), (4, 7), (5, 7)]
[(0, 5), (0, 6), (0, 7), (1, 5), (1, 7), (2, 6), (3, 7), (4, 7), (5, 7)]
[(0, 5), (0, 6), (0, 7), (1, 5), (1, 6), (2, 6), (2, 7), (3, 7), (4, 7)]
[(0, 5), (0, 6), (1, 5), (1, 6), (2, 6), (2, 7), (3, 7), (4, 7), (5, 7)]
[(0, 5), (0, 7), (1, 5), (1, 7), (2, 6), (2, 7), (3, 6), (4, 6), (5, 7)]
[(0, 5), (0, 7), (1, 5), (2, 6), (2, 7), (3, 6), (3, 7), (4, 6), (6, 7)]
[(0, 5), (0, 7), (1, 5), (1, 7), (2, 6), (2, 7), (3, 6), (4, 7), (5, 6)]
[(0, 5), (0, 7), (1, 5), (1, 7), (2, 6), (3, 6), (4, 7), (5, 6), (5, 7)]
[(0, 4), (0, 6), (1, 5), (1, 7), (2, 6), (2, 7), (3, 7), (4, 7), (5, 7)]
[(0, 4), (0, 6), (0, 7), (1, 5), (1, 7), (2, 6), (3, 7), (5, 7), (6, 7)]
[(0, 4), (0, 6), (0, 7), (1, 5), (1, 7), (2, 7), (3, 7), (4, 6), (4, 7)]
[(0, 4), (0, 6), (1, 5), (1, 7), (2, 6), (2, 7), (3, 6), (4, 7), (5, 7)]
[(0, 4), (0, 6), (0, 7), (1, 5), (1, 7), (2, 6), (3, 6), (5, 7), (6, 7)]
[(0, 4), (0, 6), (0, 7), (1, 5), (1, 6), (1, 7), (2, 7), (3, 7), (4, 6)]
[(0, 4), (0, 6), (1, 5), (1, 7), (2, 6), (2, 7), (3, 7), (4, 6), (5, 7)]
[(0, 4), (0, 5), (0, 7), (1, 5), (1, 6), (2, 6), (2, 7), (3, 7), (4, 7)]
[(0, 4), (0, 5), (0, 7), (1, 5), (1, 7), (2, 6), (3, 6), (4, 7), (6, 7)]
[(0, 4), (0, 7), (1, 5), (1, 6), (2, 5), (2, 7), (3, 6), (4, 7), (5, 7)]
[(0, 4), (0, 6), (1, 5), (1, 6), (2, 5), (2, 7), (3, 6), (4, 7), (5, 7)]
[(0, 4), (0, 6), (0, 7), (1, 5), (2, 5), (3, 6), (3, 7), (4, 6), (5, 7)]
[(0, 4), (0, 5), (0, 7), (1, 6), (2, 6), (3, 7), (4, 5), (4, 7), (6, 7)]
[(0, 4), (0, 5), (1, 4), (1, 6), (2, 5), (2, 6), (2, 7), (3, 7), (4, 7)]
[(0, 3), (0, 6), (1, 4), (1, 6), (2, 5), (2, 7), (3, 6), (4, 7), (5, 7)]

One could construct the list by using nauty's generator and filtering by the desired conditions.

There are 236 bicyclic graphs on 8 vertices:

sage: bg8 = [g for g in graphs.nauty_geng("8 -c") if g.size() == 9]
sage: len(bg8)
236

Out of those, 30 3 have second smallest eigenvalue equal to 1:

sage: gg = [g for g in bg8 if g.laplacian_matrix().eigenvalues()[1] sorted(g.laplacian_matrix().eigenvalues())[1] == 1]
sage: gg
[Graph on 8 vertices, Graph on 8 vertices, Graph on 8 vertices]
sage: len(gg)
30

To show them:

sage: for g in gg:
....:     g.show()

To list 3

List their edges:

sage: for g in gg:
....:     print(g.edges(labels=None))
....:
[(0, 5), 6), (0, 6), (0, 7), (1, 6), (1, 7), (2, 7), (3, 7), (4, 7), (5, 7), (6, 7)]
[(0, 5), (0, 6), (1, 6), (1, 7), (2, 6), 7), (1, 6), (1, 7), (2, 7), (3, 7), (4, 7), (5, 7)]
[(0, 5), (0, 6), (1, 6), (1, 7), (2, 6), (2, 7), (3, 7), (4, 7), (6, 7)]
[(0, 5), (0, 6), (0, 7), (1, 6), (2, 6), (3, 7), (4, 7), (5, 7), (6, 7)]
[(0, 5), (0, 6), (1, 6), (1, 7), (2, 6), (3, 7), (4, 7), (5, 7), (6, 7)]
[(0, 5), (0, 6), (0, 7), (1, 6), (2, 7), (3, 7), (4, 7), (5, 6), (6, 7)]
[(0, 5), (0, 6), (1, 6), (1, 7), (2, 6), (2, 7), (3, 6), (4, 7), (5, 7)]
[(0, 5), (0, 6), (0, 7), (1, 5), (1, 6), (2, 7), (3, 7), (4, 7), (5, 7)]
[(0, 5), (0, 6), (0, 7), (1, 5), (1, 7), (2, 6), (3, 7), (4, 7), (5, 7)]
[(0, 5), (0, 6), (0, 7), (1, 5), (1, 6), (2, 6), (2, 7), (3, 7), (4, 7)]
[(0, 5), (0, 6), (1, 5), (1, 6), (2, 6), (2, 7), (3, 7), (4, 7), (5, 7)]
[(0, 5), (0, 7), (1, 5), (1, 7), (2, 6), (2, 7), (3, 6), (4, 6), (5, 7)]
[(0, 5), (0, 7), (1, 5), (2, 6), (2, 7), (3, 6), (3, 7), (4, 6), (6, 7)]
[(0, 5), (0, 7), (1, 5), (1, 7), (2, 6), (2, 7), (3, 6), (4, 7), (5, 6)]
[(0, 5), (0, 7), (1, 5), (1, 7), (2, 6), (3, 6), (4, 7), (5, 6), (5, 7)]
[(0, 4), (0, 6), (1, 5), (1, 7), (2, 6), (2, 7), (3, 7), (4, 7), (5, 7)]
[(0, 4), (0, 6), (0, 7), (1, 5), (1, 7), (2, 6), (3, 7), (5, 7), (6, 7)]
[(0, 4), (0, 6), (0, 7), (1, 5), (1, 7), (2, 7), (3, 7), (4, 6), (4, 7)]
[(0, 4), (0, 6), (1, 5), (1, 7), (2, 6), (2, 7), (3, 6), (4, 7), (5, 7)]
[(0, 4), (0, 6), (0, 7), (1, 5), (1, 7), (2, 6), (3, 6), (5, 7), (6, 7)]
[(0, 4), (0, 6), (0, 7), (1, 5), (1, 6), (1, 7), (2, 7), (3, 7), (4, 6)]
[(0, 4), (0, 6), (1, 5), (1, 7), (2, 6), (2, 7), (3, 7), (4, 6), (5, 7)]
[(0, 4), (0, 5), (0, 7), (1, 5), (1, 6), (2, 6), (2, 7), (3, 7), (4, 7)]
[(0, 4), (0, 5), (0, 7), (1, 5), (1, 7), (2, 6), (3, 6), (4, 7), (6, 7)]
[(0, 4), (0, 7), (1, 5), (1, 6), (2, 5), (2, 7), (3, 6), (4, 7), (5, 7)]
[(0, 4), (0, 6), (1, 5), (1, 6), (2, 5), (2, 7), (3, 6), (4, 7), (5, 7)]
[(0, 4), (0, 6), (0, 7), (1, 5), (2, 5), (3, 6), (3, 7), (4, 6), (5, 7)]
[(0, 4), (0, 5), (0, 7), (1, 6), (2, 6), (3, 7), (4, 5), (4, 7), (6, 7)]
[(0, 4), (0, 5), (1, 4), (1, 6), (2, 5), (2, 6), (2, 7), (3, 7), (4, 7)]
[(0, 3), (0, 6), (1, 4), (1, 6), (2, 5), (2, 7), 6), (3, 6), 7), (4, 7), (5, 7)]

Show them:

sage: for g in gg:
....:     g.show()

[Edited to take comments into account.]

One could can construct the list by using nauty's Nauty's generator and filtering filtering by the desired conditions.

Note that Nauty's generator can already filter by minimum and maximum number of edges using mine:maxe (for "minimum number of edges", "maximum number of edges") -- thanks to @rburing for pointing this out; see note below on ways to browse the documentation.

There are 236 bicyclic graphs on 8 vertices:

sage: bg8 bicy8 = [g for g in graphs.nauty_geng("8 -c") if g.size() == 9]
sage: len(bg8)
9:9 -c")]
sage: len(bicy8)
236

Out of those, 3 have second For a given graph g, its algebraic connectivity is the second smallest eigenvalue equal to 1:laplacian eigenvalue, so it can be obtained as sorted(g.laplacian_matrix().eigenvalues())[1].

Compute their algebraic connectivity, and the top algebraic connectivity:

sage: ac = [sorted(g.laplacian_matrix().eigenvalues())[1] for g in bicy8]
sage: tac = max(ac)
1

Extract graphs with top algebraic connectivity:

sage: gg = [g for i, g in bg8 enumerate(bicy8) if sorted(g.laplacian_matrix().eigenvalues())[1] ac[i] == 1]
sage: gg
[Graph on 8 vertices, Graph on 8 vertices, Graph on 8 vertices]
tac]

There are three:

sage: len(gg)
3

List their Their edges:

sage: for g in gg:
....:     print(g.edges(labels=None))
....:
[(0, 6), (0, 7), (1, 6), (1, 7), (2, 7), (3, 7), (4, 7), (5, 7), (6, 7)]
[(0, 5), (0, 7), (1, 6), (1, 7), (2, 7), (3, 7), (4, 7), (5, 7), (6, 7)]
[(0, 3), (0, 6), (1, 4), (1, 6), (2, 5), (2, 6), (3, 7), (4, 7), (5, 7)]

Show them:

sage: for g in gg:
....:     g.show()

Note on the documentation of Nauty's generator.

The documentation is available via any of the following solutions, which respectively give the documentation in text mode, the full source code in text mode, and the documentation in html mode:

$ graphs.nauty_geng?
$ graphs.nauty_geng??
$ browse_sage_doc(graphs.nauty_geng)

The html documentation can also be browsed locally (at least if you installed from source or from binaries from the Sage download pages) by pointing a browser to SAGE_ROOT/local/share/doc (where SAGE_ROOT denotes the root directory of your local Sage installation).

Or see the online SageMath documentation (html or pdf).

[Edited to take comments into account.]

Bicyclic graphs with top algebraic connectivity

One can construct the list using Nauty's generator and filtering by the desired conditions.

Note that Nauty's generator can already filter by minimum and maximum number of edges using mine:maxe (for "minimum number of edges", "maximum number of edges") -- thanks to @rburing for pointing this out; see note below on ways to browse the documentation.

There are 236 bicyclic graphs on 8 vertices:

sage: bicy8 = [g for g in graphs.nauty_geng("8 9:9 -c")]
sage: len(bicy8)
236

For a given graph g, its algebraic connectivity is the second smallest laplacian eigenvalue, so it can be obtained as sorted(g.laplacian_matrix().eigenvalues())[1].

Compute their algebraic connectivity, and the top algebraic connectivity:

sage: ac = [sorted(g.laplacian_matrix().eigenvalues())[1] for g in bicy8]
sage: tac = max(ac)
1

Extract graphs with top algebraic connectivity:

sage: gg = [g for i, g in enumerate(bicy8) if ac[i] == tac]

There are three:

sage: len(gg)
3

Their edges:

sage: for g in gg:
....:     print(g.edges(labels=None))
....:
[(0, 6), (0, 7), (1, 6), (1, 7), (2, 7), (3, 7), (4, 7), (5, 7), (6, 7)]
[(0, 5), (0, 7), (1, 6), (1, 7), (2, 7), (3, 7), (4, 7), (5, 7), (6, 7)]
[(0, 3), (0, 6), (1, 4), (1, 6), (2, 5), (2, 6), (3, 7), (4, 7), (5, 7)]

Show them:

sage: for g in gg:
....:     g.show()

Note on the documentation

Documentation of Nauty's generator.

graph generator

The documentation is available via any of the following solutions, which respectively give the documentation in text mode, the full source code in text mode, and the documentation in html mode:

$ graphs.nauty_geng?
$ graphs.nauty_geng??
$ browse_sage_doc(graphs.nauty_geng)

The html documentation can also be browsed locally (at least if you installed from source or from binaries from the Sage download pages) by pointing a browser to SAGE_ROOT/local/share/doc (where SAGE_ROOT denotes the root directory of your local Sage installation).

Or see the online SageMath documentation (html or pdf).

To avoid storing a long list graphs

To avoid storing all bicyclic graphs on 8 vertices in a list, one could run through them, keeping and updating a current value of the top algebraic connectivity and a current list of graphs achieving it.

sage: tac = 0
sage: gtac = []
sage: for g in graphs.nauty_geng("8 9:9 -c"):
....:     ac = sorted(g.laplacian_matrix().eigenvalues())[1]
....:     if ac == tac:
....:         gtac.append(g)
....:     elif ac > tac:
....:         tac, gtac = ac, [g]

In the end we get the top algebraic connectivity:

sage: tac
1

and know how many graphs achieve it:

sage: len(gtac)
3

and we can show their edges:

sage: [g.edges(labels=None) for g in gtac]
[[(0, 6), (0, 7), (1, 6), (1, 7), (2, 7), (3, 7), (4, 7), (5, 7), (6, 7)],
 [(0, 5), (0, 7), (1, 6), (1, 7), (2, 7), (3, 7), (4, 7), (5, 7), (6, 7)],
 [(0, 3), (0, 6), (1, 4), (1, 6), (2, 5), (2, 6), (3, 7), (4, 7), (5, 7)]]

or visualize them:

sage: for g in gtac:
....:     g.show(layout='circular')

Note there are other options for visualization, including:

  • g.show(layout='circular')
  • g.show(layout='planar')
  • g.show(method='js')

Defining a function

The code above can be turned into a function of the number of vertices:

def top_alg_conn(n):
    m = n + 1
    tac = 0
    gtac = []
    for g in graphs.nauty_geng("{} {}:{} -c".format(n, m, m)):
        ac = sorted(g.laplacian_matrix().eigenvalues())[1]
        if ac == tac:
            gtac.append(g)
        elif ac > tac:
            tac, gtac = ac, [g]
    return tac, gtac

For 9 vertices this might take something like 10 seconds:

sage: tac, gtac = top_alg_conn(9)
sage: tac, len(gtac)
(1, 2)
sage: for g in gtac:
....:     print(g.edges(labels=False))
[(0, 7), (0, 8), (1, 7), (1, 8), (2, 8), (3, 8), (4, 8), (5, 8), (6, 8), (7, 8)]
[(0, 6), (0, 8), (1, 7), (1, 8), (2, 8), (3, 8), (4, 8), (5, 8), (6, 8), (7, 8)]

For 10 vertices this might take on the order of 30 seconds:

sage: tac, gtac = top_alg_conn(10)
sage: tac, len(gtac)
(1, 2)
sage: for g in gtac:
....:     print(g.edges(labels=False))
[(0, 8), (0, 9), (1, 8), (1, 9), (2, 9), (3, 9), (4, 9), (5, 9), (6, 9), (7, 9), (8, 9)]
[(0, 7), (0, 9), (1, 8), (1, 9), (2, 9), (3, 9), (4, 9), (5, 9), (6, 9), (7, 9), (8, 9)]

For 11 vertices this might take on the order of 2 minutes:

sage: tac, len(gtac)
(1, 2)
sage: for g in gtac:
....:     print(g.edges(labels=False))
[(0, 9), (0, 10), (1, 9), (1, 10), (2, 10), (3, 10), (4, 10), (5, 10), (6, 10), (7, 10), (8, 10), (9, 10)]
[(0, 8), (0, 10), (1, 9), (1, 10), (2, 10), (3, 10), (4, 10), (5, 10), (6, 10), (7, 10), (8, 10), (9, 10)]

And so on...

[Edited to take comments into account.]

Bicyclic graphs with top algebraic connectivity

One can construct the list using Nauty's generator and filtering by the desired conditions.

Note that Nauty's generator can already filter by minimum and maximum number of edges using mine:maxe (for "minimum number of edges", "maximum number of edges") -- thanks to @rburing for pointing this out; see note below on ways to browse the documentation.

There are 236 bicyclic graphs on 8 vertices:

sage: bicy8 = [g for g in graphs.nauty_geng("8 9:9 -c")]
sage: len(bicy8)
236

For a given graph g, its algebraic connectivity is the second smallest laplacian eigenvalue, so it can be obtained as sorted(g.laplacian_matrix().eigenvalues())[1].

Compute their algebraic connectivity, and the top algebraic connectivity:

sage: ac = [sorted(g.laplacian_matrix().eigenvalues())[1] for g in bicy8]
sage: tac = max(ac)
1

Extract graphs with top algebraic connectivity:

sage: gg = [g for i, g in enumerate(bicy8) if ac[i] == tac]

There are three:

sage: len(gg)
3

Their edges:

sage: for g in gg:
....:     print(g.edges(labels=None))
....:
[(0, 6), (0, 7), (1, 6), (1, 7), (2, 7), (3, 7), (4, 7), (5, 7), (6, 7)]
[(0, 5), (0, 7), (1, 6), (1, 7), (2, 7), (3, 7), (4, 7), (5, 7), (6, 7)]
[(0, 3), (0, 6), (1, 4), (1, 6), (2, 5), (2, 6), (3, 7), (4, 7), (5, 7)]

Show them:

sage: for g in gg:
....:     g.show()

Documentation of Nauty's graph generator

The documentation is available via any of the following solutions, which respectively give the documentation in text mode, the full source code in text mode, and the documentation in html mode:

$ graphs.nauty_geng?
$ graphs.nauty_geng??
$ browse_sage_doc(graphs.nauty_geng)

The html documentation can also be browsed locally (at least if you installed from source or from binaries from the Sage download pages) by pointing a browser to SAGE_ROOT/local/share/doc (where SAGE_ROOT denotes the root directory of your local Sage installation).

Or see the online SageMath documentation (html or pdf).

To avoid storing a long list graphs

To avoid storing all bicyclic graphs on 8 vertices in a list, one could run through them, keeping and updating a current value of the top algebraic connectivity and a current list of graphs achieving it.

sage: tac = 0
sage: gtac = []
sage: for g in graphs.nauty_geng("8 9:9 -c"):
....:     ac = sorted(g.laplacian_matrix().eigenvalues())[1]
....:     if ac == tac:
....:         gtac.append(g)
....:     elif ac > tac:
....:         tac, gtac = ac, [g]

In the end we get the top algebraic connectivity:

sage: tac
1

and know how many graphs achieve it:

sage: len(gtac)
3

and we can show their edges:

sage: [g.edges(labels=None) for g in gtac]
[[(0, 6), (0, 7), (1, 6), (1, 7), (2, 7), (3, 7), (4, 7), (5, 7), (6, 7)],
 [(0, 5), (0, 7), (1, 6), (1, 7), (2, 7), (3, 7), (4, 7), (5, 7), (6, 7)],
 [(0, 3), (0, 6), (1, 4), (1, 6), (2, 5), (2, 6), (3, 7), (4, 7), (5, 7)]]

or visualize them:

sage: for g in gtac:
....:     g.show(layout='circular')

Note there are other options for visualization, including:

  • g.show(layout='circular')
  • g.show(layout='planar')
  • g.show(method='js')

Defining a function

The code above can be turned into a function of the number of vertices:

def top_alg_conn(n):
    m = n + 1
    tac = 0
    gtac = []
    for g in graphs.nauty_geng("{} {}:{} -c".format(n, m, m)):
        ac = sorted(g.laplacian_matrix().eigenvalues())[1]
        if ac == tac:
            gtac.append(g)
        elif ac > tac:
            tac, gtac = ac, [g]
    return tac, gtac

For 9 vertices this might take something like 10 seconds:

sage: tac, gtac = top_alg_conn(9)
sage: tac, len(gtac)
(1, 2)
sage: for g in gtac:
....:     print(g.edges(labels=False))
[(0, 7), (0, 8), (1, 7), (1, 8), (2, 8), (3, 8), (4, 8), (5, 8), (6, 8), (7, 8)]
[(0, 6), (0, 8), (1, 7), (1, 8), (2, 8), (3, 8), (4, 8), (5, 8), (6, 8), (7, 8)]

For 10 vertices this might take on the order of 30 seconds:

sage: tac, gtac = top_alg_conn(10)
sage: tac, len(gtac)
(1, 2)
sage: for g in gtac:
....:     print(g.edges(labels=False))
[(0, 8), (0, 9), (1, 8), (1, 9), (2, 9), (3, 9), (4, 9), (5, 9), (6, 9), (7, 9), (8, 9)]
[(0, 7), (0, 9), (1, 8), (1, 9), (2, 9), (3, 9), (4, 9), (5, 9), (6, 9), (7, 9), (8, 9)]

For 11 vertices this might take on the order of 2 minutes:

sage: %time tac, gtac = top_alg_conn(11)
CPU times: user 2min 5s, sys: 960 ms, total: 2min 6s
Wall time: 2min 9s

sage: tac, len(gtac)
(1, 2)
sage: for g in gtac:
....:     print(g.edges(labels=False))
[(0, 9), (0, 10), (1, 9), (1, 10), (2, 10), (3, 10), (4, 10), (5, 10), (6, 10), (7, 10), (8, 10), (9, 10)]
[(0, 8), (0, 10), (1, 9), (1, 10), (2, 10), (3, 10), (4, 10), (5, 10), (6, 10), (7, 10), (8, 10), (9, 10)]

And so on...