ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 19 Dec 2013 10:14:15 -0600Sage and planar graphshttp://ask.sagemath.org/question/7904/sage-and-planar-graphs/How can I compute the faces of a planar embedding of a planar graph? And how to compute the dual of a plane graph?Tue, 17 Dec 2013 14:08:01 -0600http://ask.sagemath.org/question/7904/sage-and-planar-graphs/Answer by fidbc for <p>How can I compute the faces of a planar embedding of a planar graph? And how to compute the dual of a plane graph?</p>
http://ask.sagemath.org/question/7904/sage-and-planar-graphs/?answer=15837#post-id-15837About the faces of a planar graph, you can try using the `trace_faces` method for Graphs. For example:
sage: g=graphs.IcosahedralGraph()
sage: g.is_planar(set_embedding=True)
True
sage: g.trace_faces(g.get_embedding())
[[(10, 11), (11, 7), (7, 10)],
[(6, 4), (4, 3), (3, 6)],
[(5, 6), (6, 1), (1, 5)],
[(2, 8), (8, 1), (1, 2)],
[(9, 8), (8, 2), (2, 9)],
[(8, 0), (0, 1), (1, 8)],
[(3, 2), (2, 6), (6, 3)],
[(0, 7), (7, 11), (11, 0)],
[(2, 1), (1, 6), (6, 2)],
[(8, 9), (9, 7), (7, 8)],
[(4, 10), (10, 3), (3, 4)],
[(5, 4), (4, 6), (6, 5)],
[(11, 4), (4, 5), (5, 11)],
[(10, 4), (4, 11), (11, 10)],
[(9, 3), (3, 10), (10, 9)],
[(7, 0), (0, 8), (8, 7)],
[(11, 5), (5, 0), (0, 11)],
[(10, 7), (7, 9), (9, 10)],
[(2, 3), (3, 9), (9, 2)],
[(5, 1), (1, 0), (0, 5)]]
As @Nathann mentions, there seems to be no code to get the dual. However there seems to be some code for this in [trac](http://trac.sagemath.org/ticket/6236), perhaps you can start from there.
Wed, 18 Dec 2013 05:36:18 -0600http://ask.sagemath.org/question/7904/sage-and-planar-graphs/?answer=15837#post-id-15837Comment by Nathann for <p>About the faces of a planar graph, you can try using the <code>trace_faces</code> method for Graphs. For example:</p>
<pre><code>sage: g=graphs.IcosahedralGraph()
sage: g.is_planar(set_embedding=True)
True
sage: g.trace_faces(g.get_embedding())
[[(10, 11), (11, 7), (7, 10)],
[(6, 4), (4, 3), (3, 6)],
[(5, 6), (6, 1), (1, 5)],
[(2, 8), (8, 1), (1, 2)],
[(9, 8), (8, 2), (2, 9)],
[(8, 0), (0, 1), (1, 8)],
[(3, 2), (2, 6), (6, 3)],
[(0, 7), (7, 11), (11, 0)],
[(2, 1), (1, 6), (6, 2)],
[(8, 9), (9, 7), (7, 8)],
[(4, 10), (10, 3), (3, 4)],
[(5, 4), (4, 6), (6, 5)],
[(11, 4), (4, 5), (5, 11)],
[(10, 4), (4, 11), (11, 10)],
[(9, 3), (3, 10), (10, 9)],
[(7, 0), (0, 8), (8, 7)],
[(11, 5), (5, 0), (0, 11)],
[(10, 7), (7, 9), (9, 10)],
[(2, 3), (3, 9), (9, 2)],
[(5, 1), (1, 0), (0, 5)]]
</code></pre>
<p>As <a href="/users/30/nathann/">@Nathann</a> mentions, there seems to be no code to get the dual. However there seems to be some code for this in <a href="http://trac.sagemath.org/ticket/6236">trac</a>, perhaps you can start from there.</p>
http://ask.sagemath.org/question/7904/sage-and-planar-graphs/?comment=16521#post-id-16521This is now a trac ticket : http://trac.sagemath.org/ticket/15551Thu, 19 Dec 2013 10:14:15 -0600http://ask.sagemath.org/question/7904/sage-and-planar-graphs/?comment=16521#post-id-16521Comment by Nathann for <p>About the faces of a planar graph, you can try using the <code>trace_faces</code> method for Graphs. For example:</p>
<pre><code>sage: g=graphs.IcosahedralGraph()
sage: g.is_planar(set_embedding=True)
True
sage: g.trace_faces(g.get_embedding())
[[(10, 11), (11, 7), (7, 10)],
[(6, 4), (4, 3), (3, 6)],
[(5, 6), (6, 1), (1, 5)],
[(2, 8), (8, 1), (1, 2)],
[(9, 8), (8, 2), (2, 9)],
[(8, 0), (0, 1), (1, 8)],
[(3, 2), (2, 6), (6, 3)],
[(0, 7), (7, 11), (11, 0)],
[(2, 1), (1, 6), (6, 2)],
[(8, 9), (9, 7), (7, 8)],
[(4, 10), (10, 3), (3, 4)],
[(5, 4), (4, 6), (6, 5)],
[(11, 4), (4, 5), (5, 11)],
[(10, 4), (4, 11), (11, 10)],
[(9, 3), (3, 10), (10, 9)],
[(7, 0), (0, 8), (8, 7)],
[(11, 5), (5, 0), (0, 11)],
[(10, 7), (7, 9), (9, 10)],
[(2, 3), (3, 9), (9, 2)],
[(5, 1), (1, 0), (0, 5)]]
</code></pre>
<p>As <a href="/users/30/nathann/">@Nathann</a> mentions, there seems to be no code to get the dual. However there seems to be some code for this in <a href="http://trac.sagemath.org/ticket/6236">trac</a>, perhaps you can start from there.</p>
http://ask.sagemath.org/question/7904/sage-and-planar-graphs/?comment=16523#post-id-16523Hey, I didn't even know this function existed ! The docstring begins by saying that it is "a helper function to compute the genus of a graph". What about renaming it to "faces" and updating the docstring ? Could you review the patch if I write that ?Wed, 18 Dec 2013 22:21:48 -0600http://ask.sagemath.org/question/7904/sage-and-planar-graphs/?comment=16523#post-id-16523Comment by hbm for <p>About the faces of a planar graph, you can try using the <code>trace_faces</code> method for Graphs. For example:</p>
<pre><code>sage: g=graphs.IcosahedralGraph()
sage: g.is_planar(set_embedding=True)
True
sage: g.trace_faces(g.get_embedding())
[[(10, 11), (11, 7), (7, 10)],
[(6, 4), (4, 3), (3, 6)],
[(5, 6), (6, 1), (1, 5)],
[(2, 8), (8, 1), (1, 2)],
[(9, 8), (8, 2), (2, 9)],
[(8, 0), (0, 1), (1, 8)],
[(3, 2), (2, 6), (6, 3)],
[(0, 7), (7, 11), (11, 0)],
[(2, 1), (1, 6), (6, 2)],
[(8, 9), (9, 7), (7, 8)],
[(4, 10), (10, 3), (3, 4)],
[(5, 4), (4, 6), (6, 5)],
[(11, 4), (4, 5), (5, 11)],
[(10, 4), (4, 11), (11, 10)],
[(9, 3), (3, 10), (10, 9)],
[(7, 0), (0, 8), (8, 7)],
[(11, 5), (5, 0), (0, 11)],
[(10, 7), (7, 9), (9, 10)],
[(2, 3), (3, 9), (9, 2)],
[(5, 1), (1, 0), (0, 5)]]
</code></pre>
<p>As <a href="/users/30/nathann/">@Nathann</a> mentions, there seems to be no code to get the dual. However there seems to be some code for this in <a href="http://trac.sagemath.org/ticket/6236">trac</a>, perhaps you can start from there.</p>
http://ask.sagemath.org/question/7904/sage-and-planar-graphs/?comment=16525#post-id-16525Thank you.Wed, 18 Dec 2013 12:39:09 -0600http://ask.sagemath.org/question/7904/sage-and-planar-graphs/?comment=16525#post-id-16525Answer by Nathann for <p>How can I compute the faces of a planar embedding of a planar graph? And how to compute the dual of a plane graph?</p>
http://ask.sagemath.org/question/7904/sage-and-planar-graphs/?answer=15831#post-id-15831Hmmmmm... I don't think that we have functions for this, though we already have the tools. The `is_planar` method can give you an "embedding" dictionary, which can then be used to list all faces. It would be nice to have functions to do that directly, though.
Well, if you feel like coding them and adding them to Sage, I think that it may not be that much work and be very helpful :-)Tue, 17 Dec 2013 22:04:15 -0600http://ask.sagemath.org/question/7904/sage-and-planar-graphs/?answer=15831#post-id-15831Comment by hbm for <p>Hmmmmm... I don't think that we have functions for this, though we already have the tools. The <code>is_planar</code> method can give you an "embedding" dictionary, which can then be used to list all faces. It would be nice to have functions to do that directly, though.</p>
<p>Well, if you feel like coding them and adding them to Sage, I think that it may not be that much work and be very helpful :-)</p>
http://ask.sagemath.org/question/7904/sage-and-planar-graphs/?comment=16526#post-id-16526It would be probably best to modify is_planar to do it. Is the source for is_planar available? How can I get?Wed, 18 Dec 2013 07:04:16 -0600http://ask.sagemath.org/question/7904/sage-and-planar-graphs/?comment=16526#post-id-16526Comment by fidbc for <p>Hmmmmm... I don't think that we have functions for this, though we already have the tools. The <code>is_planar</code> method can give you an "embedding" dictionary, which can then be used to list all faces. It would be nice to have functions to do that directly, though.</p>
<p>Well, if you feel like coding them and adding them to Sage, I think that it may not be that much work and be very helpful :-)</p>
http://ask.sagemath.org/question/7904/sage-and-planar-graphs/?comment=16524#post-id-16524Of course the source is available! If `g` is a graph, you can access it by executing `g.is_planar??`. This seems to use the `is_planar` method from `sage.graphs`. I believe things get a bit complicated after this call.Wed, 18 Dec 2013 13:27:10 -0600http://ask.sagemath.org/question/7904/sage-and-planar-graphs/?comment=16524#post-id-16524