Ask Your Question
1

Output of plantri and graphs.planar_graphs

asked 2018-05-25 16:08:27 -0500

standardtrickyness gravatar image

updated 2018-06-05 23:38:35 -0500

slelievre gravatar image

I find the documentation of Sage much lacking what is the output of plantri and graphs.planar_graphs?

I assumed the output would be graphs (could not find documentation on this) and did the following

l = graphs.planar_graphs(4, dual=False)    
gen = list(l)       
ii = 1
G = gen[ii] 
p = G.plot()
p.show()
edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
0

answered 2018-06-27 05:37:43 -0500

slelievre gravatar image

The output of a command like graphs.planar_graphs(4) is an iterator that can yield all planar graphs with the specified number of vertices.

To get the documentation, do one of the following:

  • in Sage, type graphs.planar_graph? and hit the return or enter key.

    This will display the documentation for this function, in text mode.

  • in Sage, type graphs.planar_graph?? and hit the return or enter key.

    This will display the code source for this function, including the documentation string.

  • in Sage, type browse_sage_doc(graphs.planar_graph).

    This will open the documentation for this function, in html, in a browser tab.

  • browse the online documentation:

So for example, if you define

sage: gen = graphs.planar_graphs(n)

and turn it into a list

sage: G = list(gen)

you could display a summary of this list of graphs and their diameters:

sage: newline = '\n'
sage: s = 'There are {} planar graphs on {} vertices.'
sage: s = s.format(n, len(G))
sage: for j, g in enumerate(G):
....:     s += newline + '{}.'.format(j)
....:     s += newline + 'Edges: {}'.format(g.edges(labels=False))
....:     s += newline + 'Diameter: {}'.format(g.diameter())
....:
sage: print(s)
There are 4 planar graphs on 6 vertices.
0.
Edges: [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
Diameter: 1
1.
Edges: [(1, 2), (1, 3), (2, 3), (2, 4), (3, 4)]
Diameter: 2
2.
Edges: [(1, 2), (1, 3), (2, 4), (3, 4)]
Diameter: 2
3.
Edges: [(1, 2), (2, 3), (2, 4), (3, 4)]
Diameter: 2
4.
Edges: [(1, 2), (2, 3), (3, 4)]
Diameter: 3
5.
Edges: [(1, 2), (2, 3), (2, 4)]
Diameter: 2

or plot them all:

sage: for g in G:
....:     plot(g)
....: 
Launched png viewer for Graphics object consisting of 11 graphics primitives
Launched png viewer for Graphics object consisting of 10 graphics primitives
Launched png viewer for Graphics object consisting of 9 graphics primitives
Launched png viewer for Graphics object consisting of 9 graphics primitives
Launched png viewer for Graphics object consisting of 8 graphics primitives
Launched png viewer for Graphics object consisting of 8 graphics primitives

etc.

Don't hesitate to suggest any specific improvement to the documentation.

edit flag offensive delete link more
2

answered 2018-06-05 15:35:38 -0500

Sébastien gravatar image

To get the documentation on the function you mention, you do:

sage: graphs.planar_graphs?

which gives:

[...]

   An iterator over connected planar graphs using the plantri
   generator.

   This uses the plantri generator (see [plantri]) which is available
   through the optional package plantri.

   Note: The non-3-connected graphs will be returned several times,
     with all its possible embeddings.

[...]

You may also read the documentation of planar_graphs function online.

The output is not a graph, neither a list. It is an iterator of graphs.

edit flag offensive delete link more

Comments

To learn more about iterators, you can go through the tutorial at

slelievre gravatar imageslelievre ( 2018-06-05 23:41:36 -0500 )edit

Note about getting to know more about any function, method or module in Sage:

  • graphs.planar_graphs? gives the documentation of graphs.planar_graphs
  • help(graphs.planar_graphs) does the same
  • graphs.planar_graphs?? gives the source code
  • browse_sage_doc(graphs.planar_graphs) gives the documentation in html
  • search_src('graphs.planar_graphs') looks for all occurrences in Sage's source code
  • search_doc('graphs.planar_graphs') looks for all occurrences in Sage's documentation

For Python built-ins, such as for, while, if, use python_help, as in

python_help('if')
slelievre gravatar imageslelievre ( 2018-06-05 23:49:36 -0500 )edit

Thank both, but it doesn't quite answer my question what is the output of plantri and graphs.planar_graphs how come when I use the output as a graph I do not get a plot as usual? and I guess how to get a "graph" from a planar graph in the easiest way possible?

standardtrickyness gravatar imagestandardtrickyness ( 2018-06-26 16:10:07 -0500 )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: 2018-05-25 16:08:27 -0500

Seen: 71 times

Last updated: Jun 27