use of fr.lirmm.graphik.graal.homomorphism.bbc.BCC in project graal by graphik-team.
the class BackjumpTest method test1.
/*
* X1 --(p15)--> X5 --(p56)--> X6 \ (p12)--> X2 --(p24)--> X4 \ (p23)--> X3
*
* solutions: X1 X2 X3 X4 X5 X6
* b b c d a a
* b b d d a a
* b d a a a a
*/
@Test
public void test1() throws HomomorphismException, IteratorException, ParseException, AtomSetException {
InMemoryAtomSet data = new DefaultInMemoryGraphStore();
data.addAll(DlgpParser.parseAtomSet("p12(a,a), p12(b,b), p12(b,c), p12(b,d)."));
data.addAll(DlgpParser.parseAtomSet("p23(a,a), p23(b,c), p23(b,d), p23(c,a), p23(d,a)."));
data.addAll(DlgpParser.parseAtomSet("p24(a,a), p24(b,d), p24(d,a)."));
data.addAll(DlgpParser.parseAtomSet("p15(b,a), p15(b,b)."));
data.addAll(DlgpParser.parseAtomSet("p56(a,a)."));
ConjunctiveQuery query = DlgpParser.parseQuery("?(X1,X2,X3,X4,X5,X6) :- p12(X1,X2), p23(X2,X3), p24(X2,X4), p15(X1,X5), p56(X5,X6).");
BCC bcc = new BCC();
Homomorphism<ConjunctiveQuery, AtomSet> h = new BacktrackHomomorphism(bcc.getBCCScheduler(), AllDomainBootstrapper.instance(), NoForwardChecking.instance(), bcc.getBCCBackJumping());
h.setProfiler(new CPUTimeProfiler());
CloseableIterator<Substitution> results = h.execute(query, data);
int i = 0;
while (results.hasNext()) {
results.next();
++i;
}
Assert.assertEquals(3, i);
Assert.assertEquals(49, h.getProfiler().get("#calls"));
}
use of fr.lirmm.graphik.graal.homomorphism.bbc.BCC in project graal by graphik-team.
the class TestUtil method getHomomorphisms.
@SuppressWarnings({ "rawtypes" })
public static Homomorphism[] getHomomorphisms() {
BCC bcc0 = new BCC(true);
BCC bcc1 = new BCC(new GraphBaseBackJumping(), true);
BCC bcc2 = new BCC(new GraphBaseBackJumping(), true);
BCC bcc3 = new BCC(new GraphBaseBackJumping(), true);
BCC bcc4 = new BCC(new GraphBaseBackJumping(), true);
BCC bcc5 = new BCC(new GraphBaseBackJumping(), true);
return new Homomorphism[] { SmartHomomorphism.instance(), RecursiveBacktrackHomomorphism.instance(), // Without Optimization
new BacktrackHomomorphism(DefaultScheduler.instance(), StarBootstrapper.instance(), NoForwardChecking.instance(), NoBackJumping.instance()), // BackJumping
new BacktrackHomomorphism(DefaultScheduler.instance(), StarBootstrapper.instance(), NoForwardChecking.instance(), new GraphBaseBackJumping()), // BCC
new BacktrackHomomorphism(bcc0.getBCCScheduler(), StarBootstrapper.instance(), NoForwardChecking.instance(), bcc0.getBCCBackJumping()), new BacktrackHomomorphism(bcc1.getBCCScheduler(), StarBootstrapper.instance(), NoForwardChecking.instance(), bcc1.getBCCBackJumping()), // Forward Checking
new BacktrackHomomorphism(DefaultScheduler.instance(), StarBootstrapper.instance(), new NFC0(), new GraphBaseBackJumping()), new BacktrackHomomorphism(DefaultScheduler.instance(), StarBootstrapper.instance(), new NFC2(), new GraphBaseBackJumping()), new BacktrackHomomorphism(DefaultScheduler.instance(), StarBootstrapper.instance(), new NFC2(true), new GraphBaseBackJumping()), new BacktrackHomomorphism(DefaultScheduler.instance(), StarBootstrapper.instance(), new SimpleFC(), new GraphBaseBackJumping()), new BacktrackHomomorphism(DefaultScheduler.instance(), StarBootstrapper.instance(), new NFC2WithLimit(8), new GraphBaseBackJumping()), // Bootstrapper
new BacktrackHomomorphism(bcc2.getBCCScheduler(), StarBootstrapper.instance(), new NFC2(), bcc2.getBCCBackJumping()), new BacktrackHomomorphism(bcc3.getBCCScheduler(), StatBootstrapper.instance(), new NFC2(), bcc3.getBCCBackJumping()), new BacktrackHomomorphism(bcc4.getBCCScheduler(), DefaultBootstrapper.instance(), new NFC2(), bcc4.getBCCBackJumping()), new BacktrackHomomorphism(bcc5.getBCCScheduler(), AllDomainBootstrapper.instance(), new NFC2(), bcc5.getBCCBackJumping()) };
}
use of fr.lirmm.graphik.graal.homomorphism.bbc.BCC in project graal by graphik-team.
the class HomomorphismTest method test5.
@Test
public void test5() throws HomomorphismException, IteratorException, AtomSetException {
InMemoryAtomSet data = new DefaultInMemoryGraphStore();
data.addAll(DlgpParser.parseAtomSet("p(a,b), r(b,b), r(c,c), q(c), q(b)."));
Variable x = DefaultTermFactory.instance().createVariable("X");
InMemoryAtomSet positivePart = new LinkedListAtomSet();
positivePart.addAll(DlgpParser.parseAtomSet("p(a,X),r(W,Y),q(Y)."));
positivePart.iterator().next().setTerm(1, x);
InMemoryAtomSet negatedPart = new LinkedListAtomSet();
negatedPart.addAll(DlgpParser.parseAtomSet("q(X)."));
negatedPart.iterator().next().setTerm(0, x);
DefaultConjunctiveQueryWithNegatedParts query = new DefaultConjunctiveQueryWithNegatedParts(positivePart, Collections.singletonList(negatedPart), Collections.<Term>emptyList());
BCC bcc = new BCC(new GraphBaseBackJumping(), true);
BacktrackHomomorphismWithNegatedParts h = new BacktrackHomomorphismWithNegatedParts(bcc.getBCCScheduler(), StarBootstrapper.instance(), new NFC2(), bcc.getBCCBackJumping());
CloseableIterator<Substitution> res = h.execute(query, data);
Assert.assertFalse(res.hasNext());
res.close();
}
Aggregations