First time here? Check out the FAQ!

Ask Your Question
1

Determining Complete Multipartite Graphs (Specifically Tripartite)

asked 13 years ago

acacost1 gravatar image

updated 13 years ago

Mike Hansen gravatar image

I 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 following two lines of code to see if it would work for complete multipartite graphs.

def is_complete_multipartite(p):
    return p.is_multipartite() and p.num_edges() == mul(map(len, g.multipartite_sets()))

dd = filter(is_complete_multipartite, d)

I get a "graph attribute needed" error. I just wanted to verify that this is the case. Thanks again for the help!

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
3

answered 13 years ago

Mike Hansen gravatar image

You're getting that error because there is no is_multipartite method on graphs in Sage, nor is there a multipartite_sets method. You can use the coloring method to get what you need since a tripartite graph is 3-colourable. Thus, you could do something like the following: (To simplify things, I'll just consider the m > 1 case.)

def is_complete_multipartite(m):
    assert m > 1
    def is_complete_m_partite(g):
        coloring = g.coloring()
        if coloring is None: #empty graph
            return False
        return len(coloring) == m and g.num_edges() == mul(map(len, coloring))
    return is_complete_m_partite

Then, you'd use it like

dd = filter(is_complete_multipartite(3), d)

to test for complete tripartiteness.

Preview: (hide)
link

Comments

Thanks! I'll give it try.

acacost1 gravatar imageacacost1 ( 13 years ago )

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 13 years ago

Seen: 1,125 times

Last updated: Sep 14 '11