use of org.drools.core.util.bitmask.OpenBitSet in project drools by kiegroup.
the class JunctionTreeBuilderTest method testCliqueSuperSet.
@Test
public void testCliqueSuperSet() {
Graph<BayesVariable> graph = new BayesNetwork();
JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder(graph);
List<OpenBitSet> cliques = new ArrayList<OpenBitSet>();
OpenBitSet OpenBitSet1 = bitSet("00011110");
jtBuilder.updateCliques(cliques, OpenBitSet1);
assertEquals(1, cliques.size());
// ignore subset
OpenBitSet OpenBitSet2 = bitSet("00000110");
jtBuilder.updateCliques(cliques, OpenBitSet2);
assertEquals(1, cliques.size());
assertEquals(OpenBitSet1, cliques.get(0));
// add overlapping, as not a pure subset
OpenBitSet OpenBitSet3 = bitSet("01000110");
jtBuilder.updateCliques(cliques, OpenBitSet3);
assertEquals(2, cliques.size());
assertEquals(OpenBitSet1, cliques.get(0));
assertEquals(OpenBitSet3, cliques.get(1));
}
use of org.drools.core.util.bitmask.OpenBitSet in project drools by kiegroup.
the class JunctionTreeBuilderTest method testJunctionTreeNoPruning.
@Test
public void testJunctionTreeNoPruning() {
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);
List<OpenBitSet> list = new ArrayList<OpenBitSet>();
OpenBitSet OpenBitSet1 = bitSet("00001111");
OpenBitSet OpenBitSet2 = bitSet("00111100");
// linear
OpenBitSet OpenBitSet3 = bitSet("11100000");
OpenBitSet intersect1And2 = ((OpenBitSet) OpenBitSet2.clone());
intersect1And2.and(OpenBitSet1);
OpenBitSet intersect2And3 = ((OpenBitSet) OpenBitSet2.clone());
intersect2And3.and(OpenBitSet3);
list.add(OpenBitSet1);
list.add(OpenBitSet2);
list.add(OpenBitSet3);
JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder(graph);
JunctionTreeClique jtNode = jtBuilder.junctionTree(list, false).getRoot();
assertEquals(OpenBitSet1, jtNode.getBitSet());
assertEquals(1, jtNode.getChildren().size());
JunctionTreeSeparator sep = jtNode.getChildren().get(0);
assertEquals(OpenBitSet1, sep.getParent().getBitSet());
assertEquals(OpenBitSet2, sep.getChild().getBitSet());
assertEquals(intersect1And2, sep.getBitSet());
jtNode = sep.getChild();
assertEquals(OpenBitSet2, jtNode.getBitSet());
assertEquals(1, jtNode.getChildren().size());
sep = jtNode.getChildren().get(0);
assertEquals(OpenBitSet2, sep.getParent().getBitSet());
assertEquals(OpenBitSet3, sep.getChild().getBitSet());
assertEquals(intersect2And3, sep.getBitSet());
}
use of org.drools.core.util.bitmask.OpenBitSet in project drools by kiegroup.
the class JunctionTreeBuilderTest method testJunctionWithPruning2.
@Test
public void testJunctionWithPruning2() {
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);
List<OpenBitSet> list = new ArrayList<OpenBitSet>();
OpenBitSet OpenBitSet1 = bitSet("00001111");
OpenBitSet OpenBitSet2 = bitSet("00111100");
OpenBitSet OpenBitSet3 = bitSet("11100000");
OpenBitSet OpenBitSet4 = bitSet("00100001");
OpenBitSet intersect1And2 = ((OpenBitSet) OpenBitSet2.clone());
intersect1And2.and(OpenBitSet1);
OpenBitSet intersect2And3 = ((OpenBitSet) OpenBitSet2.clone());
intersect2And3.and(OpenBitSet3);
OpenBitSet intersect1And4 = ((OpenBitSet) OpenBitSet1.clone());
intersect1And4.and(OpenBitSet4);
list.add(OpenBitSet1);
list.add(OpenBitSet2);
list.add(OpenBitSet3);
list.add(OpenBitSet4);
JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder(graph);
JunctionTreeClique jtNode = jtBuilder.junctionTree(list, false).getRoot();
JunctionTreeClique root = jtNode;
assertEquals(OpenBitSet1, root.getBitSet());
assertEquals(2, root.getChildren().size());
JunctionTreeSeparator sep = root.getChildren().get(0);
assertEquals(OpenBitSet1, sep.getParent().getBitSet());
assertEquals(OpenBitSet2, sep.getChild().getBitSet());
assertEquals(1, sep.getChild().getChildren().size());
jtNode = sep.getChild();
assertEquals(OpenBitSet2, jtNode.getBitSet());
assertEquals(1, jtNode.getChildren().size());
sep = jtNode.getChildren().get(0);
assertEquals(OpenBitSet2, sep.getParent().getBitSet());
assertEquals(OpenBitSet3, sep.getChild().getBitSet());
assertEquals(intersect2And3, sep.getBitSet());
assertEquals(0, sep.getChild().getChildren().size());
sep = root.getChildren().get(1);
assertEquals(OpenBitSet1, sep.getParent().getBitSet());
assertEquals(OpenBitSet4, sep.getChild().getBitSet());
assertEquals(intersect1And4, sep.getBitSet());
assertEquals(0, sep.getChild().getChildren().size());
}
use of org.drools.core.util.bitmask.OpenBitSet in project drools by kiegroup.
the class JunctionTreeBuilderTest method testMapNodeToCliques.
@Test
public void testMapNodeToCliques() {
Graph<BayesVariable> graph = new BayesNetwork();
JunctionTreeBuilder tbuilder = new JunctionTreeBuilder(graph);
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);
OpenBitSet clique0 = bitSet("01010101");
OpenBitSet clique1 = bitSet("10010001");
OpenBitSet clique2 = bitSet("10111010");
OpenBitSet[] nodeToCliques = new OpenBitSet[8];
tbuilder.mapVarNodeToCliques(nodeToCliques, 0, clique0);
tbuilder.mapVarNodeToCliques(nodeToCliques, 1, clique1);
tbuilder.mapVarNodeToCliques(nodeToCliques, 2, clique2);
assertEquals(bitSet("011"), nodeToCliques[0]);
assertEquals(bitSet("100"), nodeToCliques[1]);
assertEquals(bitSet("001"), nodeToCliques[2]);
assertEquals(bitSet("100"), nodeToCliques[3]);
assertEquals(bitSet("111"), nodeToCliques[4]);
assertEquals(bitSet("100"), nodeToCliques[5]);
assertEquals(bitSet("001"), nodeToCliques[6]);
assertEquals(bitSet("110"), nodeToCliques[7]);
}
use of org.drools.core.util.bitmask.OpenBitSet in project drools by kiegroup.
the class JunctionTreeBuilderTest method testOpenBitSet.
@Test
public void testOpenBitSet() {
OpenBitSet b1 = bitSet("00000111");
OpenBitSet b2 = bitSet("00000111");
OpenBitSet b3 = bitSet("00000110");
OpenBitSet b4 = bitSet("00001110");
// b1 and b3 are equal
assertEquals(0, OpenBitSet.andNotCount(b1, b2));
// b2 is not a subset of b3
assertEquals(1, OpenBitSet.andNotCount(b2, b3));
// b3 is a subset of b2
assertEquals(0, OpenBitSet.andNotCount(b3, b2));
// b2 is not a subset of b4
assertEquals(1, OpenBitSet.andNotCount(b2, b4));
// b4 is not a subset of b3
assertEquals(1, OpenBitSet.andNotCount(b4, b2));
}
Aggregations