Search in sources :

Example 1 with IEvalElement

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();
}
Also used : IEvalElement(de.prob.animator.domainobjects.IEvalElement)

Example 2 with IEvalElement

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));
        }
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) IEvalElement(de.prob.animator.domainobjects.IEvalElement) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm)

Example 3 with IEvalElement

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;
}
Also used : RuleOperation(de.be4.classicalb.core.parser.rules.RuleOperation) AbstractOperation(de.be4.classicalb.core.parser.rules.AbstractOperation) HashMap(java.util.HashMap) AbstractEvalResult(de.prob.animator.domainobjects.AbstractEvalResult) IEvalElement(de.prob.animator.domainobjects.IEvalElement) ArrayList(java.util.ArrayList) ComputationOperation(de.be4.classicalb.core.parser.rules.ComputationOperation)

Example 4 with IEvalElement

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;
    }
}
Also used : IEvalElement(de.prob.animator.domainobjects.IEvalElement)

Example 5 with IEvalElement

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());
}
Also used : StructuredPrologOutput(de.prob.prolog.output.StructuredPrologOutput) IEvalElement(de.prob.animator.domainobjects.IEvalElement) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ClassicalB(de.prob.animator.domainobjects.ClassicalB) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) Test(org.junit.Test)

Aggregations

IEvalElement (de.prob.animator.domainobjects.IEvalElement)15 AbstractEvalResult (de.prob.animator.domainobjects.AbstractEvalResult)4 ArrayList (java.util.ArrayList)4 ComposedCommand (de.prob.animator.command.ComposedCommand)3 ListPrologTerm (de.prob.prolog.term.ListPrologTerm)3 PrologTerm (de.prob.prolog.term.PrologTerm)3 HashMap (java.util.HashMap)3 AbstractCommand (de.prob.animator.command.AbstractCommand)2 GetOperationByPredicateCommand (de.prob.animator.command.GetOperationByPredicateCommand)2 ClassicalB (de.prob.animator.domainobjects.ClassicalB)2 EvalResult (de.prob.animator.domainobjects.EvalResult)2 CompoundPrologTerm (de.prob.prolog.term.CompoundPrologTerm)2 Map (java.util.Map)2 WeakHashMap (java.util.WeakHashMap)2 Test (org.junit.Test)2 AbstractOperation (de.be4.classicalb.core.parser.rules.AbstractOperation)1 ComputationOperation (de.be4.classicalb.core.parser.rules.ComputationOperation)1 RuleOperation (de.be4.classicalb.core.parser.rules.RuleOperation)1 EvaluationCommand (de.prob.animator.command.EvaluationCommand)1 OperationInfo (de.prob.animator.command.GetMachineOperationInfos.OperationInfo)1