Ask Your Question
1

How to find the graphs from the following collection whose determinant is maximum?

asked 2025-03-06 20:20:14 +0100

anonymous user

Anonymous

updated 2025-03-06 20:40:55 +0100

Max Alekseyev gravatar image

.

for g in graphs.nauty_geng("7 -c"):
    if g.size()==9
    A=g.adjacency_matrix().determinant()
    if A!=0:
      g.show()
      show(A)
edit retag flag offensive close merge delete

Comments

What is your question given the code? Btw, you can specify the graphs size directly in nauty's parameters: for g in graphs.nauty_geng("-c 7 9:9"):

Max Alekseyev gravatar imageMax Alekseyev ( 2025-03-06 20:42:50 +0100 )edit

My question is to find the graph(s) on 7 vertices having 9 edges whose adjacency matrix determinant (absolute) is maximum among all other graphs on 7 vertices having 9 edges.

rewi gravatar imagerewi ( 2025-03-06 20:50:31 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2025-03-06 20:53:59 +0100

Max Alekseyev gravatar image

updated 2025-03-06 22:21:16 +0100

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

g = max(graphs.nauty_geng("-c 7 9:9"), key=lambda g: 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(abs(g.adjacency_matrix().determinant()) for g in graphs.nauty_geng("-c 7 9:9"))
G = filter(lambda g: 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 = abs(g.adjacency_matrix().determinant())
    if A > max_det:
        max_det = A
        G = [g]
    elif A == max_det:
        G.append(g)
edit flag offensive delete link more

Comments

ok. can we see the graphs also?

rewi gravatar imagerewi ( 2025-03-06 21:26:00 +0100 )edit

g is a graph, G is a container with graphs. You can see them like

for g in G: show(g)
Max Alekseyev gravatar imageMax Alekseyev ( 2025-03-06 21:27:43 +0100 )edit

But it is giving all the graphs which are not maximizing graphs. I need only the graphs with highest (absolute value) adjacency determinant.

rewi gravatar imagerewi ( 2025-03-06 21:37:32 +0100 )edit

Why all? G contains only graphs with the maximum determinant.

Max Alekseyev gravatar imageMax Alekseyev ( 2025-03-06 22:20:07 +0100 )edit

can you please put all the codes in a single code?

rewi gravatar imagerewi ( 2025-03-07 11:33:15 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2025-03-06 20:20:14 +0100

Seen: 143 times

Last updated: Mar 06