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);
}
use of com.google.api.expr.v1alpha1.Expr in project batfish by batfish.
the class PropertyAdder method allEqual.
static BoolExpr allEqual(Context ctx, List<Expr> exprs) {
BoolExpr acc = ctx.mkBool(true);
if (exprs.size() > 1) {
for (int i = 0; i < exprs.size() - 1; i++) {
Expr x = exprs.get(i);
Expr y = exprs.get(i + 1);
acc = ctx.mkAnd(acc, ctx.mkEq(x, y));
}
}
return acc;
}
use of com.google.api.expr.v1alpha1.Expr in project batfish by batfish.
the class TransferSSA method joinPoint.
/*
* The [phi] function from SSA that merges variables that may differ across
* different branches of an mkIf statement.
*/
private Pair<Expr, Expr> joinPoint(TransferParam<SymbolicRoute> p, TransferResult<BoolExpr, BoolExpr> r, BoolExpr guard, Pair<String, Pair<Expr, Expr>> values) {
String variableName = values.getFirst();
Expr trueBranch = values.getSecond().getFirst();
Expr falseBranch = values.getSecond().getSecond();
if (variableName.equals("RETURN") || variableName.equals("FALLTHROUGH")) {
Expr t = (trueBranch == null ? _enc.mkFalse() : // can use False because the value has not been assigned
trueBranch);
Expr f = (falseBranch == null ? _enc.mkFalse() : falseBranch);
Expr tass = (trueBranch == null ? r.getReturnAssignedValue() : _enc.mkTrue());
Expr fass = (falseBranch == null ? r.getReturnAssignedValue() : _enc.mkTrue());
BoolExpr newAss = _enc.mkIf(guard, (BoolExpr) tass, (BoolExpr) fass);
BoolExpr retAss = createBoolVariableWith(p, "ASSIGNED", newAss);
BoolExpr variable = (variableName.equals("RETURN") ? r.getReturnValue() : r.getFallthroughValue());
BoolExpr newValue = _enc.mkIf(r.getReturnAssignedValue(), variable, _enc.mkIf(guard, (BoolExpr) t, (BoolExpr) f));
BoolExpr ret = createBoolVariableWith(p, variableName, newValue);
return new Pair<>(ret, retAss);
}
if (variableName.equals("PREFIX-LEN")) {
Expr t = (trueBranch == null ? p.getData().getPrefixLength() : trueBranch);
Expr f = (falseBranch == null ? p.getData().getPrefixLength() : falseBranch);
ArithExpr newValue = _enc.mkIf(guard, (ArithExpr) t, (ArithExpr) f);
newValue = _enc.mkIf(r.getReturnAssignedValue(), p.getData().getPrefixLength(), newValue);
ArithExpr ret = createArithVariableWith(p, "PREFIX-LEN", newValue);
p.getData().setPrefixLength(ret);
return new Pair<>(ret, null);
}
if (variableName.equals("ADMIN-DIST")) {
Expr t = (trueBranch == null ? p.getData().getAdminDist() : trueBranch);
Expr f = (falseBranch == null ? p.getData().getAdminDist() : falseBranch);
ArithExpr newValue = _enc.mkIf(guard, (ArithExpr) t, (ArithExpr) f);
newValue = _enc.mkIf(r.getReturnAssignedValue(), p.getData().getAdminDist(), newValue);
ArithExpr ret = createArithVariableWith(p, "ADMIN-DIST", newValue);
p.getData().setAdminDist(ret);
return new Pair<>(ret, null);
}
if (variableName.equals("LOCAL-PREF")) {
Expr t = (trueBranch == null ? p.getData().getLocalPref() : trueBranch);
Expr f = (falseBranch == null ? p.getData().getLocalPref() : falseBranch);
ArithExpr newValue = _enc.mkIf(guard, (ArithExpr) t, (ArithExpr) f);
newValue = _enc.mkIf(r.getReturnAssignedValue(), p.getData().getLocalPref(), newValue);
ArithExpr ret = createArithVariableWith(p, "LOCAL-PREF", newValue);
p.getData().setLocalPref(ret);
return new Pair<>(ret, null);
}
if (variableName.equals("METRIC")) {
Expr t = (trueBranch == null ? p.getData().getMetric() : trueBranch);
Expr f = (falseBranch == null ? p.getData().getMetric() : falseBranch);
ArithExpr newValue = _enc.mkIf(guard, (ArithExpr) t, (ArithExpr) f);
newValue = _enc.mkIf(r.getReturnAssignedValue(), p.getData().getMetric(), newValue);
ArithExpr ret = createArithVariableWith(p, "METRIC", newValue);
p.getData().setMetric(ret);
return new Pair<>(ret, null);
}
if (variableName.equals("OSPF-TYPE")) {
Expr t = (trueBranch == null ? p.getData().getOspfType().getBitVec() : trueBranch);
Expr f = (falseBranch == null ? p.getData().getOspfType().getBitVec() : falseBranch);
BitVecExpr newValue = _enc.mkIf(guard, (BitVecExpr) t, (BitVecExpr) f);
newValue = _enc.mkIf(r.getReturnAssignedValue(), p.getData().getOspfType().getBitVec(), newValue);
BitVecExpr ret = createBitVecVariableWith(p, "OSPF-TYPE", 2, newValue);
p.getData().getOspfType().setBitVec(ret);
return new Pair<>(ret, null);
}
for (Map.Entry<CommunityVar, BoolExpr> entry : p.getData().getCommunities().entrySet()) {
CommunityVar cvar = entry.getKey();
if (variableName.equals(cvar.getValue())) {
Expr t = (trueBranch == null ? p.getData().getCommunities().get(cvar) : trueBranch);
Expr f = (falseBranch == null ? p.getData().getCommunities().get(cvar) : falseBranch);
BoolExpr newValue = _enc.mkIf(guard, (BoolExpr) t, (BoolExpr) f);
newValue = _enc.mkIf(r.getReturnAssignedValue(), p.getData().getCommunities().get(cvar), newValue);
BoolExpr ret = createBoolVariableWith(p, cvar.getValue(), newValue);
p.getData().getCommunities().put(cvar, ret);
return new Pair<>(ret, null);
}
}
throw new BatfishException("[joinPoint]: unhandled case for " + variableName);
}
use of com.google.api.expr.v1alpha1.Expr in project batfish by batfish.
the class Z3ContextJob method getSolverInput.
protected BoolExpr getSolverInput(Expr answer, NodProgram program, boolean negate) {
BoolExpr solverInput;
if (answer.getArgs().length > 0) {
Map<String, BitVecExpr> variablesAsConsts = program.getNodContext().getVariablesAsConsts();
List<BitVecExpr> reversedVars = Lists.reverse(program.getNodContext().getVariableNames().stream().filter(name -> !TransformationHeaderField.transformationHeaderFieldNames.contains(name)).map(variablesAsConsts::get).collect(Collectors.toList()));
Expr substitutedAnswer = answer.substituteVars(reversedVars.toArray(new Expr[] {}));
solverInput = (BoolExpr) substitutedAnswer;
} else {
solverInput = (BoolExpr) answer;
}
if (negate) {
solverInput = program.getNodContext().getContext().mkNot(solverInput);
}
return solverInput;
}
use of com.google.api.expr.v1alpha1.Expr in project bmoth by hhu-stups.
the class StateTest method testStateEquals3.
@Test
public void testStateEquals3() throws Exception {
HashMap<String, Expr> map = new HashMap<>();
map.put("x", z3Context.mkInt(11));
State state = new State(map);
assertEquals(state, state);
assertNotEquals(state, new Object());
}
Aggregations