use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class AbstractNFC method getCandidatsIterator.
@Override
public CloseableIterator<Term> getCandidatsIterator(AtomSet g, Var var, Substitution initialSubstitution, Map<Variable, Integer> map, Var[] varData, RulesCompilation rc) throws BacktrackException {
HomomorphismIteratorChecker tmp;
if (this.data[var.shared.level].last.init) {
tmp = new HomomorphismIteratorChecker(var, new CloseableIteratorAdapter<Term>(this.data[var.shared.level].last.candidats.iterator()), this.data[var.shared.level].toCheckAfterAssignment, g, initialSubstitution, map, varData, rc);
} else {
try {
tmp = new HomomorphismIteratorChecker(var, g.termsIterator(), var.shared.preAtoms, g, initialSubstitution, map, varData, rc);
} catch (AtomSetException e) {
throw new BacktrackException(e);
}
}
tmp.setProfiler(this.getProfiler());
return tmp;
}
use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class NFC2WithLimit method getCandidatsIterator.
@Override
public CloseableIterator<Term> getCandidatsIterator(AtomSet g, Var var, Substitution initialSubstitution, Map<Variable, Integer> map, Var[] varData, RulesCompilation rc) throws BacktrackException {
HomomorphismIteratorChecker tmp;
if (this.data[var.shared.level].last.init) {
this.dataWithLimit[var.shared.level].atomsToCheck.addAll(this.data[var.shared.level].toCheckAfterAssignment);
tmp = new HomomorphismIteratorChecker(var, new CloseableIteratorAdapter<Term>(this.data[var.shared.level].last.candidats.iterator()), this.dataWithLimit[var.shared.level].atomsToCheck, g, initialSubstitution, map, varData, rc);
} else {
try {
tmp = new HomomorphismIteratorChecker(var, g.termsIterator(), var.shared.preAtoms, g, initialSubstitution, map, varData, rc);
} catch (AtomSetException e) {
throw new BacktrackException(e);
}
}
tmp.setProfiler(this.getProfiler());
return tmp;
}
use of fr.lirmm.graphik.graal.api.core.AtomSetException 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.graal.api.core.AtomSetException in project graal by graphik-team.
the class SimpleFC method getCandidatsIterator.
@Override
public CloseableIterator<Term> getCandidatsIterator(AtomSet g, Var var, Substitution initialSubstitution, Map<Variable, Integer> map, Var[] varData, RulesCompilation rc) throws BacktrackException {
HomomorphismIteratorChecker tmp;
try {
tmp = new HomomorphismIteratorChecker(var, g.termsIterator(), var.shared.preAtoms, g, initialSubstitution, map, varData, rc);
} catch (AtomSetException e) {
throw new BacktrackException(e);
}
tmp.setProfiler(this.getProfiler());
return tmp;
}
use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class NFC2 method checkForward.
// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public boolean checkForward(Var v, AtomSet g, Substitution initialSubstitution, Map<Variable, Integer> map, Var[] varData, RulesCompilation rc) throws BacktrackException {
// clear all computed candidats for post variables
for (VarSharedData z : v.shared.postVars) {
this.clear(v.shared, z);
}
Var varToAssign = null;
for (Atom atom : v.shared.postAtoms) {
boolean runCheck = true;
if (checkMode) {
int i = 0;
for (Variable t : atom.getVariables()) {
Integer idx = map.get(t);
if (idx != null) {
Var z = varData[idx];
if (z.shared.level > v.shared.level) {
++i;
varToAssign = z;
if (i > 1 || !this.data[z.shared.level].candidats[v.shared.level].init) {
runCheck = false;
break;
}
}
}
}
}
if (checkMode && runCheck) {
try {
if (!check(atom, v.shared, varToAssign.shared, g, initialSubstitution, map, varData, rc)) {
return false;
}
} catch (AtomSetException e) {
throw new BacktrackException("An error occurs while checking current candidate");
}
} else {
try {
if (!select(atom, v, g, initialSubstitution, map, varData, rc)) {
return false;
}
} catch (IteratorException e) {
throw new BacktrackException("An error occurs while selecting candidates for next steps ");
} catch (AtomSetException e) {
throw new BacktrackException("An error occurs while selecting candidates for next steps ");
}
}
}
return true;
}
Aggregations