Search in sources :

Example 1 with CSP

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

the class CSPAssertionsCommand method writeCommand.

@Override
public void writeCommand(final IPrologTermOutput pout) {
    pout.openTerm(PROLOG_COMMAND_NAME);
    pout.openList();
    // print parsed expressions/predicates
    for (CSP term : evalElements) {
        term.printPrologAssertion(pout);
    }
    pout.closeList();
    pout.printVariable(RESULT_VARIABLE);
    pout.printVariable(RESULT_TRACES_VARIABLE);
    pout.closeTerm();
}
Also used : CSP(de.prob.animator.domainobjects.CSP)

Example 2 with CSP

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

the class StateSpace method subscribe.

/**
 * This method lets ProB know that the subscriber is interested in the
 * specified formulas. ProB will then evaluate the formulas for every state
 * (after which the values can be retrieved from the
 * {@link State#getValues()} method).
 *
 * @param subscriber
 *            who is interested in the given formulas
 * @param formulas
 *            that are of interest
 * @return whether or not the subscription was successful (will return true
 *         if at least one of the formulas was successfully subscribed)
 */
public boolean subscribe(final Object subscriber, final Collection<? extends IEvalElement> formulas) {
    boolean success = false;
    List<AbstractCommand> subscribeCmds = new ArrayList<>();
    for (IEvalElement formulaOfInterest : formulas) {
        if (formulaOfInterest instanceof CSP) {
            logger.info("CSP formula {} not subscribed because CSP evaluation is not state based. Use eval method instead", formulaOfInterest.getCode());
        } else {
            if (formulaRegistry.containsKey(formulaOfInterest)) {
                formulaRegistry.get(formulaOfInterest).put(subscriber, new WeakReference<Object>(formulaOfInterest));
                success = true;
            } else {
                WeakHashMap<Object, Object> subscribers = new WeakHashMap<>();
                subscribers.put(subscriber, new WeakReference<Object>(subscriber));
                formulaRegistry.put(formulaOfInterest, subscribers);
                subscribeCmds.add(new RegisterFormulaCommand(formulaOfInterest));
                success = true;
            }
        }
    }
    if (!subscribeCmds.isEmpty()) {
        execute(new ComposedCommand(subscribeCmds));
    }
    return success;
}
Also used : CSP(de.prob.animator.domainobjects.CSP) AbstractCommand(de.prob.animator.command.AbstractCommand) ArrayList(java.util.ArrayList) IEvalElement(de.prob.animator.domainobjects.IEvalElement) RegisterFormulaCommand(de.prob.animator.command.RegisterFormulaCommand) ComposedCommand(de.prob.animator.command.ComposedCommand) WeakHashMap(java.util.WeakHashMap)

Example 3 with CSP

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

the class CSPModel method checkSyntax.

@Override
public boolean checkSyntax(final String formula) {
    try {
        CSP element = (CSP) parseFormula(formula, FormulaExpand.TRUNCATE);
        element.printProlog(new PrologTermStringOutput());
        return true;
    } catch (EvaluationException e) {
        return false;
    }
}
Also used : CSP(de.prob.animator.domainobjects.CSP) PrologTermStringOutput(de.prob.prolog.output.PrologTermStringOutput) EvaluationException(de.prob.animator.domainobjects.EvaluationException)

Aggregations

CSP (de.prob.animator.domainobjects.CSP)3 AbstractCommand (de.prob.animator.command.AbstractCommand)1 ComposedCommand (de.prob.animator.command.ComposedCommand)1 RegisterFormulaCommand (de.prob.animator.command.RegisterFormulaCommand)1 EvaluationException (de.prob.animator.domainobjects.EvaluationException)1 IEvalElement (de.prob.animator.domainobjects.IEvalElement)1 PrologTermStringOutput (de.prob.prolog.output.PrologTermStringOutput)1 ArrayList (java.util.ArrayList)1 WeakHashMap (java.util.WeakHashMap)1