use of de.prob.animator.command.GetMachineOperationInfos.OperationInfo in project prob2 by bendisposto.
the class GetMachineOperationInfosCommandTest method testGetMachineOperationInfosCommand.
@Test
public void testGetMachineOperationInfosCommand() throws IOException, ModelTranslationError {
System.out.println(Main.getProBDirectory());
System.out.println(api.getVersion());
s = api.b_load("src" + File.separator + "test" + File.separator + "resources" + File.separator + "b" + File.separator + "ExampleMachine.mch");
assertNotNull(s);
GetMachineOperationInfos command = new GetMachineOperationInfos();
s.execute(command);
System.out.println(command.getOperationInfos());
OperationInfo operationInfo = command.getOperationInfos().get(0);
assertEquals("Foo", operationInfo.getOperationName());
assertEquals("p1", operationInfo.getParameterNames().get(0));
assertEquals("p2", operationInfo.getParameterNames().get(1));
assertEquals("out1", operationInfo.getOutputParameterNames().get(0));
assertEquals("out2", operationInfo.getOutputParameterNames().get(1));
}
use of de.prob.animator.command.GetMachineOperationInfos.OperationInfo in project prob2 by bendisposto.
the class LoadedMachine method getOperations.
private Map<String, OperationInfo> getOperations() {
if (this.machineOperationInfos == null) {
GetMachineOperationInfos command = new GetMachineOperationInfos();
this.stateSpace.execute(command);
this.machineOperationInfos = command.getOperationInfos().stream().collect(Collectors.toMap(OperationInfo::getOperationName, i -> i));
}
return this.machineOperationInfos;
}
use of de.prob.animator.command.GetMachineOperationInfos.OperationInfo 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();
}
Aggregations