Search in sources :

Example 31 with Status

use of su.litvak.chromecast.api.v2.Status in project bmoth by hhu-stups.

the class BoundedModelChecker method doModelCheck.

@Override
protected ModelCheckingResult doModelCheck() {
    for (int k = 0; k < maxSteps; k++) {
        // get a clean solver
        solver.reset();
        // INIT(V0)
        solver.add(init());
        // CONJUNCTION i from 1 to k T(Vi-1, Vi)
        for (int i = 1; i <= k; i++) {
            solver.add(transition(i - 1, i));
        }
        // not INV(Vk)
        solver.add(getContext().mkNot(invariant(k)));
        // CONJUNCTION i from 1 to k, j from i + 1 to k (Vi != Vj)
        solver.add(distinctVectors(k));
        Status check = solver.check();
        if (check == Status.SATISFIABLE) {
            // counter example found!
            State counterExample = getStateFromModel(solver.getModel(), k);
            return ModelCheckingResult.createCounterExampleFound(k, counterExample, null);
        }
    }
    // no counter example found after maxStep steps
    return ModelCheckingResult.createExceededMaxSteps(maxSteps);
}
Also used : Status(com.microsoft.z3.Status) State(de.bmoth.modelchecker.State)

Example 32 with Status

use of su.litvak.chromecast.api.v2.Status in project bmoth by hhu-stups.

the class ExplicitStateModelChecker method labelStateSpace.

private void labelStateSpace() {
    Queue<State> statesToUpdate = new ArrayDeque<>();
    statesToUpdate.addAll(stateSpace.vertexSet());
    while (!statesToUpdate.isEmpty()) {
        State current = statesToUpdate.poll();
        final Set<BuechiAutomatonNode> buechiNodes = new HashSet<>();
        final Set<BuechiAutomatonNode> candidates = new HashSet<>();
        if (stateSpace.rootVertexSet().contains(current)) {
            candidates.addAll(buechiAutomaton.getInitialStates());
        } else {
            Set<DefaultEdge> incomingEdges = stateSpace.incomingEdgesOf(current);
            for (DefaultEdge incomingEdge : incomingEdges) {
                State predecessor = stateSpace.getEdgeSource(incomingEdge);
                predecessor.getBuechiNodes().forEach(n -> candidates.addAll(n.getSuccessors()));
            }
        }
        for (BuechiAutomatonNode node : candidates) {
            if (node.getLabels().isEmpty()) {
                buechiNodes.add(node);
            }
            // TODO use all labels?
            for (PredicateNode label : node.getLabels()) {
                labelSolver.reset();
                labelSolver.add(FormulaToZ3Translator.translatePredicate(label, getContext(), getMachineTranslator().getZ3TypeInference()));
                labelSolver.add(current.getStateConstraint(getContext()));
                Status status = labelSolver.check();
                switch(status) {
                    case UNSATISFIABLE:
                        break;
                    case UNKNOWN:
                        throw new UnsupportedOperationException("should not be undefined");
                    case SATISFIABLE:
                        buechiNodes.add(node);
                }
            }
        }
        buechiNodes.stream().filter(n -> !current.getBuechiNodes().contains(n)).forEach(newBuechiNode -> {
            // found a new node, need to update successors again
            current.addBuechiNode(newBuechiNode);
            Set<DefaultEdge> outgoingEdges = stateSpace.outgoingEdgesOf(current);
            for (DefaultEdge outgoingEdge : outgoingEdges) {
                State successor = stateSpace.getEdgeTarget(outgoingEdge);
                if (!statesToUpdate.contains(successor)) {
                    statesToUpdate.add(successor);
                }
            }
        });
    }
}
Also used : Status(com.microsoft.z3.Status) Z3SolverFactory(de.bmoth.backend.z3.Z3SolverFactory) de.bmoth.modelchecker(de.bmoth.modelchecker) java.util(java.util) FormulaToZ3Translator(de.bmoth.backend.z3.FormulaToZ3Translator) DefaultEdge(org.jgrapht.graph.DefaultEdge) Solver(com.microsoft.z3.Solver) MachineNode(de.bmoth.parser.ast.nodes.MachineNode) SolutionFinder(de.bmoth.backend.z3.SolutionFinder) ModelCheckingResult(de.bmoth.modelchecker.ModelCheckingResult) NOT(de.bmoth.parser.ast.nodes.ltl.LTLPrefixOperatorNode.Kind.NOT) TarjanSimpleCycles(org.jgrapht.alg.cycle.TarjanSimpleCycles) Model(com.microsoft.z3.Model) PredicateNode(de.bmoth.parser.ast.nodes.PredicateNode) de.bmoth.parser.ast.nodes.ltl(de.bmoth.parser.ast.nodes.ltl) BoolExpr(com.microsoft.z3.BoolExpr) LTLTransformations(de.bmoth.backend.ltl.LTLTransformations) Status(com.microsoft.z3.Status) TranslationOptions(de.bmoth.backend.TranslationOptions) BMothPreferences(de.bmoth.preferences.BMothPreferences) PredicateNode(de.bmoth.parser.ast.nodes.PredicateNode) DefaultEdge(org.jgrapht.graph.DefaultEdge)

