Exemplo n.º 1
0
        /// <summary>
        /// Grounds all the cached effects with the currently use operator substitution.
        /// </summary>
        /// <param name="groundingManager">Grounding manager.</param>
        /// <param name="operatorSubstitution">Variables substitution.</param>
        public void GroundEffectsByCurrentOperatorSubstitution(GroundingManager groundingManager, ISubstitution operatorSubstitution)
        {
            OriginalLiftedPredicates.Clear();
            OriginalLiftedFunctions.Clear();

            GroundedPositivePredicateEffects.Clear();
            foreach (var predicate in PositivePredicateEffects)
            {
                var groundedPredicate = operatorSubstitution.IsEmpty() ? predicate : groundingManager.GroundAtom(predicate, operatorSubstitution);
                GroundedPositivePredicateEffects.Add(groundedPredicate);
                if (!OriginalLiftedPredicates.ContainsKey(groundedPredicate))
                {
                    OriginalLiftedPredicates.Add(groundedPredicate, predicate);
                }
            }

            GroundedNegativePredicateEffects.Clear();
            foreach (var predicate in NegativePredicateEffects)
            {
                var groundedPredicate = operatorSubstitution.IsEmpty() ? predicate : groundingManager.GroundAtom(predicate, operatorSubstitution);
                GroundedNegativePredicateEffects.Add(groundedPredicate);
                if (!OriginalLiftedPredicates.ContainsKey(groundedPredicate))
                {
                    OriginalLiftedPredicates.Add(groundedPredicate, predicate);
                }
            }

            GroundedNumericFunctionAssignmentEffects.Clear();
            foreach (var numericFunc in NumericFunctionAssignmentEffects)
            {
                var groundedFunction   = operatorSubstitution.IsEmpty() ? numericFunc.FunctionAtom : groundingManager.GroundAtom(numericFunc.FunctionAtom, operatorSubstitution);
                var groundedAssignment = operatorSubstitution.IsEmpty() ? numericFunc.GetBackwardsSubstitutedValue() : groundingManager.GroundNumericExpression(numericFunc.GetBackwardsSubstitutedValue(), operatorSubstitution);
                GroundedNumericFunctionAssignmentEffects.Add(groundedFunction, groundedAssignment);
                if (!OriginalLiftedFunctions.ContainsKey(groundedFunction))
                {
                    OriginalLiftedFunctions.Add(groundedFunction, numericFunc.FunctionAtom);
                }
            }

            GroundedObjectFunctionAssignmentEffects.Clear();
            foreach (var objectFunc in ObjectFunctionAssignmentEffects)
            {
                var groundedFunction   = operatorSubstitution.IsEmpty() ? objectFunc.FunctionAtom : groundingManager.GroundAtom(objectFunc.FunctionAtom, operatorSubstitution);
                var groundedAssignment = operatorSubstitution.IsEmpty() ? objectFunc.Value : groundingManager.GroundTerm(objectFunc.Value, operatorSubstitution);
                GroundedObjectFunctionAssignmentEffects.Add(groundedFunction, groundedAssignment);
                if (!OriginalLiftedFunctions.ContainsKey(groundedFunction))
                {
                    OriginalLiftedFunctions.Add(groundedFunction, objectFunc.FunctionAtom);
                }
            }
        }