use of org.sosy_lab.java_smt.api.visitors.TraversalProcess in project java-smt by sosy-lab.
the class RecursiveFormulaVisitorImpl method visitFunction.
@Override
public TraversalProcess visitFunction(Formula pF, List<Formula> pArgs, FunctionDeclaration<?> pFunctionDeclaration) {
TraversalProcess result = delegate.visitFunction(pF, pArgs, pFunctionDeclaration);
addToQueueIfNecessary(result, pArgs);
return result;
}
use of org.sosy_lab.java_smt.api.visitors.TraversalProcess in project java-smt by sosy-lab.
the class RecursiveFormulaVisitorImpl method visitQuantifier.
@Override
public TraversalProcess visitQuantifier(BooleanFormula pF, Quantifier pQuantifier, List<Formula> boundVars, BooleanFormula pBody) {
TraversalProcess result = delegate.visitQuantifier(pF, pQuantifier, boundVars, pBody);
addToQueueIfNecessary(result, ImmutableList.of(pBody));
return result;
}
use of org.sosy_lab.java_smt.api.visitors.TraversalProcess in project java-smt by sosy-lab.
the class SolverVisitorTest method testVisitingTrue.
@Test
public void testVisitingTrue() {
// Check that "true" is correctly treated as a constant.
BooleanFormula t = bmgr.makeBoolean(true);
final List<Boolean> containsTrue = new ArrayList<>();
mgr.visitRecursively(t, new DefaultFormulaVisitor<>() {
@Override
protected TraversalProcess visitDefault(Formula f) {
return TraversalProcess.CONTINUE;
}
@Override
public TraversalProcess visitConstant(Formula f, Object o) {
if (f.equals(bmgr.makeBoolean(true))) {
containsTrue.add(true);
}
return TraversalProcess.CONTINUE;
}
});
assertThat(containsTrue).isNotEmpty();
}
use of org.sosy_lab.java_smt.api.visitors.TraversalProcess in project java-smt by sosy-lab.
the class SolverVisitorTest method extractionDeclarations.
@Test
public void extractionDeclarations() {
requireIntegers();
// Create the variables and uf
IntegerFormula a = imgr.makeVariable("a");
IntegerFormula b = imgr.makeVariable("b");
IntegerFormula ab = imgr.add(a, b);
BooleanFormula uf1 = fmgr.declareAndCallUF("testFunc", FormulaType.BooleanType, a, b, ab);
BooleanFormula uf2 = fmgr.declareAndCallUF("testFunc", FormulaType.BooleanType, ab, b, a);
BooleanFormula f = bmgr.and(uf1, uf2);
final Collection<Formula> usedArgs = new LinkedHashSet<>();
final List<FunctionDeclaration<?>> usedDecls = new ArrayList<>();
FormulaVisitor<TraversalProcess> argCollectingVisitor = new DefaultFormulaVisitor<>() {
@Override
public TraversalProcess visitFunction(Formula pF, List<Formula> args, FunctionDeclaration<?> pFunctionDeclaration) {
usedArgs.addAll(args);
usedDecls.add(pFunctionDeclaration);
return visitDefault(pF);
}
@Override
protected TraversalProcess visitDefault(Formula pF) {
return TraversalProcess.CONTINUE;
}
};
mgr.visitRecursively(f, argCollectingVisitor);
// check general stuff about variables, copied from above
assertThat(usedArgs).hasSize(5);
assertThat(usedArgs).containsExactly(uf1, uf2, a, b, ab);
Map<String, Formula> vars = mgr.extractVariables(f);
assertThat(vars).hasSize(2);
assertThat(vars.keySet()).containsExactly("a", "b");
Map<String, Formula> varsUfs = mgr.extractVariablesAndUFs(f);
assertThat(varsUfs).hasSize(3);
assertThat(varsUfs.keySet()).containsExactly("a", "b", "testFunc");
// check correct traversal order of the functions
assertThat(usedDecls).hasSize(4);
assertThat(usedDecls.get(0).getKind()).isEqualTo(FunctionDeclarationKind.AND);
assertThat(usedDecls.get(1).getName()).isEqualTo("testFunc");
assertThat(usedDecls.get(2).getKind()).isEqualTo(FunctionDeclarationKind.ADD);
assertThat(usedDecls.get(3).getName()).isEqualTo("testFunc");
// check UF-equality. This check went wrong in CVC4 and was fixed.
assertThat(usedDecls.get(1)).isEqualTo(usedDecls.get(3));
}
use of org.sosy_lab.java_smt.api.visitors.TraversalProcess in project java-smt by sosy-lab.
the class UfElimination method isQuantified.
private boolean isQuantified(Formula f) {
AtomicBoolean result = new AtomicBoolean();
fmgr.visitRecursively(f, new DefaultFormulaVisitor<>() {
@Override
protected TraversalProcess visitDefault(Formula pF) {
return TraversalProcess.CONTINUE;
}
@Override
public TraversalProcess visitQuantifier(BooleanFormula pF, Quantifier pQ, List<Formula> pBoundVariables, BooleanFormula pBody) {
result.set(true);
return TraversalProcess.ABORT;
}
});
return result.get();
}
Aggregations