use of fr.lirmm.graphik.util.profiler.Profiler in project graal by graphik-team.
the class NFC2WithLimit method select.
// /////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
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;
int nbAns = 0;
Iterator<Pair<Atom, Substitution>> rewIt = rc.getRewritingOf(atom).iterator();
Set<Var> postVarsFromThisAtom = new HashSet<Var>();
while (rewIt.hasNext() && nbAns < LIMIT) {
Atom a = rewIt.next().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 cpt = 0;
CloseableIterator<? extends Atom> it = g.match(im);
while (it.hasNext() && nbAns < LIMIT) {
++nbAns;
++cpt;
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", cpt);
}
}
boolean isThereAnEmptiedList = false;
if (contains) {
// set computed candidats for post variables
for (Var z : postVarsFromThisAtom) {
if (!isThereAnEmptiedList) {
if (nbAns >= LIMIT) {
this.dataWithLimit[z.shared.level].atomsToCheck.add(atom);
} else {
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;
}
use of fr.lirmm.graphik.util.profiler.Profiler in project graal by graphik-team.
the class ForwardCheckingTest method simpleFCTest1.
@Test
public void simpleFCTest1() throws HomomorphismException, IteratorException, ParseException, AtomSetException {
Profiler profiler = new CPUTimeProfiler();
InMemoryAtomSet data = new DefaultInMemoryGraphStore();
data.addAll(DlgpParser.parseAtomSet("p(a,b), q(b,c)."));
ConjunctiveQuery query = DlgpParser.parseQuery("?(X,Y,Z) :- p(X,Y), q(Y,Z).");
Homomorphism<ConjunctiveQuery, AtomSet> h = new BacktrackHomomorphism(new SimpleFC());
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 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();
}
use of fr.lirmm.graphik.util.profiler.Profiler in project graal by graphik-team.
the class SimpleFC method checkForward.
@Override
public boolean checkForward(Var v, AtomSet g, Substitution initialSubstitution, Map<Variable, Integer> map, Var[] varData, RulesCompilation rc) throws BacktrackException {
Profiler profiler = this.getProfiler();
for (Atom atom : v.shared.postAtoms) {
boolean contains = false;
Atom im = BacktrackUtils.createImageOf(atom, initialSubstitution, map, varData);
if (profiler != null) {
profiler.incr("#selectOne", 1);
profiler.start("selectOneTime");
}
for (Pair<Atom, Substitution> rew : rc.getRewritingOf(im)) {
Atom a = rew.getLeft();
CloseableIterator<Atom> matchIt = null;
try {
matchIt = g.match(a);
if (matchIt.hasNext()) {
contains = true;
break;
}
} catch (IteratorException e) {
throw new BacktrackException(e);
} catch (AtomSetException e) {
throw new BacktrackException(e);
} finally {
if (matchIt != null) {
matchIt.close();
}
}
}
if (profiler != null) {
profiler.stop("selectOneTime");
}
if (!contains) {
return false;
}
}
return true;
}
use of fr.lirmm.graphik.util.profiler.Profiler in project graal by graphik-team.
the class PureHomomorphismImpl method exist.
// /////////////////////////////////////////////////////////////////////////
// METHODS
// /////////////////////////////////////////////////////////////////////////
/**
* @return true if there exist a homomorphism.
* @throws HomomorphismException
*/
public boolean exist() throws HomomorphismException {
// check if the query is empty
if (source == null || !source.iterator().hasNext()) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Empty query");
}
return true;
}
// /////////////////////////////////////////////////////////////////////
// Initialisation
Profiler profiler = this.getProfiler();
profiler.start("preprocessing time");
boolean res = this.initialiseHomomorphism();
profiler.stop("preprocessing time");
if (res) {
profiler.start("backtracking time");
res = this.backtrack();
profiler.stop("backtracking time");
}
return res;
}
Aggregations