Search in sources :

Example 11 with ListPrologTerm

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

Example 12 with ListPrologTerm

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

the class GetOperationByPredicateCommand method processResult.

/**
 * This method is called to extract relevant information from ProB's answer.
 * The method is called by the Animator class, most likely it is not
 * interesting for other classes.
 *
 * @see de.prob.animator.command.AbstractCommand#writeCommand(de.prob.prolog.output.IPrologTermOutput)
 */
@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
    ListPrologTerm list = BindingGenerator.getList(bindings.get(NEW_STATE_ID_VARIABLE));
    for (PrologTerm prologTerm : list) {
        CompoundPrologTerm cpt = BindingGenerator.getCompoundTerm(prologTerm, 4);
        operations.add(Transition.createTransitionFromCompoundPrologTerm(s, cpt));
    }
    for (PrologTerm prologTerm : BindingGenerator.getList(bindings.get(ERRORS_VARIABLE))) {
        this.errors.add(prologTerm.getFunctor());
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) 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 13 with ListPrologTerm

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

the class GetOperationsWithTimeout method processResult.

@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
    ListPrologTerm list = BindingGenerator.getList(bindings, TIMEOUT_VARIABLE);
    timeouts = PrologTerm.atomicStrings(list);
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm)

Example 14 with ListPrologTerm

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

the class FindTraceBetweenNodesCommand method processResult.

@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
    PrologTerm trace = bindings.get(TRACE);
    if (trace instanceof ListPrologTerm) {
        for (PrologTerm term : (ListPrologTerm) trace) {
            newTransitions.add(Transition.createTransitionFromCompoundPrologTerm(stateSpace, (CompoundPrologTerm) term));
        }
    } else {
        String msg = "Trace was not found. Error was: " + trace.getFunctor();
        logger.error(msg);
        throw new NoTraceFoundException(msg);
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) 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 15 with ListPrologTerm

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

the class EvaluateRegisteredFormulasCommand method processResult.

@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
    PrologTerm terms = bindings.get(RESULTS_VARIABLE);
    if (terms instanceof ListPrologTerm) {
        ListPrologTerm lpt = BindingGenerator.getList(terms);
        for (int i = 0; i < lpt.size(); i++) {
            PrologTerm pt = lpt.get(i);
            IEvalElement key = formulas.get(i);
            results.put(key, EvalResult.getEvalResult(pt));
        }
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) IEvalElement(de.prob.animator.domainobjects.IEvalElement) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm)

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