use of org.hl7.fhir.dstu3.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;
}
}
Aggregations