Search in sources :

Example 6 with ListPrologTerm

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

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

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

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

use of de.prob.prolog.term.ListPrologTerm 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

ListPrologTerm (de.prob.prolog.term.ListPrologTerm)38 PrologTerm (de.prob.prolog.term.PrologTerm)33 CompoundPrologTerm (de.prob.prolog.term.CompoundPrologTerm)27 Test (org.junit.Test)11 IntegerPrologTerm (de.prob.prolog.term.IntegerPrologTerm)6 VariablePrologTerm (de.prob.prolog.term.VariablePrologTerm)4 ArrayList (java.util.ArrayList)4 Transition (de.prob.statespace.Transition)3 AbstractEvalResult (de.prob.animator.domainobjects.AbstractEvalResult)2 ComputationNotCompletedResult (de.prob.animator.domainobjects.ComputationNotCompletedResult)2 EvalResult (de.prob.animator.domainobjects.EvalResult)2 IEvalElement (de.prob.animator.domainobjects.IEvalElement)2 StateError (de.prob.animator.domainobjects.StateError)2 HashMap (java.util.HashMap)2 List (java.util.List)2 DotEdge (de.prob.animator.domainobjects.DotEdge)1 DotNode (de.prob.animator.domainobjects.DotNode)1 ProBPreference (de.prob.animator.domainobjects.ProBPreference)1 ASTCategory (de.prob.animator.prologast.ASTCategory)1 ASTFormula (de.prob.animator.prologast.ASTFormula)1