Search in sources :

Example 6 with AbstractEvalResult

use of de.prob.animator.domainobjects.AbstractEvalResult 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;
}
Also used : HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) AbstractEvalResult(de.prob.animator.domainobjects.AbstractEvalResult) EvaluationCommand(de.prob.animator.command.EvaluationCommand) ArrayList(java.util.ArrayList) IEvalElement(de.prob.animator.domainobjects.IEvalElement) HashMap(java.util.HashMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) ComposedCommand(de.prob.animator.command.ComposedCommand)

Aggregations

AbstractEvalResult (de.prob.animator.domainobjects.AbstractEvalResult)6 IEvalElement (de.prob.animator.domainobjects.IEvalElement)5 EvalResult (de.prob.animator.domainobjects.EvalResult)4 HashMap (java.util.HashMap)3 ISimplifiedROMap (de.prob.parser.ISimplifiedROMap)2 CompoundPrologTerm (de.prob.prolog.term.CompoundPrologTerm)2 ListPrologTerm (de.prob.prolog.term.ListPrologTerm)2 PrologTerm (de.prob.prolog.term.PrologTerm)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 AbstractOperation (de.be4.classicalb.core.parser.rules.AbstractOperation)1 ComputationOperation (de.be4.classicalb.core.parser.rules.ComputationOperation)1 RuleOperation (de.be4.classicalb.core.parser.rules.RuleOperation)1 ComposedCommand (de.prob.animator.command.ComposedCommand)1 EvaluationCommand (de.prob.animator.command.EvaluationCommand)1 ClassicalB (de.prob.animator.domainobjects.ClassicalB)1 ComputationNotCompletedResult (de.prob.animator.domainobjects.ComputationNotCompletedResult)1 TranslatedEvalResult (de.prob.animator.domainobjects.TranslatedEvalResult)1 IPrologTermOutput (de.prob.prolog.output.IPrologTermOutput)1 IntegerPrologTerm (de.prob.prolog.term.IntegerPrologTerm)1