use of com.microsoft.z3.Sort in project bmoth by hhu-stups.
the class MachineToZ3Translator method getDistinctVars.
public BoolExpr getDistinctVars(int from, int to) {
if (tuple == null) {
Expr[] variables = getVariables().stream().map(this::getVariable).toArray(Expr[]::new);
Symbol[] symbols = Arrays.stream(variables).map(var -> var.getFuncDecl().getName()).toArray(Symbol[]::new);
Sort[] sorts = Arrays.stream(variables).map(Expr::getSort).toArray(Sort[]::new);
tuple = z3Context.mkTupleSort(z3Context.mkSymbol("tuple"), symbols, sorts);
}
Expr[] distinct = new Expr[to - from + 1];
for (int v = from, i = 0; v <= to; v++, i++) {
int finalV = v;
Expr[] vector = getVariables().stream().map(var -> getPrimedVariable(var, new TranslationOptions(finalV))).toArray(Expr[]::new);
distinct[i] = tuple.mkDecl().apply(vector);
}
return z3Context.mkDistinct(distinct);
}
use of com.microsoft.z3.Sort 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());
}
use of com.microsoft.z3.Sort in project batfish by batfish.
the class Encoder method initFailedLinkVariables.
/*
* Initialize symbolic variables to represent link failures.
*/
private void initFailedLinkVariables() {
for (List<GraphEdge> edges : _graph.getEdgeMap().values()) {
for (GraphEdge ge : edges) {
if (ge.getPeer() == null) {
Interface i = ge.getStart();
String name = getId() + "_FAILED-EDGE_" + ge.getRouter() + "_" + i.getName();
ArithExpr var = getCtx().mkIntConst(name);
_symbolicFailures.getFailedEdgeLinks().put(ge, var);
_allVariables.put(var.toString(), var);
}
}
}
for (Entry<String, Set<String>> entry : _graph.getNeighbors().entrySet()) {
String router = entry.getKey();
Set<String> peers = entry.getValue();
for (String peer : peers) {
// sort names for unique
String pair = (router.compareTo(peer) < 0 ? router + "_" + peer : peer + "_" + router);
String name = getId() + "_FAILED-EDGE_" + pair;
ArithExpr var = _ctx.mkIntConst(name);
_symbolicFailures.getFailedInternalLinks().put(router, peer, var);
_allVariables.put(var.toString(), var);
}
}
}
Aggregations