JunctionTreeBuilder { public void createClique(int v, boolean[][] clonedAdjMatrix, Set<Integer> verticesToUpdate, boolean[] adjList) { for ( int i = 0; i < adjList.length; i++ ) { if ( !adjList[i] ) { continue; } getRelatedVerticesToUpdate(v, clonedAdjMatrix, verticesToUpdate, i); boolean needsConnection = false; for ( int j = i+1; j < adjList.length; j++ ) { if ( !adjList[j] || clonedAdjMatrix[i][j] ) { continue; } connect(adjacencyMatrix, i, j); connect(clonedAdjMatrix, i, j ); getRelatedVerticesToUpdate(v, clonedAdjMatrix, verticesToUpdate, j); needsConnection = true; } if ( needsConnection ) { verticesToUpdate.add( i ); } } } JunctionTreeBuilder(Graph<BayesVariable> graph); Graph<BayesVariable> getGraph(); JunctionTree build(); JunctionTree build(boolean init); JunctionTree build(Resource resource, String namespace, String name); JunctionTree build(Resource resource, String namespace, String name, boolean init); void moralize(); void moralize(GraphNode<BayesVariable> v, GraphNode v1); static void connect(boolean[][] adjMatrix, int v1, int v2); static void disconnect(boolean[][] adjMatrix, int v1, int v2); List<OpenBitSet> triangulate(); void eliminateVertex(PriorityQueue<EliminationCandidate> p, Map<Integer, EliminationCandidate> elmVertMap, boolean[][] clonedAdjMatrix, boolean[] adjList, Set<Integer> verticesToUpdate, EliminationCandidate v); void createClique(int v, boolean[][] clonedAdjMatrix, Set<Integer> verticesToUpdate, boolean[] adjList); static void updateCliques(List<OpenBitSet> cliques, OpenBitSet newClique); boolean[][] getAdjacencyMatrix(); static boolean[][] cloneAdjacencyMarix(boolean[][] src); JunctionTree junctionTree(List<OpenBitSet> cliques, boolean init); JunctionTree junctionTree(Resource resource, String namespace, String name, List<OpenBitSet> cliques, boolean init); void mergeGraphs(SeparatorSet[][][] graphs, SeparatorSet separatorSet); int createJunctionTreeGraph(SeparatorSet[][] sepGraph, JunctionTreeClique parent, JunctionTreeClique[] jtNodes, JunctionTreeSeparator[] jtSeps, int i); void mapNodeToCliqueFamily(OpenBitSet[] varNodeToCliques, JunctionTreeClique[] jtNodes); void mapVarNodeToCliques(OpenBitSet[] nodeToCliques, int id, OpenBitSet clique); static List<Integer> getAdjacentVertices(boolean[][] adjacencyMatrix, int i);  }
@Test public void testCreateClique() { Graph<BayesVariable> graph = new BayesNetwork(); GraphNode dX0 = addNode(graph); GraphNode dX1 = addNode(graph); GraphNode dX2 = addNode(graph); GraphNode dX3 = addNode(graph); GraphNode dX4 = addNode(graph); GraphNode dX5 = addNode(graph); connectParentToChildren(dX1, dX2, dX3, dX4); JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder( graph ); Set<Integer> vertices = new HashSet<Integer>(); boolean[] adjList = new boolean[] { false, false, true, true, true, false }; boolean[][] clonedAdjMatrix = JunctionTreeBuilder.cloneAdjacencyMarix(jtBuilder.getAdjacencyMatrix()); jtBuilder.createClique(dX1.getId(), clonedAdjMatrix, vertices, adjList ); assertEquals( 3, vertices.size() ); assertTrue( vertices.containsAll(Arrays.asList(new Integer[]{2, 3, 4})) ); assertLinkedNode(jtBuilder, 1, 2, 3, 4); assertLinkedNode(jtBuilder, 2, 1, 3, 4); assertLinkedNode(jtBuilder, 3, 1, 2, 4); assertLinkedNode(jtBuilder, 4, 1, 2, 3); }