try {
for (int i = 0; i < steps; i++) {
trace = trace.anyEvent(null);
System.out.println(trace.getCurrent().getTransition().evaluate().getPrettyRep());
//if (!trace.getCurrentState().isInvariantOk()) {
// throw new Exception("Invariants violation");
//}
}
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
How can I get info about a "broken" invariant in this case?
Thanks,
Denis
How can I get info about a "broken" invariant in this case?
List<IEvalElement> invariants = new ArrayList<>();
EventBMachine machine = (EventBMachine) stateSpace.getMainComponent();
for (Invariant i : machine.getAllInvariants()) {
invariants.add(i.getPredicate());
}
List<AbstractEvalResult> results = trace.getCurrentState().eval(invariants);
List<String> violated_invariants = new ArrayList<>();
for (int i = 0; i < results.size(); ++i) {
EvalResult r = (EvalResult) results.get(i);
if (r != EvalResult.TRUE) {
violated_invariants.add(invariants.get(i).toString());
}
}
if (!violated_invariants.isEmpty()) {
System.out.println("Violated invariants:\n\t - " + String.join("\n\t - ", violated_invariants));
}