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;
}
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"));
}
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"));
}
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;
}
}
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;
}
Aggregations