Search in sources :

Example 61 with Model

use of org.eclipse.xtext.parsetree.reconstr.bug299395.Model 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

Test (org.junit.Test)47 Model (org.eclipse.xtext.valueconverter.bug250313.Model)30 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)16 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)11 Model (org.eclipse.xtext.parsetree.reconstr.bug299395.Model)9 SubModel (org.eclipse.xtext.parsetree.reconstr.bug299395.SubModel)9 BoolExpr (com.microsoft.z3.BoolExpr)7 Model (com.microsoft.z3.Model)7 EPackage (org.eclipse.emf.ecore.EPackage)6 Action (org.eclipse.xtext.Action)6 Parameter (org.eclipse.xtext.Parameter)6 ParserRule (org.eclipse.xtext.ParserRule)6 Status (com.microsoft.z3.Status)3 Model (de.micromata.opengis.kml.v_2_2_0.Model)3 Model (org.sbolstandard.core2.Model)3 Context (com.microsoft.z3.Context)2 Solver (com.microsoft.z3.Solver)2 Kml (de.micromata.opengis.kml.v_2_2_0.Kml)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2