Generating non-bipartite graphs.

asked 2017-01-18 00:24:19 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I use graphs.nauty_geng('n') to generate graphs on n vertices. By adding the flag -c (resp. -b), I will get filtered list of connected (resp. bipartite) graphs on n vertices. For example, see the following code:

for G in graphs.nauty_geng('6, -c'):
    if not G.is_bipartite():
        print "Graph" +str(c)+":"

This will generate a list of connected non-bipartite graphs on 6 vertices. I want to do the same by avoiding the if loop I have used. For example by replacing above with graphs.nauty_geng('6,-b'), I can get the list of bipartite ones. Is there any direct command which works just like -b and -c work?

Thanks in advance.

edit retag flag offensive close merge delete


Here is a way to generate the disconnected graphs on n vertices using an if loop.

c=0 for G in graphs.nauty_geng('n'): c=c+1 if not G.is_connected():

As I am new here, I don't know how to add a code here to be looked like just a way it works in sage. I hope you understand anyway.

Siki gravatar imageSiki ( 2017-01-25 02:55:08 -0500 )edit

Here is the code to generate disconnected graphs on 5 vertices. Thanks for your assistance about adding a code.

for G in graphs.nauty_geng('5'):
    if not G.is_connected():
        print "Graph" +str(c)+":"
Siki gravatar imageSiki ( 2017-01-30 01:28:27 -0500 )edit

Alright then.

Siki gravatar imageSiki ( 2017-02-12 00:44:46 -0500 )edit