JunctionTreeBuilder { public boolean[][] getAdjacencyMatrix() { return adjacencyMatrix; } 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 testPriorityQueueWithMinimalNewEdges() { Graph<BayesVariable> graph = new BayesNetwork(); GraphNode x0 = addNode(graph); GraphNode x1 = addNode(graph); GraphNode x2 = addNode(graph); GraphNode x3 = addNode(graph); GraphNode x4 = addNode(graph); GraphNode x5 = addNode(graph); GraphNode x6 = addNode(graph); GraphNode x7 = addNode(graph); GraphNode x8 = addNode(graph); GraphNode x9 = addNode(graph); GraphNode x10 = addNode(graph); GraphNode x11 = addNode(graph); GraphNode x12 = addNode(graph); connectParentToChildren(x2, x1); connectParentToChildren(x3, x1); connectParentToChildren(x4, x1); connectParentToChildren(x6, x5); connectParentToChildren(x7, x5); x5.setContent(new BayesVariable<String>("x5", x0.getId(), new String[]{"a", "b", "c"}, new double[][]{{0.1, 0.1, 0.1}})); x6.setContent(new BayesVariable<String>("x6", x0.getId(), new String[]{"a", "b", "c"}, new double[][]{{0.1, 0.1, 0.1}})); x7.setContent(new BayesVariable<String>("x7", x0.getId(), new String[]{"a", "b", "c"}, new double[][]{{0.1, 0.1, 0.1}})); connectParentToChildren(x9, x8); connectParentToChildren(x10, x8); connectParentToChildren(x11, x8); connectParentToChildren(x12, x8); JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder( graph ); PriorityQueue<EliminationCandidate> p = new PriorityQueue<EliminationCandidate>(graph.size()); EliminationCandidate elmCandVert = new EliminationCandidate(graph, jtBuilder.getAdjacencyMatrix(), x1); p.add( elmCandVert ); elmCandVert = new EliminationCandidate(graph, jtBuilder.getAdjacencyMatrix(), x5); p.add( elmCandVert ); elmCandVert = new EliminationCandidate(graph, jtBuilder.getAdjacencyMatrix(), x8); p.add( elmCandVert ); EliminationCandidate v = p.remove(); int id = v.getV().getId(); assertEquals( 5, id ); assertEquals( 1, v.getNewEdgesRequired() ); v = p.remove(); id = v.getV().getId(); assertEquals( 1, id ); assertEquals( 3, v.getNewEdgesRequired() ); v = p.remove(); id = v.getV().getId(); assertEquals( 8, id ); assertEquals( 6, v.getNewEdgesRequired() ); assertEquals( 0, p.size() ); }
@Test public void testPriorityQueueWithMaximalCliqueWeight() { Graph<BayesVariable> graph = new BayesNetwork(); GraphNode x0 = addNode(graph); GraphNode x1 = addNode(graph); GraphNode x2 = addNode(graph); GraphNode x3 = addNode(graph); GraphNode x4 = addNode(graph); GraphNode x5 = addNode(graph); GraphNode x6 = addNode(graph); GraphNode x7 = addNode(graph); GraphNode x8 = addNode(graph); GraphNode x9 = addNode(graph); GraphNode x10 = addNode(graph); GraphNode x11 = addNode(graph); GraphNode x12 = addNode(graph); connectParentToChildren(x2, x1); connectParentToChildren(x3, x1); connectParentToChildren(x4, x1); x1.setContent(new BayesVariable<String>("x1", x0.getId(), new String[]{"a", "b"}, new double[][]{{0.1, 0.1}})); x2.setContent(new BayesVariable<String>("x2", x0.getId(), new String[]{"a", "b"}, new double[][]{{0.1, 0.1}})); x3.setContent(new BayesVariable<String>("x3", x0.getId(), new String[]{"a", "b"}, new double[][]{{0.1, 0.1}})); x4.setContent(new BayesVariable<String>("x4", x0.getId(), new String[]{"a", "b"}, new double[][]{{0.1, 0.1}})); connectParentToChildren(x6, x5); connectParentToChildren(x7, x5); connectParentToChildren(x8, x5); x5.setContent(new BayesVariable<String>("x5", x0.getId(), new String[]{"a", "b", "c"}, new double[][]{{0.1, 0.1, 0.1}})); x6.setContent(new BayesVariable<String>("x6", x0.getId(), new String[]{"a", "b", "c"}, new double[][]{{0.1, 0.1, 0.1}})); x7.setContent(new BayesVariable<String>("x7", x0.getId(), new String[]{"a", "b", "c"}, new double[][]{{0.1, 0.1, 0.1}})); x8.setContent(new BayesVariable<String>("x8", x0.getId(), new String[]{"a", "b", "c"}, new double[][]{{0.1, 0.1, 0.1}})); connectParentToChildren(x10, x9); connectParentToChildren(x11, x9); connectParentToChildren(x12, x9); x9.setContent(new BayesVariable<String>("x9", x0.getId(), new String[]{"a"}, new double[][]{{0.1}})); x10.setContent(new BayesVariable<String>("x10", x0.getId(), new String[]{"a"}, new double[][]{{0.1}})); x11.setContent(new BayesVariable<String>("x11", x0.getId(), new String[]{"a", "b"}, new double[][]{{0.1, 0.1}})); x12.setContent(new BayesVariable<String>("x12", x0.getId(), new String[]{"a", "b"}, new double[][]{{0.1, 0.1}})); JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder( graph ); PriorityQueue<EliminationCandidate> p = new PriorityQueue<EliminationCandidate>(graph.size()); EliminationCandidate elmCandVert = new EliminationCandidate(graph, jtBuilder.getAdjacencyMatrix(), x1); p.add( elmCandVert ); elmCandVert = new EliminationCandidate(graph, jtBuilder.getAdjacencyMatrix(), x5); p.add( elmCandVert ); elmCandVert = new EliminationCandidate(graph, jtBuilder.getAdjacencyMatrix(), x9); p.add( elmCandVert ); EliminationCandidate v = p.remove(); int id = v.getV().getId(); assertEquals( 9, id ); assertEquals( 4, v.getWeightRequired() ); v = p.remove(); id = v.getV().getId(); assertEquals( 1, id ); assertEquals( 16, v.getWeightRequired() ); v = p.remove(); id = v.getV().getId(); assertEquals( 5, id ); assertEquals( 81, v.getWeightRequired() ); assertEquals( 0, p.size() ); }