Example 33 with Status

use of su.litvak.chromecast.api.v2.Status in project bmoth by hhu-stups.

the class KInductionModelChecker method doModelCheck.

@Override
protected ModelCheckingResult doModelCheck() {
    for (int k = 0; k < maxSteps; k++) {
        // get a clean baseSolver
        baseSolver.reset();
        // INIT(V0)
        baseSolver.add(init());
        // CONJUNCTION i from 1 to k T(Vi-1, Vi)
        for (int i = 1; i <= k; i++) {
            baseSolver.add(transition(i - 1, i));
        }
        // not INV(Vk)
        baseSolver.add(getContext().mkNot(invariant(k)));
        Status check = baseSolver.check();
        if (check == Status.SATISFIABLE) {
            // counter example found!
            State counterExample = getStateFromModel(baseSolver.getModel(), k);
            return createCounterExampleFound(k, counterExample, null);
        } else {
            stepSolver.reset();
            stepSolver.add();
            // CONJUNCTION i from 1 to k, j from i + 1 to k (Vi != Vj)
            stepSolver.add(distinctVectors(k));
            for (int i = 0; i <= k; i++) {
                stepSolver.add(transition(i - 1, i));
            }
            for (int i = 0; i <= k; i++) {
                stepSolver.add(invariant(i));
            }
            stepSolver.add(getContext().mkNot(invariant(k + 1)));
            Status checkStep = stepSolver.check();
            if (checkStep == Status.UNSATISFIABLE)
                // TODO think about state space root!
                return createVerified(k, null);
        }
    }
    // no counter example found after maxStep steps
    return createExceededMaxSteps(maxSteps);
}
Also used : Status(com.microsoft.z3.Status) State(de.bmoth.modelchecker.State)

Example 34 with Status

use of su.litvak.chromecast.api.v2.Status in project bmoth by hhu-stups.

the class InitialStateExistsChecker method doInitialStateExistsCheck.

static InitialStateExistsCheckingResult doInitialStateExistsCheck(MachineNode machine) {
    Context ctx = new Context();
    Solver solver = Z3SolverFactory.getZ3Solver(ctx);
    MachineToZ3Translator machineTranslator = new MachineToZ3Translator(machine, ctx);
    final BoolExpr invariant = machineTranslator.getInitialValueConstraint();
    solver.add(invariant);
    Status check = solver.check();
    return new InitialStateExistsCheckingResult(check);
}
Also used : Context(com.microsoft.z3.Context) Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) Solver(com.microsoft.z3.Solver) MachineToZ3Translator(de.bmoth.backend.z3.MachineToZ3Translator)

Example 35 with Status

use of su.litvak.chromecast.api.v2.Status in project bmoth by hhu-stups.

the class InvariantSatisfiabilityChecker method doInvariantSatisfiabilityCheck.

static InvariantSatisfiabilityCheckingResult doInvariantSatisfiabilityCheck(MachineNode machine) {
    Context ctx = new Context();
    Solver solver = Z3SolverFactory.getZ3Solver(ctx);
    MachineToZ3Translator machineTranslator = new MachineToZ3Translator(machine, ctx);
    final BoolExpr invariant = machineTranslator.getInvariantConstraint();
    solver.add(invariant);
    Status check = solver.check();
    return new InvariantSatisfiabilityCheckingResult(check);
}
Also used : Context(com.microsoft.z3.Context) Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) Solver(com.microsoft.z3.Solver) MachineToZ3Translator(de.bmoth.backend.z3.MachineToZ3Translator)

Aggregations

Status (com.microsoft.z3.Status)61 BoolExpr (com.microsoft.z3.BoolExpr)55 Test (org.junit.Test)48 Context (com.microsoft.z3.Context)11 Expr (com.microsoft.z3.Expr)10 Solver (com.microsoft.z3.Solver)6 Model (com.microsoft.z3.Model)4 BatfishException (org.batfish.common.BatfishException)4 HeaderSpace (org.batfish.datamodel.HeaderSpace)4 IpWildcard (org.batfish.datamodel.IpWildcard)4 Fixedpoint (com.microsoft.z3.Fixedpoint)3 Z3Exception (com.microsoft.z3.Z3Exception)3 MachineToZ3Translator (de.bmoth.backend.z3.MachineToZ3Translator)2 ModelCheckingResult (de.bmoth.modelchecker.ModelCheckingResult)2 State (de.bmoth.modelchecker.State)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Z3_ast_print_mode (com.microsoft.z3.enumerations.Z3_ast_print_mode)1 LitmusLexer (dartagnan.LitmusLexer)1 LitmusParser (dartagnan.LitmusParser)1