/// <summary>
        /// Visits the expression.
        /// </summary>
        /// <param name="expression">Expression.</param>
        public Tuple <bool, bool> Visit(EqualsLiteralCNF expression)
        {
            bool positiveCondition = false;
            bool negativeCondition = true;

            Action <ITerm, ITerm> checkObjectFunctionArgument = (argument, secondaryArgument) =>
            {
                ObjectFunctionTerm objectFunction = argument as ObjectFunctionTerm;
                if (objectFunction != null)
                {
                    ITerm assignValue;
                    if (Effects.GroundedObjectFunctionAssignmentEffects.TryGetValue(GroundingManager.GroundAtom(objectFunction.FunctionAtom, ExpressionSubstitution), out assignValue))
                    {
                        positiveCondition = true;
                        if (!(secondaryArgument is ObjectFunctionTerm) && !(assignValue is ObjectFunctionTerm))
                        {
                            bool valueDiffersValueAssign = !GroundingManager.GroundTerm(secondaryArgument, ExpressionSubstitution).Equals(GroundingManager.GroundTerm(assignValue, OperatorSubstitution));
                            if (valueDiffersValueAssign && !expression.IsNegated || !valueDiffersValueAssign && expression.IsNegated)
                            {
                                // surely assigning different value (or assigning exact value with negated equals) -> not relevant
                                negativeCondition = false;
                            }
                        }
                    }
                }
            };

            checkObjectFunctionArgument(expression.LeftArgument, expression.RightArgument);
            checkObjectFunctionArgument(expression.RightArgument, expression.LeftArgument);

            return(Tuple.Create(positiveCondition, negativeCondition));
        }
예제 #2
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);
                }
            }
        }