// ...and add the edges to jt that come to the top of the queue
// and don't cause a cycle.
// xxx OK, this sucks. openjgraph doesn't allow adding
// disconnected edges to a tree, so what we'll do is create a
// Graph frist, then convert it to a Tree.
ListenableUndirectedGraph g = new ListenableUndirectedGraph (new SimpleGraph ());
// first add every clique to the graph
for (Iterator it = cliques.iterator(); it.hasNext();) {
VarSet c = (VarSet) it.next();
g.addVertex (c);
}
ConnectivityInspector inspector = new ConnectivityInspector (g);
g.addGraphListener (inspector);
// then add n - 1 edges
int numCliques = cliques.size();
int edgesAdded = 0;
while (edgesAdded < numCliques - 1) {
VarSet[] pair = (VarSet[]) pq.first();
pq.remove(pair);
if (!inspector.pathExists(pair[0], pair[1])) {
g.addEdge(pair[0], pair[1]);
edgesAdded++;
}
}
JunctionTree jt = graphToJt(g);