Search in sources :

Example 1 with Transition

use of de.prob.statespace.Transition in project prob2 by bendisposto.

the class ConstraintBasedInvariantCheckCommand method extractExamples.

private List<InvariantCheckCounterExample> extractExamples(final ListPrologTerm ceTerm) {
    List<InvariantCheckCounterExample> examples = new ArrayList<>();
    for (final PrologTerm t : ceTerm) {
        final CompoundPrologTerm term = (CompoundPrologTerm) t;
        final String eventName = PrologTerm.atomicString(term.getArgument(1));
        final Transition step1 = Transition.createTransitionFromCompoundPrologTerm(s, BindingGenerator.getCompoundTerm(term.getArgument(2), 4));
        final Transition step2 = Transition.createTransitionFromCompoundPrologTerm(s, BindingGenerator.getCompoundTerm(term.getArgument(3), 4));
        final InvariantCheckCounterExample ce = new InvariantCheckCounterExample(eventName, step1, step2);
        newTransitions.add(step1);
        newTransitions.add(step2);
        examples.add(ce);
    }
    return examples;
}
Also used : InvariantCheckCounterExample(de.prob.check.InvariantCheckCounterExample) ArrayList(java.util.ArrayList) Transition(de.prob.statespace.Transition) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm)

Example 2 with Transition

use of de.prob.statespace.Transition in project prob2 by bendisposto.

the class ConstructTraceCommand method processResult.

@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
    ListPrologTerm trace = BindingGenerator.getList(bindings.get(RESULT_VARIABLE));
    for (PrologTerm term : trace) {
        CompoundPrologTerm t = BindingGenerator.getCompoundTerm(term, 4);
        Transition operation = Transition.createTransitionFromCompoundPrologTerm(stateSpace, t);
        resultTrace.add(operation);
    }
    ListPrologTerm reportedErrors = BindingGenerator.getList(bindings.get(ERRORS_VARIABLE));
    for (PrologTerm prologTerm : reportedErrors) {
        this.errors.add(prologTerm.getFunctor());
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) Transition(de.prob.statespace.Transition) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm)

Example 3 with Transition

use of de.prob.statespace.Transition in project prob2 by bendisposto.

the class LtlCheckingCommand method processResult.

@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
    PrologTerm term = bindings.get(VARIABLE_NAME_RESULT);
    if (term.hasFunctor("ok", 0)) {
        LTLOk res = new LTLOk(ltlFormula);
        result = res;
        value = res;
    } else if (term.hasFunctor("nostart", 0)) {
        LTLError res = new LTLError(ltlFormula, "Could not find initialisation. Try to animating the model.");
        result = res;
        value = res;
    } else if (term.hasFunctor("typeerror", 0)) {
        LTLError res = new LTLError(ltlFormula, "Type error discovered in formula");
        result = res;
        value = res;
    } else if (term.hasFunctor("incomplete", 0)) {
        LTLNotYetFinished res = new LTLNotYetFinished(ltlFormula);
        result = res;
        value = res;
    } else if (term.hasFunctor("counterexample", 3)) {
        CompoundPrologTerm cpt = BindingGenerator.getCompoundTerm(term, 3);
        List<Transition> counterExample = BindingGenerator.getList(cpt.getArgument(1)).stream().filter(pt -> !pt.hasFunctor("none", 0)).map(pt -> Transition.createTransitionFromCompoundPrologTerm(s, BindingGenerator.getCompoundTerm(pt, 4))).collect(Collectors.toList());
        PathType pathType;
        int loopEntry;
        PrologTerm loopStatus = cpt.getArgument(2);
        if (loopStatus.hasFunctor("no_loop", 0)) {
            pathType = PathType.REDUCED;
            loopEntry = -1;
        } else if (loopStatus.hasFunctor("deadlock", 0)) {
            pathType = PathType.FINITE;
            loopEntry = -1;
        } else if (loopStatus.hasFunctor("loop", 1)) {
            pathType = PathType.INFINITE;
            loopEntry = ((IntegerPrologTerm) loopStatus.getArgument(1)).getValue().intValue();
        } else {
            throw new UnexpectedLoopStatusException("LTL model check returned unexpected loop status: " + loopStatus);
        }
        List<Transition> pathToCE = BindingGenerator.getList(cpt.getArgument(3)).stream().map(pt -> Transition.createTransitionFromCompoundPrologTerm(s, BindingGenerator.getCompoundTerm(pt, 4))).collect(Collectors.toList());
        LTLCounterExample res = new LTLCounterExample(ltlFormula, pathToCE, counterExample, loopEntry, pathType);
        result = res;
        value = res;
    } else {
        throw new UnknownLtlResult("Unknown result from LTL checking: " + term);
    }
}
Also used : LTLError(de.prob.check.LTLError) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) LTLNotYetFinished(de.prob.check.LTLNotYetFinished) Collectors(java.util.stream.Collectors) IModelCheckingResult(de.prob.check.IModelCheckingResult) ISimplifiedROMap(de.prob.parser.ISimplifiedROMap) LTL(de.prob.animator.domainobjects.LTL) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) List(java.util.List) Transition(de.prob.statespace.Transition) PrologTerm(de.prob.prolog.term.PrologTerm) BindingGenerator(de.prob.parser.BindingGenerator) LTLOk(de.prob.check.LTLOk) StateSpace(de.prob.statespace.StateSpace) Collections(java.util.Collections) LTLCounterExample(de.prob.check.LTLCounterExample) IntegerPrologTerm(de.prob.prolog.term.IntegerPrologTerm) LTLNotYetFinished(de.prob.check.LTLNotYetFinished) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) IntegerPrologTerm(de.prob.prolog.term.IntegerPrologTerm) LTLError(de.prob.check.LTLError) LTLOk(de.prob.check.LTLOk) Transition(de.prob.statespace.Transition) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) LTLCounterExample(de.prob.check.LTLCounterExample) IntegerPrologTerm(de.prob.prolog.term.IntegerPrologTerm)

