Ask Your Question
1

Generate certain number of planar graphs with graphs.planar_graphs?

asked 2021-03-22 16:20:44 +0200

lucv gravatar image

updated 2021-03-22 18:15:45 +0200

slelievre gravatar image

I want to use graphs.planar_graphs (which is based on plantri) to generate 1000 planar graphs of a certain size (e.g. 50 vertices), i.e. I want to use the iterator exactly 1000 times and not until it has created all possible solutions.

How can I do this with graphs.planar_graphs, since this is an iterator that just creates all possible planar graphs on 50 vertices (which is a lot more than I need and also too computationally expensive)?

edit retag flag offensive close merge delete

Comments

slelievre gravatar imageslelievre ( 2021-03-22 20:42:19 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-03-22 18:23:28 +0200

slelievre gravatar image

Iterators are wonderful.

One of the ways in which they are wonderful is you can grab as many or as few elements as you want.

The iterator for all planar graphs of order 50:

sage: planar_50 = graphs.planar_graphs(50)

Grab the first four:

sage: planar_50_4 = [next(planar_50) for _ in range(4)]

Check:

sage: planar_50_4
[Graph on 50 vertices,
 Graph on 50 vertices,
 Graph on 50 vertices,
 Graph on 50 vertices]
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

Stats

Asked: 2021-03-22 15:43:12 +0200

Seen: 31 times

Last updated: Mar 22