use of de.prob.animator.command.EvaluationCommand in project prob2 by bendisposto.
the class StateSpace method evaluateForGivenStates.
/**
* Evaluates all of the formulas for every specified state (if they can be
* evaluated). Internally calls {@link #canBeEvaluated(State)}. If the
* formulas are of interest to a class (i.e. the an object has subscribed to
* the formula) the formula is cached.
*
* @param states
* for which the formula is to be evaluated
* @param formulas
* which are to be evaluated
* @return a map of the formulas and their results for all of the specified
* states
*/
public Map<State, Map<IEvalElement, AbstractEvalResult>> evaluateForGivenStates(final Collection<State> states, final List<IEvalElement> formulas) {
Map<State, Map<IEvalElement, AbstractEvalResult>> result = new HashMap<>();
List<EvaluationCommand> cmds = new ArrayList<>();
for (State stateId : states) {
if (stateId.isInitialised()) {
Map<IEvalElement, AbstractEvalResult> res = new HashMap<>();
result.put(stateId, res);
// Check for cached values
Map<IEvalElement, AbstractEvalResult> map = stateId.getValues();
for (IEvalElement f : formulas) {
if (map.containsKey(f)) {
res.put(f, map.get(f));
} else {
cmds.add(f.getCommand(stateId));
}
}
}
}
execute(new ComposedCommand(cmds));
for (EvaluationCommand efCmd : cmds) {
IEvalElement formula = efCmd.getEvalElement();
AbstractEvalResult value = efCmd.getValue();
State id = addState(efCmd.getStateId());
result.get(id).put(formula, value);
}
return result;
}
Aggregations