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");
}
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();
}
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());
}
}
}
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();
}
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();
}
Aggregations