Search in sources :

Example 1 with NFC2

use of fr.lirmm.graphik.graal.homomorphism.forward_checking.NFC2 in project graal by graphik-team.

the class ForwardCheckingTest method NFC2Test.

@Test
public void NFC2Test() throws HomomorphismException, IteratorException, ParseException {
    Profiler profiler = new CPUTimeProfiler();
    Predicate[] predicates = { new Predicate("p2", 2), new Predicate("p3", 3), new Predicate("p4", 4) };
    InMemoryAtomSet data = new DefaultInMemoryGraphStore();
    TestUtil.addNAtoms(data, 13, predicates, 5, new Random(0));
    ConjunctiveQuery query = DlgpParser.parseQuery("?(X5,X6,X7,X8) :- p4(X5,X6,X7,X8), p4(X8,X7,X6,X5), p3(X7,X8,X9), p2(X7,X11).");
    Homomorphism<ConjunctiveQuery, AtomSet> h = new BacktrackHomomorphism(new NFC2());
    h.setProfiler(profiler);
    CloseableIterator<Substitution> results = h.execute(query, data);
    while (results.hasNext()) {
        results.next();
    }
    results.close();
    Assert.assertEquals(1, profiler.get("#calls"));
}
Also used : NFC2(fr.lirmm.graphik.graal.homomorphism.forward_checking.NFC2) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) CPUTimeProfiler(fr.lirmm.graphik.util.profiler.CPUTimeProfiler) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) Profiler(fr.lirmm.graphik.util.profiler.Profiler) CPUTimeProfiler(fr.lirmm.graphik.util.profiler.CPUTimeProfiler) Random(java.util.Random) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Test(org.junit.Test)

Example 2 with NFC2

use of fr.lirmm.graphik.graal.homomorphism.forward_checking.NFC2 in project graal by graphik-team.

the class ForwardCheckingTest method FCTest2.

@Test
public void FCTest2() throws HomomorphismException, IteratorException, ParseException, AtomSetException {
    Profiler profiler = new CPUTimeProfiler();
    InMemoryAtomSet data = new DefaultInMemoryGraphStore();
    data.addAll(DlgpParser.parseAtomSet("p(a,b), p(a,c), q(a,a), q(a,b)."));
    ConjunctiveQuery query = DlgpParser.parseQuery("?(X,Y,Z) :- p(X,Z), q(Y,Z).");
    Homomorphism<ConjunctiveQuery, AtomSet> h = new BacktrackHomomorphism(new NFC2());
    h.setProfiler(profiler);
    CloseableIterator<Substitution> results = h.execute(query, data);
    while (results.hasNext()) {
        results.next();
    }
    results.close();
    Assert.assertEquals(7, profiler.get("#calls"));
}
Also used : NFC2(fr.lirmm.graphik.graal.homomorphism.forward_checking.NFC2) Profiler(fr.lirmm.graphik.util.profiler.Profiler) CPUTimeProfiler(fr.lirmm.graphik.util.profiler.CPUTimeProfiler) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) CPUTimeProfiler(fr.lirmm.graphik.util.profiler.CPUTimeProfiler) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Test(org.junit.Test)

Example 3 with NFC2

use of fr.lirmm.graphik.graal.homomorphism.forward_checking.NFC2 in project graal by graphik-team.

the class ForwardCheckingTest method test1.

@Test
public void test1() throws HomomorphismException, IteratorException, ParseException, AtomSetException {
    InMemoryAtomSet data = new DefaultInMemoryGraphStore();
    data.addAll(DlgpParser.parseAtomSet("p(a,b)."));
    ConjunctiveQuery query = DlgpParser.parseQuery("?(X,Y,Z) :- p(X,Y), p(X,Z).");
    Homomorphism<ConjunctiveQuery, AtomSet> h = new BacktrackHomomorphism(new NFC2());
    CloseableIterator<Substitution> results = h.execute(query, data);
    while (results.hasNext()) {
        results.next();
    }
    results.close();
}
Also used : NFC2(fr.lirmm.graphik.graal.homomorphism.forward_checking.NFC2) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Test(org.junit.Test)

Example 4 with NFC2

