use of com.microsoft.z3.Context in project batfish by batfish.
the class BoolExprTransformer method visitBasicRuleStatement.
@Override
public BoolExpr visitBasicRuleStatement(BasicRuleStatement basicRuleStatement) {
Context ctx = _nodContext.getContext();
ImmutableList.Builder<BoolExpr> preconditions = ImmutableList.<BoolExpr>builder().add(toBoolExpr(basicRuleStatement.getPreconditionStateIndependentConstraints(), _input, _nodContext));
basicRuleStatement.getPreconditionStates().stream().map(preconditionState -> toBoolExpr(preconditionState, _input, _nodContext)).forEach(preconditions::add);
return ctx.mkImplies(ctx.mkAnd(preconditions.build().stream().toArray(BoolExpr[]::new)), toBoolExpr(basicRuleStatement.getPostconditionState(), _input, _nodContext));
}
use of com.microsoft.z3.Context in project bmoth by hhu-stups.
the class Issue59Test method testIssue59JustInvariant.
@Test
public void testIssue59JustInvariant() {
Context ctx = new Context();
Solver s = ctx.mkSolver();
String formula = "x**2 = x*x & #x.({x} \\/ {1,2} = {1,2})";
BoolExpr combinedConstraint = translatePredicate(formula, ctx);
s.add(combinedConstraint);
Status check = s.check();
assertEquals(Status.SATISFIABLE, check);
}
use of com.microsoft.z3.Context in project bmoth by hhu-stups.
the class Issue59Test method testIssue59JustInvariant2.
@Test
public void testIssue59JustInvariant2() {
Context ctx = new Context();
Solver s = ctx.mkSolver();
String formula = "x**2 = x*x";
BoolExpr combinedConstraint = translatePredicate(formula, ctx);
s.add(combinedConstraint);
Status check = s.check();
assertEquals(Status.SATISFIABLE, check);
}
use of com.microsoft.z3.Context in project bmoth by hhu-stups.
the class Z3SolverFactory method getZ3Solver.
static Solver getZ3Solver(Context ctx) {
Solver solver = ctx.mkSolver();
Params params = ctx.mkParams();
params.add("timeout", BMothPreferences.getIntPreference(BMothPreferences.IntPreference.Z3_TIMEOUT));
solver.setParameters(params);
return solver;
}
use of com.microsoft.z3.Context in project bmoth by hhu-stups.
the class Z3TypeInference method getZ3Sort.
public Sort getZ3Sort(Z3Type t, Context z3Context) {
if (t instanceof Z3BasicType) {
switch(((Z3BasicType) t).kind) {
case INTEGER:
return z3Context.getIntSort();
case BOOL:
return z3Context.getBoolSort();
default:
break;
}
} else if (t instanceof Z3SetType) {
Sort subSort = getZ3Sort(((Z3SetType) t).subtype, z3Context);
return z3Context.mkSetSort(subSort);
} else if (t instanceof Z3CoupleType) {
Z3CoupleType couple = (Z3CoupleType) t;
Sort left = getZ3Sort(couple.left, z3Context);
Sort right = getZ3Sort(couple.right, z3Context);
Sort[] subSorts = new Sort[2];
subSorts[0] = left;
subSorts[1] = right;
return z3Context.mkTupleSort(z3Context.mkSymbol("couple"), new Symbol[] { z3Context.mkSymbol("left"), z3Context.mkSymbol("right") }, subSorts);
} else if (t instanceof Z3SequenceType) {
Sort subSort = getZ3Sort(((Z3SequenceType) t).subtype, z3Context);
Sort intType = z3Context.getIntSort();
Sort[] subSorts = new Sort[2];
subSorts[0] = z3Context.mkArraySort(intType, subSort);
subSorts[1] = intType;
return z3Context.mkTupleSort(z3Context.mkSymbol("sequence"), new Symbol[] { z3Context.mkSymbol("array"), z3Context.mkSymbol("size") }, subSorts);
} else if (t instanceof Z3DeferredType) {
return z3Context.mkUninterpretedSort(((Z3DeferredType) t).name);
} else if (t instanceof Z3EnumeratedSetType) {
List<String> elements = ((Z3EnumeratedSetType) t).elements;
String[] array = elements.toArray(new String[elements.size()]);
return z3Context.mkEnumSort(((Z3EnumeratedSetType) t).name, array);
}
throw new AssertionError("Missing Type Conversion: " + t.getClass());
}
Aggregations