コード例 #1
0
        /// <summary>
        /// Processes primitive effects.
        /// </summary>
        /// <param name="relativeState">Relative state to be modified.</param>
        private void ProcessPrimitiveEffects(IRelativeState relativeState)
        {
            foreach (var positivePredicate in Effects.GroundedPositivePredicateEffects)
            {
                if (relativeState.HasPredicate(positivePredicate))
                {
                    relativeState.RemovePredicate(positivePredicate);
                }
            }

            foreach (var negatedPredicate in Effects.GroundedNegativePredicateEffects)
            {
                if (relativeState.HasNegatedPredicate(negatedPredicate))
                {
                    relativeState.RemoveNegatedPredicate(negatedPredicate);
                }
            }

            foreach (var objectFunction in Effects.GroundedObjectFunctionAssignmentEffects)
            {
                var groundedValue = GroundingManager.GroundTermDeep(objectFunction.Value, OperatorSubstitution, relativeState);

                ConstantTerm constantValue = groundedValue as ConstantTerm;
                if (constantValue != null)
                {
                    if (relativeState.GetObjectFunctionValue(objectFunction.Key) == constantValue.NameId)
                    {
                        relativeState.AssignObjectFunction(objectFunction.Key, ObjectFunctionTerm.UndefinedValue);
                    }
                }
            }

            foreach (var numericFunction in Effects.GroundedNumericFunctionAssignmentEffects)
            {
                NumericAssignmentsBackwardsReplacer replacer = new NumericAssignmentsBackwardsReplacer(Effects.GroundedNumericFunctionAssignmentEffects, GroundingManager, OperatorSubstitution, new Substitution());
                INumericExpression reducedAssignExpression   = replacer.Replace(numericFunction.Value);

                Number assignNumber = reducedAssignExpression as Number;
                if (assignNumber != null)
                {
                    if (relativeState.GetNumericFunctionValue(numericFunction.Key).Equals(assignNumber.Value))
                    {
                        relativeState.AssignNumericFunction(numericFunction.Key, NumericFunction.UndefinedValue);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Visits the expression.
        /// </summary>
        /// <param name="expression">Expression.</param>
        public IElementCNF Visit(NumericCompareLiteralCNF expression)
        {
            // 1.) Evaluates both of the arguments by NumericAssignmentsBackwardsReplacer - every numeric function instance is replaced by
            //     the available numeric assignments from effects and the whole numeric expression is reduced (partially or fully evaluated).
            // 2.) In case of the full reduction of both arguments, the numeric comparison is evaluated - if successfully, the whole condition
            //     is satisfied and we can remove it (i.e. return null).
            // 3.) Otherwise, the modified numeric compare expression is returned, replacing the original condition.

            var numericAssignEffects = Effects.GroundedNumericFunctionAssignmentEffects;

            if (numericAssignEffects.Count == 0)
            {
                // no assignment effects available, just return a copy of the original expression
                return(expression.Clone());
            }

            NumericAssignmentsBackwardsReplacer replacer = new NumericAssignmentsBackwardsReplacer(numericAssignEffects, GroundingManager, OperatorSubstitution, ExpressionSubstitution);
            INumericExpression newLeftNumericExpression  = replacer.Replace(expression.LeftArgument);
            INumericExpression newRightNumericExpression = replacer.Replace(expression.RightArgument);

            UsedGroundedFunctions.UnionWith(replacer.ReplacedFunctionAtomsInSubExpression);

            Number leftNumber  = newLeftNumericExpression as Number;
            Number rightNumber = newRightNumericExpression as Number;

            if (leftNumber != null && rightNumber != null)
            {
                bool relationHolds = NumericCompareExpression.ApplyCompare(expression.Operator, leftNumber.Value, rightNumber.Value);
                if ((relationHolds && !expression.IsNegated) || (!relationHolds && expression.IsNegated))
                {
                    // the numeric comparison was successful -> condition is satisfied, i.e. remove
                    return(null);
                }
            }

            // modified numeric compare expression, replacing the original one
            return(new NumericCompareLiteralCNF(expression.Operator, newLeftNumericExpression, newRightNumericExpression, expression.IsNegated));
        }