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)");
}
}
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());
}
}
Aggregations