Ask Your Question

# Generate certain number of planar graphs with graphs.planar_graphs?

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 close merge delete

## Comments

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

## 1 Answer

Sort by ยป oldest newest most voted

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]

more

## Your Answer

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

Add Answer

## Stats

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

Seen: 24 times

Last updated: Mar 22