Search in sources :

Example 26 with ModelCheckingResult

use of de.bmoth.modelchecker.ModelCheckingResult in project bmoth by hhu-stups.

the class Issue59Test method testIssue59WithAdditionalInvariant.

@Test
public void testIssue59WithAdditionalInvariant() {
    String machine = "MACHINE SimpleMachine\n";
    machine += "VARIABLES x\n";
    machine += "INVARIANT x : INTEGER &\n";
    machine += "\tx**2 = x*x &\n";
    machine += "\t#x.(x:INTEGER & {x} \\/ {1,2} = {1,2})\n";
    machine += "INITIALISATION x := -3\n";
    machine += "OPERATIONS\n";
    machine += "\tIncX = SELECT x < 50 THEN x := x+1 END\n";
    machine += "END";
    ModelCheckingResult result = new ExplicitStateModelChecker(parseMachine(machine)).check();
    assertEquals(true, result.isCorrect());
}
Also used : ExplicitStateModelChecker(de.bmoth.modelchecker.esmc.ExplicitStateModelChecker) ModelCheckingResult(de.bmoth.modelchecker.ModelCheckingResult) Test(org.junit.Test)

Example 27 with ModelCheckingResult

use of de.bmoth.modelchecker.ModelCheckingResult in project bmoth by hhu-stups.

the class Issue66Test method testMachine.

@Test
public void testMachine() throws IOException {
    MachineNode theMachine = parseMachineFromFile(dir + "LargeExponent.mch");
    ModelCheckingResult result = ExplicitStateModelChecker.check(theMachine);
    assertEquals(false, result.isCorrect());
}
Also used : MachineNode(de.bmoth.parser.ast.nodes.MachineNode) ModelCheckingResult(de.bmoth.modelchecker.ModelCheckingResult) Test(org.junit.Test)

Example 28 with ModelCheckingResult

use of de.bmoth.modelchecker.ModelCheckingResult in project bmoth by hhu-stups.

the class ExplicitStateModelChecker method doModelCheck.

@Override
protected ModelCheckingResult doModelCheck() {
    final int maxInitialStates = BMothPreferences.getIntPreference(BMothPreferences.IntPreference.MAX_INITIAL_STATE);
    final int maxTransitions = BMothPreferences.getIntPreference(BMothPreferences.IntPreference.MAX_TRANSITIONS);
    stateSpace = new StateSpace();
    visited = new HashSet<>();
    Queue<State> queue = new LinkedList<>();
    // prepare initial states
    BoolExpr initialValueConstraint = getMachineTranslator().getInitialValueConstraint();
    Set<Model> models = finder.findSolutions(initialValueConstraint, maxInitialStates);
    models.stream().map(this::getStateFromModel).filter(this::isUnknown).forEach(root -> {
        stateSpace.addRootVertex(root);
        queue.add(root);
    });
    final BoolExpr invariant = getMachineTranslator().getInvariantConstraint();
    solver.add(invariant);
    // create joint operations constraint and permanently add to separate
    // solver
    final BoolExpr operationsConstraint = getMachineTranslator().getCombinedOperationConstraint();
    opSolver.add(operationsConstraint);
    while (!isAborted() && !queue.isEmpty()) {
        solver.push();
        State current = queue.poll();
        visited.add(current);
        // apply current state - remains stored in solver for loop iteration
        BoolExpr stateConstraint = current.getStateConstraint(getContext());
        solver.add(stateConstraint);
        // check invariant & state
        Status check = solver.check();
        switch(check) {
            case UNKNOWN:
                return createUnknown(visited.size(), solver.getReasonUnknown());
            case UNSATISFIABLE:
                return createCounterExampleFound(visited.size(), current, stateSpace);
            case SATISFIABLE:
            default:
        }
        // compute successors on separate finder
        models = opFinder.findSolutions(stateConstraint, maxTransitions);
        models.stream().map(this::getStateFromModel).forEach(successor -> {
            if (isUnknown(successor)) {
                stateSpace.addVertex(successor);
                queue.add(successor);
            }
            stateSpace.addEdge(current, successor);
        });
        solver.pop();
    }
    if (isAborted()) {
        return createAborted(visited.size());
    } else {
        ModelCheckingResult resultVerified = createVerified(visited.size(), stateSpace);
        if (buechiAutomaton != null) {
            // do ltl model check
            labelStateSpace();
            List<List<State>> cycles = new TarjanSimpleCycles<>(stateSpace).findSimpleCycles();
            for (List<State> cycle : cycles) {
                // if there is an accepting Buechi state in the cycle, a counterexample is found
                for (State state : cycle) {
                    if (buechiAutomaton.isAcceptingSet(state.getBuechiNodes())) {
                        return createLTLCounterExampleFound(visited.size(), state);
                    }
                }
            }
        }
        return resultVerified;
    }
}
Also used : Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) Model(com.microsoft.z3.Model) ModelCheckingResult(de.bmoth.modelchecker.ModelCheckingResult)

Aggregations

ModelCheckingResult (de.bmoth.modelchecker.ModelCheckingResult)28 Test (org.junit.Test)24 MachineNode (de.bmoth.parser.ast.nodes.MachineNode)22 ExplicitStateModelChecker (de.bmoth.modelchecker.esmc.ExplicitStateModelChecker)2 BoolExpr (com.microsoft.z3.BoolExpr)1 Expr (com.microsoft.z3.Expr)1 Model (com.microsoft.z3.Model)1 Status (com.microsoft.z3.Status)1 ParserException (de.bmoth.parser.ParserException)1 IOException (java.io.IOException)1 Ignore (org.junit.Ignore)1 Benchmark (org.openjdk.jmh.annotations.Benchmark)1