Search in sources :

Example 1 with Profiler

use of fr.lirmm.graphik.util.profiler.Profiler in project graal by graphik-team.

the class HomomorphismIteratorChecker method check.

// /////////////////////////////////////////////////////////////////////////
// OBJECT OVERRIDE METHODS
// /////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
// /////////////////////////////////////////////////////////////////////////
private boolean check(Term t, Var[] varData) throws AtomSetException {
    this.var.image = t;
    Profiler profiler = this.getProfiler();
    if (profiler != null) {
        profiler.incr("#isHomomorphism", 1);
        profiler.start("isHomomorphismTime");
    }
    boolean res = BacktrackUtils.isHomomorphism(h, g, initialSubstitution, map, varData, rc);
    if (profiler != null) {
        profiler.stop("isHomomorphismTime");
    }
    return res;
}
Also used : Profiler(fr.lirmm.graphik.util.profiler.Profiler)

Example 2 with Profiler

use of fr.lirmm.graphik.util.profiler.Profiler 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 3 with Profiler

use of fr.lirmm.graphik.util.profiler.Profiler 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 4 with Profiler

use of fr.lirmm.graphik.util.profiler.Profiler in project graal by graphik-team.

the class AbstractNFC method check.

protected boolean check(Atom atom, VarSharedData currentVar, VarSharedData varToCompute, AtomSet g, Substitution initialSubstitution, Map<Variable, Integer> map, Var[] varData, RulesCompilation rc) throws AtomSetException {
    Substitution s = BacktrackUtils.createSubstitution(varData);
    s.put(initialSubstitution);
    Atom im = s.createImageOf(atom);
    this.data[varToCompute.level].tmp.clear();
    Set<Term> candidats = this.data[varToCompute.level].candidats[currentVar.level].candidats;
    // FIXME bug with p(X,Y,Z) -> q(X,Y) in the compilation
    for (Pair<Atom, Substitution> rew : rc.getRewritingOf(im)) {
        Atom a = rew.getLeft();
        Iterator<Term> it = candidats.iterator();
        while (it.hasNext()) {
            Term t = it.next();
            Atom fullInstantiatedAtom = Substitutions.createImageOf(a, varToCompute.value, t);
            Profiler profiler = this.getProfiler();
            if (profiler != null) {
                profiler.incr("#check", 1);
                profiler.start("checkTime");
            }
            if (g.contains(fullInstantiatedAtom)) {
                this.data[varToCompute.level].tmp.add(t);
            }
            if (profiler != null) {
                profiler.stop("checkTime");
            }
        }
    }
    candidats.retainAll(this.data[varToCompute.level].tmp);
    this.data[varToCompute.level].tmp.clear();
    if (candidats.isEmpty()) {
        this.bj.addNeighborhoodToBackjumpSet(varToCompute, currentVar);
        return false;
    } else {
        return true;
    }
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) Profiler(fr.lirmm.graphik.util.profiler.Profiler) Term(fr.lirmm.graphik.graal.api.core.Term) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 5 with Profiler

use of fr.lirmm.graphik.util.profiler.Profiler in project graal by graphik-team.

the class AbstractNFC method select.

protected boolean select(Atom atom, Var v, AtomSet g, Substitution initialSubstitution, Map<Variable, Integer> map, Var[] varData, RulesCompilation rc) throws AtomSetException, IteratorException {
    boolean contains = false;
    Set<Var> postVarsFromThisAtom = new HashSet<Var>();
    for (Pair<Atom, Substitution> rew : rc.getRewritingOf(atom)) {
        Atom a = rew.getLeft();
        Var[] postV = this.computePostVariablesPosition(a, v.shared.level, map, varData, postVarsFromThisAtom);
        Atom im = BacktrackUtils.createImageOf(a, initialSubstitution, map, varData);
        Profiler profiler = this.getProfiler();
        if (profiler != null) {
            profiler.incr("#Select", 1);
            profiler.start("SelectTime");
        }
        int nbAns = 0;
        CloseableIterator<? extends Atom> it = g.match(im);
        while (it.hasNext()) {
            ++nbAns;
            int i = -1;
            for (Term t : it.next()) {
                ++i;
                if (postV[i] != null) {
                    this.data[postV[i].shared.level].tmp.add(t);
                }
            }
            contains = true;
        }
        if (profiler != null) {
            profiler.stop("SelectTime");
            profiler.incr("#SelectAns", nbAns);
        }
    }
    boolean isThereAnEmptiedList = false;
    if (contains) {
        // set computed candidats for post variables
        for (Var z : postVarsFromThisAtom) {
            if (!isThereAnEmptiedList) {
                AcceptableCandidats ac = this.data[z.shared.level].candidats[v.shared.level];
                if (ac.init) {
                    ac.candidats.retainAll(this.data[z.shared.level].tmp);
                    isThereAnEmptiedList |= ac.candidats.isEmpty();
                    if (ac.candidats.isEmpty()) {
                        this.bj.addNeighborhoodToBackjumpSet(z.shared, v.shared);
                    }
                } else {
                    ac.candidats.addAll(this.data[z.shared.level].tmp);
                    ac.init = true;
                }
            }
            this.data[z.shared.level].tmp.clear();
        }
    } else {
        Var z = postVarsFromThisAtom.iterator().next();
        this.bj.addNeighborhoodToBackjumpSet(z.shared, v.shared);
    }
    return contains && !isThereAnEmptiedList;
}
Also used : Var(fr.lirmm.graphik.graal.homomorphism.Var) Term(fr.lirmm.graphik.graal.api.core.Term) Atom(fr.lirmm.graphik.graal.api.core.Atom) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) Profiler(fr.lirmm.graphik.util.profiler.Profiler) HashSet(java.util.HashSet)

Aggregations

Profiler (fr.lirmm.graphik.util.profiler.Profiler)10 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)7 Atom (fr.lirmm.graphik.graal.api.core.Atom)4 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)4 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)4 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)4 DefaultInMemoryGraphStore (fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)4 CPUTimeProfiler (fr.lirmm.graphik.util.profiler.CPUTimeProfiler)4 Test (org.junit.Test)4 Term (fr.lirmm.graphik.graal.api.core.Term)3 NFC2 (fr.lirmm.graphik.graal.homomorphism.forward_checking.NFC2)3 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)2 Var (fr.lirmm.graphik.graal.homomorphism.Var)2 HashSet (java.util.HashSet)2 Random (java.util.Random)2 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)1 BacktrackException (fr.lirmm.graphik.graal.homomorphism.BacktrackException)1 SimpleFC (fr.lirmm.graphik.graal.homomorphism.forward_checking.SimpleFC)1 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)1 Pair (org.apache.commons.lang3.tuple.Pair)1