/// <summary>
        /// Visits and evaluates relational operator expression.
        /// </summary>
        /// <param name="expression">Relational operator expression.</param>
        /// <returns>True if the specified expression evaluates as true, false otherwise.</returns>
        public bool Visit(NumericCompareExpression expression)
        {
            double leftValue  = NumericEvaluator.Value.Evaluate(expression.LeftArgument, Substitution, ReferenceState);
            double rightValue = NumericEvaluator.Value.Evaluate(expression.RightArgument, Substitution, ReferenceState);

            return(NumericCompareExpression.ApplyCompare(expression.Operator, leftValue, rightValue));
        }
        /// <summary>
        /// Evaluates the expression.
        /// </summary>
        /// <param name="expression">Expression.</param>
        /// <returns>True if the expression is logically true, false otherwise.</returns>
        public bool Visit(NumericCompareLiteralCNF expression)
        {
            double leftValue        = NumericEvaluator.Value.Evaluate(expression.LeftArgument, Substitution, ReferenceState);
            double rightValue       = NumericEvaluator.Value.Evaluate(expression.RightArgument, Substitution, ReferenceState);
            bool   evaluationResult = NumericCompareExpression.ApplyCompare(expression.Operator, leftValue, rightValue);

            return(!expression.IsNegated == evaluationResult);
        }
示例#3
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));
        }