Search in sources :

Example 1 with ComputationNotCompletedResult

use of de.prob.animator.domainobjects.ComputationNotCompletedResult 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 2 with ComputationNotCompletedResult

use of de.prob.animator.domainobjects.ComputationNotCompletedResult 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

AbstractEvalResult (de.prob.animator.domainobjects.AbstractEvalResult)2 ComputationNotCompletedResult (de.prob.animator.domainobjects.ComputationNotCompletedResult)2 EvalResult (de.prob.animator.domainobjects.EvalResult)2 CompoundPrologTerm (de.prob.prolog.term.CompoundPrologTerm)2 ListPrologTerm (de.prob.prolog.term.ListPrologTerm)2 PrologTerm (de.prob.prolog.term.PrologTerm)2 IEvalElement (de.prob.animator.domainobjects.IEvalElement)1 ISimplifiedROMap (de.prob.parser.ISimplifiedROMap)1 IPrologTermOutput (de.prob.prolog.output.IPrologTermOutput)1 IntegerPrologTerm (de.prob.prolog.term.IntegerPrologTerm)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1