use of fr.lirmm.graphik.graal.homomorphism.forward_checking.NFC2 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()) };
}
Also used : NFC0(fr.lirmm.graphik.graal.homomorphism.forward_checking.NFC0) BCC(fr.lirmm.graphik.graal.homomorphism.bbc.BCC) NFC2(fr.lirmm.graphik.graal.homomorphism.forward_checking.NFC2) SimpleFC(fr.lirmm.graphik.graal.homomorphism.forward_checking.SimpleFC) NFC2WithLimit(fr.lirmm.graphik.graal.homomorphism.forward_checking.NFC2WithLimit) RecursiveBacktrackHomomorphism(fr.lirmm.graphik.graal.homomorphism.RecursiveBacktrackHomomorphism) BacktrackHomomorphism(fr.lirmm.graphik.graal.homomorphism.BacktrackHomomorphism) SmartHomomorphism(fr.lirmm.graphik.graal.homomorphism.SmartHomomorphism) RecursiveBacktrackHomomorphism(fr.lirmm.graphik.graal.homomorphism.RecursiveBacktrackHomomorphism) Homomorphism(fr.lirmm.graphik.graal.api.homomorphism.Homomorphism) BacktrackHomomorphism(fr.lirmm.graphik.graal.homomorphism.BacktrackHomomorphism) GraphBaseBackJumping(fr.lirmm.graphik.graal.homomorphism.backjumping.GraphBaseBackJumping)

Example 5 with NFC2

use of fr.lirmm.graphik.graal.homomorphism.forward_checking.NFC2 in project graal by graphik-team.

the class ForwardCheckingTest method NFC2Test2.

@Test
public void NFC2Test2() throws HomomorphismException, IteratorException, ParseException {
    Profiler profiler = new CPUTimeProfiler();
    Predicate[] predicates = { new Predicate("p", 2), new Predicate("q", 2), new Predicate("r", 2) };
    InMemoryAtomSet data = new DefaultInMemoryGraphStore();
    TestUtil.addNAtoms(data, 32, predicates, 5, new Random(0));
    ConjunctiveQuery query = DlgpParser.parseQuery("?(X,Y,Z) :- p(X,Y), q(X,Z), r(Y,Z).");
    Homomorphism<ConjunctiveQuery, AtomSet> h = new BacktrackHomomorphism(new NFC2());
    h.setProfiler(profiler);
    CloseableIterator<Substitution> results = h.execute(query, data);
    while (results.hasNext()) {
        results.next();
    }
    results.close();
}
Also used : NFC2(fr.lirmm.graphik.graal.homomorphism.forward_checking.NFC2) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) CPUTimeProfiler(fr.lirmm.graphik.util.profiler.CPUTimeProfiler) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) Profiler(fr.lirmm.graphik.util.profiler.Profiler) CPUTimeProfiler(fr.lirmm.graphik.util.profiler.CPUTimeProfiler) Random(java.util.Random) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Test(org.junit.Test)

Aggregations

NFC2 (fr.lirmm.graphik.graal.homomorphism.forward_checking.NFC2)6 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)5 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)5 DefaultInMemoryGraphStore (fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)5 Test (org.junit.Test)5 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)4 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)4 CPUTimeProfiler (fr.lirmm.graphik.util.profiler.CPUTimeProfiler)3 Profiler (fr.lirmm.graphik.util.profiler.Profiler)3 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)2 GraphBaseBackJumping (fr.lirmm.graphik.graal.homomorphism.backjumping.GraphBaseBackJumping)2 BCC (fr.lirmm.graphik.graal.homomorphism.bbc.BCC)2 Random (java.util.Random)2 Variable (fr.lirmm.graphik.graal.api.core.Variable)1 Homomorphism (fr.lirmm.graphik.graal.api.homomorphism.Homomorphism)1 DefaultConjunctiveQueryWithNegatedParts (fr.lirmm.graphik.graal.core.DefaultConjunctiveQueryWithNegatedParts)1 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)1 BacktrackHomomorphism (fr.lirmm.graphik.graal.homomorphism.BacktrackHomomorphism)1 RecursiveBacktrackHomomorphism (fr.lirmm.graphik.graal.homomorphism.RecursiveBacktrackHomomorphism)1 SmartHomomorphism (fr.lirmm.graphik.graal.homomorphism.SmartHomomorphism)1