use of de.prob.animator.domainobjects.EvalResult 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.EvalResult in project prob2 by bendisposto.
the class EvaluateFormulasCommandTest method testProcessResult.
@Test
public void testProcessResult() throws Exception {
IEvalElement element = new ClassicalB("1<3", FormulaExpand.EXPAND);
final CompoundPrologTerm lpt = mk_result("true");
ISimplifiedROMap<String, PrologTerm> m1 = new ISimplifiedROMap<String, PrologTerm>() {
@Override
public PrologTerm get(final String key) {
return lpt;
}
};
EvaluateFormulaCommand command = new EvaluateFormulaCommand(element, "root");
command.processResult(m1);
AbstractEvalResult value = command.getValue();
assertEquals(((EvalResult) value).getValue(), "true");
assertEquals(((EvalResult) value).getSolutions().get("a"), "3");
}
use of de.prob.animator.domainobjects.EvalResult in project prob2 by bendisposto.
the class PersistentTransition method addValuesToDestState.
private void addValuesToDestState(Map<IEvalElement, AbstractEvalResult> map) {
if (destState == null) {
destState = new HashMap<>();
}
for (Map.Entry<IEvalElement, AbstractEvalResult> entry : map.entrySet()) {
if (entry.getValue() instanceof EvalResult) {
EvalResult evalResult = (EvalResult) entry.getValue();
destState.put(entry.getKey().getCode(), evalResult.getValue());
}
}
}
use of de.prob.animator.domainobjects.EvalResult 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());
}
}
use of de.prob.animator.domainobjects.EvalResult in project prob2 by bendisposto.
the class RuleResult method transformCounterExamples.
private void transformCounterExamples(AbstractEvalResult abstractEvalResult) {
EvalResult evalCurrent = (EvalResult) abstractEvalResult;
TranslatedEvalResult translatedResult = null;
try {
translatedResult = evalCurrent.translate();
} catch (Exception e) {
/*- fall back solution if the result can not be parsed (e.g. {1,...,1000})
* should not not happen because MAX_DISPLAY_SET is set to -1
* and hence, no truncated terms are delivered by ProBCore
* */
final String message = evalCurrent.getValue().replaceAll("\"", "");
counterExamples.add(new CounterExample(1, message));
return;
}
if (translatedResult.getValue() instanceof de.prob.translator.types.Set) {
de.prob.translator.types.Set set = (de.prob.translator.types.Set) translatedResult.getValue();
for (final BObject object : set) {
if (object instanceof Tuple) {
final Tuple tuple = (Tuple) object;
de.prob.translator.types.Number first = (de.prob.translator.types.Number) tuple.getFirst();
int errorType = first.intValue();
de.prob.translator.types.String second = (de.prob.translator.types.String) tuple.getSecond();
String message = second.getValue();
counterExamples.add(new CounterExample(errorType, message));
} else {
throw new AssertionError();
}
}
} else if (translatedResult.getValue() instanceof de.prob.translator.types.Sequence) {
de.prob.translator.types.Sequence sequence = (de.prob.translator.types.Sequence) translatedResult.getValue();
for (int i = 1; i <= sequence.size(); i++) {
de.prob.translator.types.String value = (de.prob.translator.types.String) sequence.get(i);
String message = value.getValue();
counterExamples.add(new CounterExample(i, message));
}
} else {
// fall back: should not happen
counterExamples.add(new CounterExample(1, evalCurrent.getValue()));
}
}
Aggregations