use of com.microsoft.z3.Fixedpoint in project batfish by batfish.
the class NodFirstUnsatJob method call.
@Override
public NodFirstUnsatResult<KeyT, ResultT> call() {
long startTime = System.currentTimeMillis();
try (Context ctx = new Context()) {
ReachabilityProgram baseProgram = _query.synthesizeBaseProgram(_synthesizer);
ReachabilityProgram queryProgram = _query.getReachabilityProgram(_synthesizer.getInput());
NodProgram program = new NodProgram(ctx, baseProgram, queryProgram);
Fixedpoint fix = mkFixedpoint(program, false);
KeyT key = _query.getKey();
for (int queryNum = 0; queryNum < program.getQueries().size(); queryNum++) {
BoolExpr query = program.getQueries().get(queryNum);
Status status = fix.query(query);
switch(status) {
case SATISFIABLE:
break;
case UNKNOWN:
return new NodFirstUnsatResult<>(startTime, _logger.getHistory(), new BatfishException("Query satisfiability unknown"));
case UNSATISFIABLE:
return new NodFirstUnsatResult<>(key, queryNum, _query.getResultsByQueryIndex().get(queryNum), _logger.getHistory(), startTime);
default:
return new NodFirstUnsatResult<>(startTime, _logger.getHistory(), new BatfishException("invalid status"));
}
}
return new NodFirstUnsatResult<>(key, null, null, _logger.getHistory(), startTime);
} catch (Z3Exception e) {
return new NodFirstUnsatResult<>(startTime, _logger.getHistory(), new BatfishException("Error running NoD on concatenated data plane", e));
}
}
use of com.microsoft.z3.Fixedpoint in project batfish by batfish.
the class NodSatJob method call.
@Override
public NodSatResult<KeyT> call() {
Map<KeyT, Boolean> results = new LinkedHashMap<>();
long startTime = System.currentTimeMillis();
try (Context ctx = new Context()) {
ReachabilityProgram baseProgram = _query.synthesizeBaseProgram(_synthesizer);
ReachabilityProgram queryProgram = _query.getReachabilityProgram(_synthesizer.getInput());
NodProgram program = new NodProgram(ctx, baseProgram, queryProgram);
Fixedpoint fix = mkFixedpoint(program, false);
for (int queryNum = 0; queryNum < program.getQueries().size(); queryNum++) {
BoolExpr query = program.getQueries().get(queryNum);
KeyT key = _query.getKeys().get(queryNum);
Status status = fix.query(query);
switch(status) {
case SATISFIABLE:
results.put(key, true);
break;
case UNKNOWN:
return new NodSatResult<>(startTime, _logger.getHistory(), new BatfishException("Query satisfiability unknown"));
case UNSATISFIABLE:
results.put(key, false);
break;
default:
return new NodSatResult<>(startTime, _logger.getHistory(), new BatfishException("invalid status"));
}
}
return new NodSatResult<>(results, _logger.getHistory(), startTime);
} catch (Z3Exception e) {
return new NodSatResult<>(startTime, _logger.getHistory(), new BatfishException("Error running NoD on concatenated data plane", e));
}
}
use of com.microsoft.z3.Fixedpoint in project batfish by batfish.
the class Z3ContextJob method computeSmtConstraintsViaNod.
protected BoolExpr computeSmtConstraintsViaNod(NodProgram program, boolean negate) {
Fixedpoint fix = mkFixedpoint(program, true);
Expr answer = answerFixedPoint(fix, program);
return getSolverInput(answer, program, negate);
}
use of com.microsoft.z3.Fixedpoint in project batfish by batfish.
the class Z3ContextJob method mkFixedpoint.
protected Fixedpoint mkFixedpoint(NodProgram program, boolean printAnswer) {
Context ctx = program.getNodContext().getContext();
Params p = ctx.mkParams();
p.add("timeout", _settings.getZ3timeout());
p.add("fixedpoint.engine", "datalog");
p.add("fixedpoint.datalog.default_relation", "doc");
p.add("fixedpoint.print_answer", printAnswer);
Fixedpoint fix = ctx.mkFixedpoint();
fix.setParameters(p);
for (FuncDecl relationDeclaration : program.getNodContext().getRelationDeclarations().values()) {
fix.registerRelation(relationDeclaration);
}
for (BoolExpr rule : program.getRules()) {
fix.addRule(rule, null);
}
return fix;
}
use of com.microsoft.z3.Fixedpoint in project batfish by batfish.
the class NodJob method computeNodSat.
protected Status computeNodSat(long startTime, Context ctx) {
NodProgram program = getNodProgram(ctx);
Fixedpoint fix = mkFixedpoint(program, true);
for (BoolExpr query : program.getQueries()) {
Status status = fix.query(query);
switch(status) {
case SATISFIABLE:
return status;
case UNKNOWN:
throw new BatfishException("Query satisfiability unknown");
case UNSATISFIABLE:
return status;
default:
throw new BatfishException("invalid status");
}
}
throw new BatfishException("No queries");
}
Aggregations