Beispiel #1
0
        /// <summary>
        /// Processes conditional (when) effects.
        /// </summary>
        /// <param name="expression">Conditions expression in CNF.</param>
        private ConditionsCNF ProcessWhenEffects(ConditionsCNF expression)
        {
            if (Effects.WhenEffects.Count == 0)
            {
                return(expression);
            }

            // Collect the relevant when effects, first
            List <WhenEffect> relevantWhenEffects = GetRelevantWhenEffectsForConditions(expression);

            // Each of the relevant when effect is either used or not (dynamic programming approach to get all combinations of when effects usage)
            List <ConditionsCNF> applicationResults = new List <ConditionsCNF> {
                expression
            };

            foreach (var whenEffect in relevantWhenEffects)
            {
                Conditions whenCondition = new Conditions(whenEffect.Expression, EvaluationManager);
                EffectsBackwardsConditionsApplier innerApplier = new EffectsBackwardsConditionsApplier(whenCondition, new List <IEffect>(whenEffect.Effects), EvaluationManager);

                List <ConditionsCNF> currentEffectApplications = new List <ConditionsCNF>();
                foreach (var currentCondition in applicationResults)
                {
                    ConditionsCNF modifiedCondition = (ConditionsCNF)innerApplier.ApplyBackwards(currentCondition, new Substitution());
                    currentEffectApplications.Add(modifiedCondition);
                }

                applicationResults.AddRange(currentEffectApplications);
            }

            // Now, all the possible results need to be merged into a single condition via OR and converted into a valid CNF
            return(ConstructCNFFromDisjunction(applicationResults));
        }
Beispiel #2
0
        /// <summary>
        /// Processes forall effects.
        /// </summary>
        /// <param name="expression">Conditions expression in CNF.</param>
        private ConditionsCNF ProcessForallEffects(ConditionsCNF expression)
        {
            if (Effects.ForallEffects.Count == 0)
            {
                return(expression);
            }

            foreach (var forallEffect in Effects.ForallEffects)
            {
                EffectsBackwardsConditionsApplier innerApplier = new EffectsBackwardsConditionsApplier(null, forallEffect.Effects, EvaluationManager);

                IEnumerable <ISubstitution> localSubstitutions = GroundingManager.GenerateAllLocalSubstitutions(forallEffect.Parameters);
                foreach (var localSubstitution in localSubstitutions)
                {
                    OperatorSubstitution.AddLocalSubstitution(localSubstitution);
                    expression = (ConditionsCNF)innerApplier.ApplyBackwards(expression, OperatorSubstitution);
                    OperatorSubstitution.RemoveLocalSubstitution(localSubstitution);
                }
            }
            return(expression);
        }