Search in sources :

Example 6 with IEvalElement

use of de.prob.animator.domainobjects.IEvalElement 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");
}
Also used : EvalResult(de.prob.animator.domainobjects.EvalResult) AbstractEvalResult(de.prob.animator.domainobjects.AbstractEvalResult) AbstractEvalResult(de.prob.animator.domainobjects.AbstractEvalResult) IEvalElement(de.prob.animator.domainobjects.IEvalElement) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ClassicalB(de.prob.animator.domainobjects.ClassicalB) ISimplifiedROMap(de.prob.parser.ISimplifiedROMap) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) Test(org.junit.Test)

Example 7 with IEvalElement

use of de.prob.animator.domainobjects.IEvalElement in project prob2 by bendisposto.

the class StateSpace method getTransitionsBasedOnParameterValues.

public List<Transition> getTransitionsBasedOnParameterValues(final State stateId, final String opName, final List<String> parameterValues, final int nrOfSolutions) {
    // default value
    String predicate = "1 = 1";
    if (!opName.equals("$initialise_machine") && !opName.equals("$setup_constants")) {
        if (!getLoadedMachine().containsOperations(opName)) {
            throw new IllegalArgumentException("Unknown operation '" + opName + "'");
        }
        OperationInfo machineOperationInfo = getLoadedMachine().getMachineOperationInfo(opName);
        List<String> parameterNames = machineOperationInfo.getParameterNames();
        StringBuilder sb = new StringBuilder();
        if (!parameterNames.isEmpty()) {
            if (parameterNames.size() != parameterValues.size()) {
                throw new IllegalArgumentException("Cannot execute operation " + opName + " because the number of parameters does not match the number of provied values: " + parameterNames.size() + " vs " + parameterValues.size());
            }
            for (int i = 0; i < parameterNames.size(); i++) {
                sb.append(parameterNames.get(i)).append(" = ").append(parameterValues.get(i));
                if (i < parameterNames.size() - 1) {
                    sb.append(" & ");
                }
            }
            predicate = sb.toString();
        }
    }
    final IEvalElement pred = model.parseFormula(predicate, FormulaExpand.EXPAND);
    final GetOperationByPredicateCommand command = new GetOperationByPredicateCommand(this, stateId.getId(), opName, pred, nrOfSolutions);
    execute(command);
    if (command.hasErrors()) {
        throw new IllegalArgumentException("Executing operation " + opName + " with predicate " + predicate + " produced errors: " + Joiner.on(", ").join(command.getErrors()));
    }
    return command.getNewTransitions();
}
Also used : OperationInfo(de.prob.animator.command.GetMachineOperationInfos.OperationInfo) IEvalElement(de.prob.animator.domainobjects.IEvalElement) GetOperationByPredicateCommand(de.prob.animator.command.GetOperationByPredicateCommand)

Example 8 with IEvalElement

use of de.prob.animator.domainobjects.IEvalElement 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());
        }
    }
}
Also used : EvalResult(de.prob.animator.domainobjects.EvalResult) AbstractEvalResult(de.prob.animator.domainobjects.AbstractEvalResult) AbstractEvalResult(de.prob.animator.domainobjects.AbstractEvalResult) IEvalElement(de.prob.animator.domainobjects.IEvalElement) Map(java.util.Map) HashMap(java.util.HashMap)

Example 9 with IEvalElement

use of de.prob.animator.domainobjects.IEvalElement in project prob2 by bendisposto.

the class EvaluateFormulasCommand method writeCommand.

@Override
public void writeCommand(final IPrologTermOutput pout) {
    pout.openTerm(PROLOG_COMMAND_NAME);
    pout.printAtomOrNumber(stateId);
    pout.openList();
    for (IEvalElement evalElement : evalElements) {
        printEvalTerm(pout, evalElement);
    }
    pout.closeList();
    pout.printVariable(EVALUATE_RESULT_VARIABLE);
    pout.closeTerm();
}
Also used : IEvalElement(de.prob.animator.domainobjects.IEvalElement)

Example 10 with IEvalElement

use of de.prob.animator.domainobjects.IEvalElement in project prob2 by bendisposto.

the class EvaluateRegisteredFormulasCommand method writeCommand.

@Override
public void writeCommand(final IPrologTermOutput pto) {
    pto.openTerm(PROLOG_COMMAND_NAME);
    pto.printAtomOrNumber(stateId);
    pto.openList();
    for (IEvalElement formula : formulas) {
        formula.getFormulaId().printUUID(pto);
    }
    pto.closeList();
    pto.printVariable(RESULTS_VARIABLE);
    pto.closeTerm();
}
Also used : IEvalElement(de.prob.animator.domainobjects.IEvalElement)

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