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