Search in sources :

Example 31 with CompoundPrologTerm

use of de.prob.prolog.term.CompoundPrologTerm 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 32 with CompoundPrologTerm

use of de.prob.prolog.term.CompoundPrologTerm in project prob2 by bendisposto.

the class ModelCheckingStepCommand method processResult.

@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
    CompoundPrologTerm statsTerm = BindingGenerator.getCompoundTerm(bindings.get(STATS_VARIABLE), STATS_ARITY);
    int numberNodes = BindingGenerator.getInteger(statsTerm.getArgument(1)).getValue().intValue();
    int numberTrans = BindingGenerator.getInteger(statsTerm.getArgument(2)).getValue().intValue();
    int numberProcessed = BindingGenerator.getInteger(statsTerm.getArgument(3)).getValue().intValue();
    stats = new StateSpaceStats(numberNodes, numberTrans, numberProcessed);
    result = extractResult(bindings.get(RESULT_VARIABLE));
}
Also used : StateSpaceStats(de.prob.check.StateSpaceStats) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm)

Example 33 with CompoundPrologTerm

use of de.prob.prolog.term.CompoundPrologTerm in project prob2 by bendisposto.

the class ModelCheckingStepCommand method extractResult.

private IModelCheckingResult extractResult(final PrologTerm prologTerm) {
    CompoundPrologTerm cpt = BindingGenerator.getCompoundTerm(prologTerm, prologTerm.getArity());
    String type = cpt.getFunctor();
    switch(type) {
        case "not_yet_finished":
            int maxNodesLeft = BindingGenerator.getInteger(cpt.getArgument(1)).getValue().intValue();
            return new NotYetFinished("Model checking not completed", maxNodesLeft);
        case "ok":
            return new ModelCheckOk("Model Checking complete. No error nodes found.");
        case "full_coverage":
            return new ModelCheckOk("Model Checking complete. All operations were covered.");
        case "ok_not_all_nodes_considered":
            return new ModelCheckOk("Model Checking complete. No error nodes found. Not all nodes were considered.");
        case "deadlock":
            return new ModelCheckErrorUncovered("Deadlock found.", cpt.getArgument(1).getFunctor());
        case "invariant_violation":
            return new ModelCheckErrorUncovered("Invariant violation found.", cpt.getArgument(1).getFunctor());
        case "assertion_violation":
            return new ModelCheckErrorUncovered("Assertion violation found.", cpt.getArgument(1).getFunctor());
        case "state_error":
            return new ModelCheckErrorUncovered("A state error occured.", cpt.getArgument(1).getFunctor());
        case "goal_found":
            return new ModelCheckErrorUncovered("Goal found", cpt.getArgument(1).getFunctor());
        case "well_definedness_error":
            return new ModelCheckErrorUncovered("A well definedness error occured.", cpt.getArgument(1).getFunctor());
        case "general_error":
            if (cpt.getArity() == 2) {
                return new ModelCheckErrorUncovered("An unknown result was uncovered: " + cpt.getArgument(2), cpt.getArgument(1).getFunctor());
            } else {
                return new ModelCheckErrorUncovered("A general error occured in state: ", cpt.getArgument(1).getFunctor());
            }
        default:
            logger.error("Model checking result unknown. This should not happen " + "unless someone changed the prolog kernel. Result was: {} ", cpt);
            throw new IllegalArgumentException("model checking result unknown: " + cpt);
    }
}
Also used : NotYetFinished(de.prob.check.NotYetFinished) ModelCheckOk(de.prob.check.ModelCheckOk) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ModelCheckErrorUncovered(de.prob.check.ModelCheckErrorUncovered)

Example 34 with CompoundPrologTerm

use of de.prob.prolog.term.CompoundPrologTerm in project prob2 by bendisposto.

the class BeforeAfterPredicateCommand method processResult.

@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
    CompoundPrologTerm compoundTerm = BindingGenerator.getCompoundTerm(bindings.get(BA_PRED_VARIABLE), 0);
    String code = compoundTerm.getFunctor();
    result = new EventB(code, FormulaExpand.EXPAND);
}
Also used : EventB(de.prob.animator.domainobjects.EventB) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm)

Example 35 with CompoundPrologTerm

use of de.prob.prolog.term.CompoundPrologTerm in project prob2 by bendisposto.

the class CbcSolveCommand method processResult.

@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
    PrologTerm idList = bindings.get(IDENTIFIER_LIST);
    if (idList instanceof ListPrologTerm) {
        for (PrologTerm id : (ListPrologTerm) idList) {
            freeVariables.add(id.getFunctor());
        }
    }
    PrologTerm prologTerm = bindings.get(EVALUATE_TERM_VARIABLE);
    assert prologTerm instanceof CompoundPrologTerm;
    String functor = prologTerm.getFunctor();
    if ("time_out".equals(functor)) {
        result = new ComputationNotCompletedResult(evalElement.getCode(), "time out");
    }
    if ("contradiction_found".equals(functor)) {
        result = EvalResult.FALSE;
    }
    if ("solution".equals(functor)) {
        ListPrologTerm solutionBindings = BindingGenerator.getList(prologTerm.getArgument(BINDINGS));
        if (solutionBindings.isEmpty()) {
            result = EvalResult.TRUE;
            return;
        }
        Map<String, String> solutions = new HashMap<>();
        for (PrologTerm b : solutionBindings) {
            CompoundPrologTerm t = (CompoundPrologTerm) b;
            solutions.put(t.getArgument(VAR_NAME).getFunctor(), t.getArgument(PRETTY_PRINT).getFunctor());
        }
        result = new EvalResult("TRUE", solutions);
    }
    if ("no_solution_found".equals(functor)) {
        result = new ComputationNotCompletedResult(evalElement.getCode(), "no solution found (but one might exist)");
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) ComputationNotCompletedResult(de.prob.animator.domainobjects.ComputationNotCompletedResult) HashMap(java.util.HashMap) EvalResult(de.prob.animator.domainobjects.EvalResult) AbstractEvalResult(de.prob.animator.domainobjects.AbstractEvalResult) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm)

Aggregations

CompoundPrologTerm (de.prob.prolog.term.CompoundPrologTerm)90 PrologTerm (de.prob.prolog.term.PrologTerm)79 ListPrologTerm (de.prob.prolog.term.ListPrologTerm)74 Test (org.junit.Test)62 IntegerPrologTerm (de.prob.prolog.term.IntegerPrologTerm)8 StructuredPrologOutput (de.prob.prolog.output.StructuredPrologOutput)7 ClassicalB (de.prob.animator.domainobjects.ClassicalB)6 VariablePrologTerm (de.prob.prolog.term.VariablePrologTerm)6 EventB (de.prob.animator.domainobjects.EventB)5 Transition (de.prob.statespace.Transition)5 ArrayList (java.util.ArrayList)4 AbstractEvalResult (de.prob.animator.domainobjects.AbstractEvalResult)3 EvalResult (de.prob.animator.domainobjects.EvalResult)3 IEvalElement (de.prob.animator.domainobjects.IEvalElement)3 ISimplifiedROMap (de.prob.parser.ISimplifiedROMap)3 ComputationNotCompletedResult (de.prob.animator.domainobjects.ComputationNotCompletedResult)2 IPrologTermOutput (de.prob.prolog.output.IPrologTermOutput)2 BigInteger (java.math.BigInteger)2 Collections (java.util.Collections)2 BParser (de.be4.classicalb.core.parser.BParser)1