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:
Tree decomposition:
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
.