ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 22 Mar 2021 20:42:19 +0100Generate certain number of planar graphs with graphs.planar_graphs?https://ask.sagemath.org/question/56313/generate-certain-number-of-planar-graphs-with-graphsplanar_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)?Mon, 22 Mar 2021 15:43:12 +0100https://ask.sagemath.org/question/56313/generate-certain-number-of-planar-graphs-with-graphsplanar_graphs/Comment by slelievre for <p>I want to use <code>graphs.planar_graphs</code> (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.</p>
<p>How can I do this with <code>graphs.planar_graphs</code>, since this is
an iterator that just creates <strong>all</strong> possible planar graphs
on 50 vertices (which is a lot more than I need and also
too computationally expensive)?</p>
https://ask.sagemath.org/question/56313/generate-certain-number-of-planar-graphs-with-graphsplanar_graphs/?comment=56319#post-id-56319Also asked as [Stack Overflow question 66749544](https://stackoverflow.com/q/66749544).Mon, 22 Mar 2021 20:42:19 +0100https://ask.sagemath.org/question/56313/generate-certain-number-of-planar-graphs-with-graphsplanar_graphs/?comment=56319#post-id-56319Answer by slelievre for <p>I want to use <code>graphs.planar_graphs</code> (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.</p>
<p>How can I do this with <code>graphs.planar_graphs</code>, since this is
an iterator that just creates <strong>all</strong> possible planar graphs
on 50 vertices (which is a lot more than I need and also
too computationally expensive)?</p>
https://ask.sagemath.org/question/56313/generate-certain-number-of-planar-graphs-with-graphsplanar_graphs/?answer=56318#post-id-56318Iterators 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]
Mon, 22 Mar 2021 18:23:28 +0100https://ask.sagemath.org/question/56313/generate-certain-number-of-planar-graphs-with-graphsplanar_graphs/?answer=56318#post-id-56318