Search in sources :

Example 1 with ISimplifiedROMap

use of de.prob.parser.ISimplifiedROMap 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 2 with ISimplifiedROMap

use of de.prob.parser.ISimplifiedROMap in project prob2 by bendisposto.

the class EvaluateFormulasCommandTest method testProcessResult.

@Test
public void testProcessResult() throws Exception {
    IEvalElement element = new ClassicalB("1<3", FormulaExpand.EXPAND);
    final CompoundPrologTerm lpt = mk_result("true");
    ISimplifiedROMap<String, PrologTerm> m1 = new ISimplifiedROMap<String, PrologTerm>() {

        @Override
        public PrologTerm get(final String key) {
            return lpt;
        }
    };
    EvaluateFormulaCommand command = new EvaluateFormulaCommand(element, "root");
    command.processResult(m1);
    AbstractEvalResult value = command.getValue();
    assertEquals(((EvalResult) value).getValue(), "true");
    assertEquals(((EvalResult) value).getSolutions().get("a"), "3");
}
Also used : EvalResult(de.prob.animator.domainobjects.EvalResult) AbstractEvalResult(de.prob.animator.domainobjects.AbstractEvalResult) AbstractEvalResult(de.prob.animator.domainobjects.AbstractEvalResult) IEvalElement(de.prob.animator.domainobjects.IEvalElement) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ClassicalB(de.prob.animator.domainobjects.ClassicalB) ISimplifiedROMap(de.prob.parser.ISimplifiedROMap) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) Test(org.junit.Test)

Example 3 with ISimplifiedROMap

use of de.prob.parser.ISimplifiedROMap in project prob2 by bendisposto.

the class EvalstoreEvalCommand method processResult.

@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
    CompoundPrologTerm term = (CompoundPrologTerm) bindings.get(RESULT_VAR);
    // most fields are about
    if (term.hasFunctor("interrupted", 0)) {
        this.result = new EvalstoreResult(false, true, evalstoreId, null, Collections.emptyList());
    } else if (term.hasFunctor("timeout", 0)) {
        this.result = new EvalstoreResult(true, false, evalstoreId, null, Collections.emptyList());
    } else if (term.hasFunctor("errors", 1)) {
        final ListPrologTerm args = (ListPrologTerm) term.getArgument(1);
        final List<String> errors = args.stream().map(arg -> PrologTerm.atomicString(arg.getArgument(1))).collect(Collectors.toList());
        final String error = errors.isEmpty() ? "unspecified error" : errors.get(0);
        final AbstractEvalResult er = new ComputationNotCompletedResult(evalElement.getCode(), error);
        this.result = new EvalstoreResult(false, false, evalstoreId, er, Collections.emptyList());
    } else if (term.hasFunctor("ok", 4)) {
        // first argument ignored
        final String valueStr = PrologTerm.atomicString(term.getArgument(2));
        final ListPrologTerm ids = (ListPrologTerm) term.getArgument(3);
        final List<String> newIdentifiers = PrologTerm.atomicStrings(ids);
        final long storeId = ((IntegerPrologTerm) term.getArgument(4)).getValue().longValue();
        final EvalResult er = new EvalResult(valueStr, Collections.emptyMap());
        this.result = new EvalstoreResult(false, false, storeId, er, newIdentifiers);
    } else {
        // I don't now which
        throw new IllegalStateException("Unexpected es_eval result: " + term.getFunctor() + "/" + term.getArity());
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) ComputationNotCompletedResult(de.prob.animator.domainobjects.ComputationNotCompletedResult) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) EvalResult(de.prob.animator.domainobjects.EvalResult) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) Collectors(java.util.stream.Collectors) ISimplifiedROMap(de.prob.parser.ISimplifiedROMap) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) List(java.util.List) IEvalElement(de.prob.animator.domainobjects.IEvalElement) PrologTerm(de.prob.prolog.term.PrologTerm) AbstractEvalResult(de.prob.animator.domainobjects.AbstractEvalResult) Collections(java.util.Collections) IntegerPrologTerm(de.prob.prolog.term.IntegerPrologTerm) ComputationNotCompletedResult(de.prob.animator.domainobjects.ComputationNotCompletedResult) EvalResult(de.prob.animator.domainobjects.EvalResult) AbstractEvalResult(de.prob.animator.domainobjects.AbstractEvalResult) AbstractEvalResult(de.prob.animator.domainobjects.AbstractEvalResult) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) List(java.util.List) IntegerPrologTerm(de.prob.prolog.term.IntegerPrologTerm)

Aggregations

ISimplifiedROMap (de.prob.parser.ISimplifiedROMap)3 CompoundPrologTerm (de.prob.prolog.term.CompoundPrologTerm)3 PrologTerm (de.prob.prolog.term.PrologTerm)3 AbstractEvalResult (de.prob.animator.domainobjects.AbstractEvalResult)2 EvalResult (de.prob.animator.domainobjects.EvalResult)2 IEvalElement (de.prob.animator.domainobjects.IEvalElement)2 IPrologTermOutput (de.prob.prolog.output.IPrologTermOutput)2 IntegerPrologTerm (de.prob.prolog.term.IntegerPrologTerm)2 ListPrologTerm (de.prob.prolog.term.ListPrologTerm)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ClassicalB (de.prob.animator.domainobjects.ClassicalB)1 ComputationNotCompletedResult (de.prob.animator.domainobjects.ComputationNotCompletedResult)1 LTL (de.prob.animator.domainobjects.LTL)1 IModelCheckingResult (de.prob.check.IModelCheckingResult)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