Ask Your Question

How to get a graph back from canonical_label graph6_string

asked 2012-12-04 08:46:46 -0600

dngraph gravatar image

updated 2012-12-04 09:31:40 -0600

I have a list of graphs that I take their canonical_label 's graph6_string and then I save that list to a file.

Now I want to open that file and get sage graphs from the list of canonical_label graph6_string

How can I do it?

Thank you!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-12-04 13:04:05 -0600

fidbc gravatar image

updated 2012-12-04 13:13:09 -0600

You could define the following function.

def get_graphs_from_file(filename):
    f = open( filename, 'r')
    graph_list=[ Graph( l[:-1] ) for l in f ]
    return graph_list

And now, assuming the file graphs.g6 contains a graph6 string per line, just run

sage: L=get_graphs_from_file( 'graphs.g6')

That should leave you with a list L of graphs.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools


Asked: 2012-12-04 08:46:46 -0600

Seen: 533 times

Last updated: Dec 04 '12