First time here? Check out the FAQ!

Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered 0 years ago

Max Alekseyev gravatar image

If you want a single graph, there is a one-liner:

g = max(graphs.nauty_geng("-c 7 9:9"), key=lambda g: g.adjacency_matrix().determinant())

Along these lines, we can make two passes over the graphs to get all graphs with the maximum determinant:

max_det = max(g.adjacency_matrix().determinant() for g in graphs.nauty_geng("-c 7 9:9"))
G = filter(lambda g: g.adjacency_matrix().determinant()==max_det, graphs.nauty_geng("-c 7 9:9"))

Finally, if only one pass is preferred, it can be done like this:

G = []
max_det = -oo
for g in graphs.nauty_geng("-c 7 9:9"):
    A = g.adjacency_matrix().determinant()
    if A > max_det:
        max_det = A
        G = [g]
    elif A == max_det:
        G.append(g)
click to hide/show revision 2
No.2 Revision

If you want a single graph, there is a one-liner:

g = max(graphs.nauty_geng("-c 7 9:9"), key=lambda g: g.adjacency_matrix().determinant())
abs(g.adjacency_matrix().determinant()))

Along these lines, we can make two passes over the graphs to get all graphs with the maximum determinant:

max_det = max(g.adjacency_matrix().determinant() max(abs(g.adjacency_matrix().determinant()) for g in graphs.nauty_geng("-c 7 9:9"))
G = filter(lambda g: g.adjacency_matrix().determinant()==max_det, abs(g.adjacency_matrix().determinant())==max_det, graphs.nauty_geng("-c 7 9:9"))

Finally, if only one pass is preferred, it can be done like this:

G = []
max_det = -oo
for g in graphs.nauty_geng("-c 7 9:9"):
    A = g.adjacency_matrix().determinant()
abs(g.adjacency_matrix().determinant())
    if A > max_det:
        max_det = A
        G = [g]
    elif A == max_det:
        G.append(g)