Example 4 with Transition

use of de.prob.statespace.Transition in project prob2 by bendisposto.

the class ExecuteUntilCommand method processResult.

@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
    ListPrologTerm trace = BindingGenerator.getList(bindings.get(TRACE_VARIABLE));
    result = bindings.get(RESULT_VARIABLE);
    for (PrologTerm term : trace) {
        CompoundPrologTerm t = BindingGenerator.getCompoundTerm(term, 4);
        Transition operation = Transition.createTransitionFromCompoundPrologTerm(statespace, t);
        resultTrace.add(operation);
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) Transition(de.prob.statespace.Transition) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm)

Example 5 with Transition

use of de.prob.statespace.Transition in project prob2 by bendisposto.

the class ExecuteModelCommand method processResult.

@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
    PrologTerm prologTerm = bindings.get(TRANSITION_VARIABLE);
    CompoundPrologTerm cpt = BindingGenerator.getCompoundTerm(prologTerm, 4);
    Transition operation = Transition.createTransitionFromCompoundPrologTerm(statespace, cpt);
    resultTrace.add(operation);
    IntegerPrologTerm intPrologTerm = BindingGenerator.getInteger(bindings.get(EXECUTED_STEPS_VARIABLE));
    BigInteger bigInt = intPrologTerm.getValue();
    stepsExecuted = bigInt.intValue();
    switch(bindings.get(RESULT_VARIABLE).getFunctor()) {
        case "maximum_nr_of_steps_reached":
            this.result = ExecuteModelResult.MAXIMUM_NR_OF_STEPS_REACHED;
            break;
        case "deadlock":
            this.result = ExecuteModelResult.DEADLOCK;
            break;
        case "error":
            this.result = ExecuteModelResult.ERROR;
            break;
        case "internal_error":
            this.result = ExecuteModelResult.INTERNAL_ERROR;
            break;
        case "time_out":
            this.result = ExecuteModelResult.TIME_OUT;
            break;
        default:
            throw new AssertionError("Unexpected result of execute command.");
    }
}
Also used : Transition(de.prob.statespace.Transition) BigInteger(java.math.BigInteger) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) IntegerPrologTerm(de.prob.prolog.term.IntegerPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) IntegerPrologTerm(de.prob.prolog.term.IntegerPrologTerm)

Aggregations

CompoundPrologTerm (de.prob.prolog.term.CompoundPrologTerm)5 PrologTerm (de.prob.prolog.term.PrologTerm)5 Transition (de.prob.statespace.Transition)5 ListPrologTerm (de.prob.prolog.term.ListPrologTerm)3 IntegerPrologTerm (de.prob.prolog.term.IntegerPrologTerm)2 LTL (de.prob.animator.domainobjects.LTL)1 IModelCheckingResult (de.prob.check.IModelCheckingResult)1 InvariantCheckCounterExample (de.prob.check.InvariantCheckCounterExample)1 LTLCounterExample (de.prob.check.LTLCounterExample)1 LTLError (de.prob.check.LTLError)1 LTLNotYetFinished (de.prob.check.LTLNotYetFinished)1 LTLOk (de.prob.check.LTLOk)1 BindingGenerator (de.prob.parser.BindingGenerator)1 ISimplifiedROMap (de.prob.parser.ISimplifiedROMap)1 IPrologTermOutput (de.prob.prolog.output.IPrologTermOutput)1 StateSpace (de.prob.statespace.StateSpace)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1