JunctionTreeBuilder { public void moralize() { for (GraphNode<BayesVariable> v : graph ) { for ( Edge e1 : v.getInEdges() ) { GraphNode pV1 = graph.getNode(e1.getOutGraphNode().getId()); moralize(v, pV1); } } } 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 testMoralize1() { 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); connectParentToChildren(x2, x1); connectParentToChildren(x3, x1); connectParentToChildren(x4, x1); JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder( graph ); assertLinkedNode(jtBuilder, new int[]{1, 2, 3, 4}); assertLinkedNode(jtBuilder, new int[]{2, 1}); assertLinkedNode(jtBuilder, new int[]{3, 1}); assertLinkedNode(jtBuilder, new int[]{4, 1}); jtBuilder.moralize(); assertLinkedNode(jtBuilder, new int[]{1, 2, 3, 4}); assertLinkedNode(jtBuilder, new int[]{2, 1, 3, 4}); assertLinkedNode(jtBuilder, new int[]{3, 1, 2, 4}); assertLinkedNode(jtBuilder, new int[]{4, 1, 2, 3}); }
@Test public void testMoralize2() { 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); connectParentToChildren(x1, x2, x3); connectParentToChildren(x2, x4); connectParentToChildren(x4, x5); connectParentToChildren(x3, x5); connectParentToChildren(x6, x5); JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder( graph ); jtBuilder.moralize(); assertLinkedNode(jtBuilder, new int[]{x1.getId(), 2, 3}); assertLinkedNode(jtBuilder, new int[]{x2.getId(), 1, 4}); assertLinkedNode(jtBuilder, new int[]{x3.getId(), 1, 4, 5, 6}); assertLinkedNode(jtBuilder, new int[]{x4.getId(), 2, 3, 5, 6}); assertLinkedNode(jtBuilder, new int[]{x5.getId(), 3, 4, 6}); assertLinkedNode(jtBuilder, new int[]{x6.getId(), 3, 4, 5}); }