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.Wed, 07 Sep 2011 01:08:51 +0200Determining Complete Bipartite Graphshttps://ask.sagemath.org/question/8299/determining-complete-bipartite-graphs/I have generated an extremely large list of graphs. Do you know if there is a way to determine which graphs in the list are Complete Bipartite graphs? I have tried a filter function: dd = filter(lambda x:x.completebipatitegraphs(), d), but it gives me an "attribute needed" error. Any help is greatly appreciated!Tue, 30 Aug 2011 11:56:35 +0200https://ask.sagemath.org/question/8299/determining-complete-bipartite-graphs/Answer by Dima for <p>I have generated an extremely large list of graphs. Do you know if there is a way to determine which graphs in the list are Complete Bipartite graphs? I have tried a filter function: dd = filter(lambda x:x.completebipatitegraphs(), d), but it gives me an "attribute needed" error. Any help is greatly appreciated!</p>
https://ask.sagemath.org/question/8299/determining-complete-bipartite-graphs/?answer=12622#post-id-12622in case you want to practice writing lambdas, you can do
dd=filter(lambda p: p.is_bipartite() and p.num_edges() == mul(map(len, p.bipartite_sets())), d)Sun, 04 Sep 2011 08:16:48 +0200https://ask.sagemath.org/question/8299/determining-complete-bipartite-graphs/?answer=12622#post-id-12622Comment by acacost1 for <p>in case you want to practice writing lambdas, you can do </p>
<pre><code>dd=filter(lambda p: p.is_bipartite() and p.num_edges() == mul(map(len, p.bipartite_sets())), d)
</code></pre>
https://ask.sagemath.org/question/8299/determining-complete-bipartite-graphs/?comment=21275#post-id-21275I have been reading the Sage References, and it does not seem that complete multipartite graphs are defined in Sage yet. I have tried to critique the code you have provide to try and see if it would work for complete multipartite graphs. I get a "graph attribute needed" error. I just wanted to verify that this is the case. Thanks again for the help!Wed, 07 Sep 2011 01:08:51 +0200https://ask.sagemath.org/question/8299/determining-complete-bipartite-graphs/?comment=21275#post-id-21275Answer by Mike Hansen for <p>I have generated an extremely large list of graphs. Do you know if there is a way to determine which graphs in the list are Complete Bipartite graphs? I have tried a filter function: dd = filter(lambda x:x.completebipatitegraphs(), d), but it gives me an "attribute needed" error. Any help is greatly appreciated!</p>
https://ask.sagemath.org/question/8299/determining-complete-bipartite-graphs/?answer=12613#post-id-12613You can use the following function to test if a graph is complete bipartite:
def is_complete_bipartite(p):
return p.is_bipartite() and p.num_edges() == mul(map(len, p.bipartite_sets()))
Then, you can do
dd = filter(is_complete_bipartite, d)
to get your list of complete bipartites.
Wed, 31 Aug 2011 13:14:31 +0200https://ask.sagemath.org/question/8299/determining-complete-bipartite-graphs/?answer=12613#post-id-12613Comment by acacost1 for <p>You can use the following function to test if a graph is complete bipartite:</p>
<pre><code>def is_complete_bipartite(p):
return p.is_bipartite() and p.num_edges() == mul(map(len, p.bipartite_sets()))
</code></pre>
<p>Then, you can do</p>
<pre><code>dd = filter(is_complete_bipartite, d)
</code></pre>
<p>to get your list of complete bipartites.</p>
https://ask.sagemath.org/question/8299/determining-complete-bipartite-graphs/?comment=21290#post-id-21290Thanks for the help! I got what I wanted.Thu, 01 Sep 2011 18:03:53 +0200https://ask.sagemath.org/question/8299/determining-complete-bipartite-graphs/?comment=21290#post-id-21290