use of de.prob.animator.domainobjects.AbstractEvalResult in project prob2 by bendisposto.
the class RulesChecker method evalOperations.
public Map<AbstractOperation, OperationStatus> evalOperations(State state, Collection<AbstractOperation> operations) {
ArrayList<IEvalElement> formulas = new ArrayList<>();
for (AbstractOperation abstractOperation : operations) {
if (abstractOperation instanceof ComputationOperation || abstractOperation instanceof RuleOperation) {
formulas.add(rulesModel.getEvalElement(abstractOperation));
}
}
state.getStateSpace().subscribe(this, formulas);
Map<IEvalElement, AbstractEvalResult> values = state.getValues();
final Map<AbstractOperation, OperationStatus> states = new HashMap<>();
for (AbstractOperation op : operations) {
if (op instanceof RuleOperation) {
states.put(op, RuleStatus.valueOf(values.get(rulesModel.getEvalElement(op))));
} else if (op instanceof ComputationOperation) {
states.put(op, ComputationStatus.valueOf(values.get(rulesModel.getEvalElement(op))));
}
}
return states;
}
use of de.prob.animator.domainobjects.AbstractEvalResult 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.AbstractEvalResult 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.AbstractEvalResult 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.AbstractEvalResult 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