Search in sources :

Example 1 with GetOperationByPredicateCommand

use of de.prob.animator.command.GetOperationByPredicateCommand 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 2 with GetOperationByPredicateCommand

use of de.prob.animator.command.GetOperationByPredicateCommand in project prob2 by bendisposto.

the class StateSpace method isValidOperation.

/**
 * Tests to see if a combination of an operation name and a predicate is
 * valid from a given state.
 *
 * @param stateId
 *            {@link State} id for state to test
 * @param name
 *            {@link String} name of operation
 * @param predicate
 *            {@link String} predicate to test
 * @return true, if the operation is valid from the given state. False
 *         otherwise.
 */
public boolean isValidOperation(final State stateId, final String name, final String predicate) {
    final ClassicalB pred = new ClassicalB(predicate, FormulaExpand.EXPAND);
    GetOperationByPredicateCommand command = new GetOperationByPredicateCommand(this, stateId.getId(), name, pred, 1);
    execute(command);
    return !command.hasErrors();
}
Also used : GetOperationByPredicateCommand(de.prob.animator.command.GetOperationByPredicateCommand) ClassicalB(de.prob.animator.domainobjects.ClassicalB)

Example 3 with GetOperationByPredicateCommand

use of de.prob.animator.command.GetOperationByPredicateCommand in project prob2 by bendisposto.

the class StateSpace method transitionFromPredicate.

/**
 * Takes the name of an operation and a predicate and finds Operations that
 * satisfy the name and predicate at the given stateId. New Operations are
 * added to the graph. This is only valid for ClassicalB predicates.
 *
 * @param stateId
 *            {@link State} from which the operation should be found
 * @param opName
 *            name of the operation that should be executed
 * @param predicate
 *            an additional guard for the operation. This usually describes
 *            the parameters
 * @param nrOfSolutions
 *            int number of solutions that should be found for the given
 *            predicate
 * @return list of operations calculated by ProB
 */
public List<Transition> transitionFromPredicate(final State stateId, final String opName, final String predicate, final int nrOfSolutions) {
    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 : IEvalElement(de.prob.animator.domainobjects.IEvalElement) GetOperationByPredicateCommand(de.prob.animator.command.GetOperationByPredicateCommand)

Aggregations

GetOperationByPredicateCommand (de.prob.animator.command.GetOperationByPredicateCommand)3 IEvalElement (de.prob.animator.domainobjects.IEvalElement)2 OperationInfo (de.prob.animator.command.GetMachineOperationInfos.OperationInfo)1 ClassicalB (de.prob.animator.domainobjects.ClassicalB)1