use of com.google.api.expr.v1alpha1.Expr in project bmoth by hhu-stups.
the class BooleanFormulaEvaluationTest method testFalseFormula.
@Test
public void testFalseFormula() throws Exception {
String formula = "x = FALSE";
// getting the translated z3 representation of the formula
BoolExpr constraint = FormulaToZ3Translator.translatePredicate(formula, z3Context);
z3Solver.add(constraint);
Status check = z3Solver.check();
Expr x = z3Context.mkBoolConst("x");
assertEquals(SATISFIABLE, check);
assertEquals(z3Context.mkFalse(), z3Solver.getModel().eval(x, true));
}
use of com.google.api.expr.v1alpha1.Expr in project bmoth by hhu-stups.
the class BooleanFormulaEvaluationTest method testImplication.
@Test
public void testImplication() throws Exception {
String formula = "1=1 => x";
// getting the translated z3 representation of the formula
BoolExpr constraint = FormulaToZ3Translator.translatePredicate(formula, z3Context);
z3Solver.add(constraint);
Status check = z3Solver.check();
Expr x = z3Context.mkBoolConst("x");
assertEquals(SATISFIABLE, check);
assertEquals(z3Context.mkBool(true), z3Solver.getModel().eval(x, true));
}
use of com.google.api.expr.v1alpha1.Expr in project bmoth by hhu-stups.
the class SetFormulaEvaluationTest method testSetExtensionFormulaWithSetVarModel.
@Test
public void testSetExtensionFormulaWithSetVarModel() {
String formula = "{1,2} = x";
// getting the translated z3 representation of the formula
BoolExpr constraint = FormulaToZ3Translator.translatePredicate(formula, z3Context);
z3Solver.add(constraint);
Status check = z3Solver.check();
Expr x = z3Context.mkArrayConst("x", z3Context.mkIntSort(), z3Context.mkBoolSort());
assertEquals(Status.SATISFIABLE, check);
assertEquals("(store (store ((as const (Array Int Bool)) false) 1 true) 2 true)", z3Solver.getModel().eval(x, true).toString());
}
use of com.google.api.expr.v1alpha1.Expr in project bmoth by hhu-stups.
the class SetFormulaEvaluationTest method testSetExtensionFormulaWithSingleVarModel.
@Test
public void testSetExtensionFormulaWithSingleVarModel() {
String formula = "{1,2} = {2,x}";
// getting the translated z3 representation of the formula
BoolExpr constraint = FormulaToZ3Translator.translatePredicate(formula, z3Context);
z3Solver.add(constraint);
Status check = z3Solver.check();
Expr x = z3Context.mkIntConst("x");
assertEquals(Status.SATISFIABLE, check);
assertEquals(z3Context.mkInt(1), z3Solver.getModel().eval(x, true));
}
use of com.google.api.expr.v1alpha1.Expr in project batfish by batfish.
the class Encoder method environmentBlockingClause.
/*
* Generate a blocking clause for the encoding that says that one
* of the environments that was true before must now be false.
*/
private BoolExpr environmentBlockingClause(Model m) {
BoolExpr acc1 = mkFalse();
BoolExpr acc2 = mkTrue();
// Disable an environment edge if possible
Map<LogicalEdge, SymbolicRoute> map = getMainSlice().getLogicalGraph().getEnvironmentVars();
for (Map.Entry<LogicalEdge, SymbolicRoute> entry : map.entrySet()) {
SymbolicRoute record = entry.getValue();
BoolExpr per = record.getPermitted();
Expr x = m.evaluate(per, false);
if (x.toString().equals("true")) {
acc1 = mkOr(acc1, mkNot(per));
} else {
acc2 = mkAnd(acc2, mkNot(per));
}
}
// Disable a community value if possible
for (Map.Entry<LogicalEdge, SymbolicRoute> entry : map.entrySet()) {
SymbolicRoute record = entry.getValue();
for (Map.Entry<CommunityVar, BoolExpr> centry : record.getCommunities().entrySet()) {
BoolExpr comm = centry.getValue();
Expr x = m.evaluate(comm, false);
if (x.toString().equals("true")) {
acc1 = mkOr(acc1, mkNot(comm));
} else {
acc2 = mkAnd(acc2, mkNot(comm));
}
}
}
return mkAnd(acc1, acc2);
}
Aggregations