Search in sources :

Example 31 with PrologTerm

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

the class ConstraintBasedRefinementCheckCommand method processResult.

@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
    final PrologTerm resultTerm = bindings.get(RESULT_VARIABLE);
    final ListPrologTerm resultStringTerm = (ListPrologTerm) bindings.get(RESULT_STRINGS_VARIABLE);
    final StringBuilder sb = new StringBuilder();
    for (PrologTerm t : resultStringTerm) {
        sb.append(PrologTerm.atomicString(t));
        sb.append('\n');
    }
    resultsString = sb.toString();
    if (resultTerm.hasFunctor("time_out", 0)) {
        this.result = ResultType.INTERRUPTED;
    } else if (resultTerm.hasFunctor("true", 0)) {
        // Errors were found
        this.result = ResultType.VIOLATION_FOUND;
    // TODO extract message
    } else if (resultTerm.hasFunctor("false", 0)) {
        // Errors were not found
        this.result = ResultType.NO_VIOLATION_FOUND;
    } else {
        throw new ProBError("unexpected result from refinement check: " + resultTerm);
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) ProBError(de.prob.exception.ProBError) PrologTerm(de.prob.prolog.term.PrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm)

Example 32 with PrologTerm

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

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

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

the class AbstractDotDiagramCmd method extractStates.

protected void extractStates(final ListPrologTerm s) {
    for (PrologTerm prologTerm : s) {
        if (prologTerm instanceof CompoundPrologTerm) {
            CompoundPrologTerm cpt = (CompoundPrologTerm) prologTerm;
            String id = Transition.getIdFromPrologTerm(cpt.getArgument(1));
            List<String> labels = new ArrayList<>();
            ListPrologTerm ls = BindingGenerator.getList(cpt.getArgument(4));
            for (PrologTerm pt : ls) {
                labels.add(pt.getFunctor());
            }
            int count = BindingGenerator.getInteger(cpt.getArgument(2)).getValue().intValue();
            String color = cpt.getArgument(3).getFunctor();
            DotNode n = new DotNode(id, labels, count, color);
            nodes.put(id, n);
        }
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) DotNode(de.prob.animator.domainobjects.DotNode) ArrayList(java.util.ArrayList) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm)

Example 35 with PrologTerm

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

the class AbstractDotDiagramCmd method extractTransitions.

protected void extractTransitions(final ListPrologTerm trans) {
    for (PrologTerm pt : trans) {
        if (pt instanceof CompoundPrologTerm) {
            CompoundPrologTerm cpt = (CompoundPrologTerm) pt;
            String id = Transition.getIdFromPrologTerm(cpt.getArgument(1));
            String src = Transition.getIdFromPrologTerm(cpt.getArgument(2));
            String dest = Transition.getIdFromPrologTerm(cpt.getArgument(3));
            String label = cpt.getArgument(4).toString();
            String style = cpt.getArgument(5).getFunctor();
            String color = cpt.getArgument(6).getFunctor();
            DotEdge e = new DotEdge(id, src, dest, label, style, color);
            edges.put(id, e);
        }
    }
}
Also used : DotEdge(de.prob.animator.domainobjects.DotEdge) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm)

Aggregations

PrologTerm (de.prob.prolog.term.PrologTerm)103 ListPrologTerm (de.prob.prolog.term.ListPrologTerm)86 CompoundPrologTerm (de.prob.prolog.term.CompoundPrologTerm)85 Test (org.junit.Test)64 IntegerPrologTerm (de.prob.prolog.term.IntegerPrologTerm)11 StructuredPrologOutput (de.prob.prolog.output.StructuredPrologOutput)10 VariablePrologTerm (de.prob.prolog.term.VariablePrologTerm)8 Transition (de.prob.statespace.Transition)5 IEvalElement (de.prob.animator.domainobjects.IEvalElement)4 ArrayList (java.util.ArrayList)4 CheckBooleanPropertyCommand (de.prob.animator.command.CheckBooleanPropertyCommand)3 AbstractEvalResult (de.prob.animator.domainobjects.AbstractEvalResult)3 EvalResult (de.prob.animator.domainobjects.EvalResult)3 ISimplifiedROMap (de.prob.parser.ISimplifiedROMap)3 IPrologTermOutput (de.prob.prolog.output.IPrologTermOutput)3 RecursiveMachineLoader (de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader)2 LtlParseException (de.be4.ltl.core.parser.LtlParseException)2 ClassicalB (de.prob.animator.domainobjects.ClassicalB)2 ComputationNotCompletedResult (de.prob.animator.domainobjects.ComputationNotCompletedResult)2 StateError (de.prob.animator.domainobjects.StateError)2