Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
501 views
in Technique[技术] by (71.8m points)

python - Algorithm for generating a tree decomposition

I want to construct a tree decomposition: http://en.wikipedia.org/wiki/Tree_decomposition and I have the chordal graph and a perfect elimination ordering. I am following advice given in a previous thread, namely:

To construct a non-nice (in general) tree decomposition of a chordal graph: find a perfect elimination ordering, enumerate the maximal cliques (the candidates are a vertex and the neighbors that appear after it in the ordering), use each clique as a decomposition node and connect it to the next clique in the ordering that it intersects.

This does not work however and I can not figure out why. Consider the following example:

Perfect elimination ordering:

['4', '3', '5', '7', '6', '2', '0', '1']

Chordal graph:

enter image description here

Tree decomposition:

enter image description here

I am using python and my current algorithm is the following:

T=nx.Graph()
    nodelist=[]
    for i in eo:
        vertex=str(i)
        bag=set()
        bag.add(vertex)
        for j in chordal_graph.neighbors(str(i)):
            bag.add(str(j))
        T.add_node(frozenset(bag))
        nodelist.append(frozenset(bag))
        chordal_graph.remove_node(str(i))
    for node1 in range(len(nodelist)):
        found=False
        for node2 in range(node1+1,len(nodelist)):
            if found==False and len(nodelist[node1].intersection(nodelist[node2]))>0:
                T.add_edge(nodelist[node1],nodelist[node2])
                found=True
    nx.draw(T)
    p.show()     

where eo is a list of the perfect ordering and 'chordal_graph' is a graph object for networkx.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

So that was my (bad, as it turns out) advice. Your tree decomposition has some cliques that aren't maximal, i.e., {2, 0, 1}, {0, 1}, and {1}. The list of candidate cliques is

{4, 5, 6} (maximal)
{3, 2} (maximal)
{5, 6, 2, 0} (maximal)
{7, 2, 1} (maximal)
{6, 2, 0, 1} (maximal)
{2, 0, 1} (not maximal: subset of {6, 2, 0, 1})
{0, 1} (not maximal: subset of {6, 2, 0, 1})
{1} (not maximal: subset of {6, 2, 0, 1})

Then the decomposition should look like

                {3, 2}
                  |
{4, 5, 6}----{5, 6, 2, 0}
                  |
             {7, 2, 1}
                  |
             {6, 2, 0, 1},

which is wrong as well, since the 0 vertices aren't connected. Sorry about that.

What I should have done is to set aside the maximality condition for the moment and to connect each clique K to the next candidate seeded with a vertex belonging to K. This ensures that every vertex in K that exists in at least one other subsequent clique also appears in the target of the connection. Then the decomposition looks like this

{4, 5, 6}----{5, 6, 2, 0}
                  |
             {6, 2, 0, 1}
                  |
   {3, 2}----{2, 0, 1}----{7, 2, 1}
                  |
                {0, 1}
                  |
                {1}

and you can splice out the non-maximal cliques by checking, for each clique in reverse order, whether it's a superset of its parent, and if so, reparenting its parent's children to it.

{4, 5, 6}----{5, 6, 2, 0}
                  |
   {3, 2}----{6, 2, 0, 1}----{7, 2, 1}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...