use of de.prob.animator.domainobjects.IEvalElement in project prob2 by bendisposto.
the class GetTableForVisualizationCommand method writeCommand.
@Override
public void writeCommand(IPrologTermOutput pto) {
pto.openTerm(PROLOG_COMMAND_NAME);
pto.printAtomOrNumber(id.getId());
pto.printAtom(item.getCommand());
pto.openList();
for (IEvalElement formula : formulas) {
formula.printProlog(pto);
}
pto.closeList();
pto.printVariable(TABLE_VAR);
pto.closeTerm();
}
use of de.prob.animator.domainobjects.IEvalElement 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));
}
}
}
use of de.prob.animator.domainobjects.IEvalElement 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.IEvalElement in project prob2 by bendisposto.
the class RulesModel method getEvalElement.
public IEvalElement getEvalElement(AbstractOperation abstractOperation) {
if (operationStateFormulaCache.containsKey(abstractOperation)) {
return operationStateFormulaCache.get(abstractOperation);
} else {
String name = abstractOperation.getName();
IEvalElement evalElement = this.parseFormula(name, FormulaExpand.EXPAND);
operationStateFormulaCache.put(abstractOperation, evalElement);
return evalElement;
}
}
use of de.prob.animator.domainobjects.IEvalElement in project prob2 by bendisposto.
the class EvaluateFormulasCommandTest method testWriteCommand.
@Test
public void testWriteCommand() throws Exception {
IEvalElement element = new ClassicalB("1<3", FormulaExpand.EXPAND);
StructuredPrologOutput prologTermOutput = new StructuredPrologOutput();
EvaluateFormulaCommand command = new EvaluateFormulaCommand(element, "root");
command.writeCommand(prologTermOutput);
prologTermOutput.fullstop().flush();
Collection<PrologTerm> sentences = prologTermOutput.getSentences();
PrologTerm t = sentences.iterator().next();
assertNotNull(t);
assertTrue(t instanceof CompoundPrologTerm);
assertEquals("evaluate_formula", t.getFunctor());
assertEquals(3, t.getArity());
PrologTerm t1 = t.getArgument(1);
assertEquals("root", t1.getFunctor());
PrologTerm t2 = t.getArgument(2);
assertEquals("eval", t2.getFunctor());
PrologTerm t3 = t.getArgument(3);
assertEquals("Res", t3.getFunctor());
}
Aggregations