Search in sources :

Example 46 with Expr

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));
}
Also used : Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) BoolExpr(com.microsoft.z3.BoolExpr) Expr(com.microsoft.z3.Expr) Test(org.junit.Test)

Example 47 with Expr

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));
}
Also used : Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) BoolExpr(com.microsoft.z3.BoolExpr) Expr(com.microsoft.z3.Expr) Test(org.junit.Test)

Example 48 with Expr

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());
}
Also used : Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) BoolExpr(com.microsoft.z3.BoolExpr) Expr(com.microsoft.z3.Expr) Test(org.junit.Test)

Example 49 with Expr

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));
}
Also used : Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) BoolExpr(com.microsoft.z3.BoolExpr) Expr(com.microsoft.z3.Expr) Test(org.junit.Test)

Example 50 with Expr

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);
}
Also used : CommunityVar(org.batfish.symbolic.CommunityVar) BoolExpr(com.microsoft.z3.BoolExpr) BoolExpr(com.microsoft.z3.BoolExpr) ArithExpr(com.microsoft.z3.ArithExpr) BitVecExpr(com.microsoft.z3.BitVecExpr) Expr(com.microsoft.z3.Expr) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Aggregations

Expr (edu.stanford.CVC4.Expr)57 Test (org.junit.Test)55 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)49 SExpr (edu.stanford.CVC4.SExpr)42 Expr (com.microsoft.z3.Expr)32 Result (edu.stanford.CVC4.Result)32 Rational (edu.stanford.CVC4.Rational)28 Expr (com.google.api.expr.v1alpha1.Expr)23 BoolExpr (com.microsoft.z3.BoolExpr)22 ArrayType (edu.stanford.CVC4.ArrayType)12 BitVectorType (edu.stanford.CVC4.BitVectorType)12 Status (com.microsoft.z3.Status)11 Type (edu.stanford.CVC4.Type)11 HashMap (java.util.HashMap)11 Test (org.junit.jupiter.api.Test)11 ParsedExpr (com.google.api.expr.v1alpha1.ParsedExpr)10 CheckedExpr (com.google.api.expr.v1alpha1.CheckedExpr)9 ArithExpr (com.microsoft.z3.ArithExpr)8 BitVecExpr (com.microsoft.z3.BitVecExpr)8 Val (org.projectnessie.cel.common.types.ref.Val)7