/// <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));
        }
Esempio n. 2
0
        /// <summary>
        /// Transforms the term.
        /// </summary>
        /// <param name="term">Term.</param>
        /// <returns>Transformed term.</returns>
        public ITerm Visit(ObjectFunctionTerm term)
        {
            if (ReferenceState != null)
            {
                IAtom groundedFunctionAtom = GroundAtomDeep(term.FunctionAtom, Substitution, ReferenceState);
                return(new ConstantTerm(ReferenceState.GetObjectFunctionValue(groundedFunctionAtom), IdManager));
            }

            return(new ObjectFunctionTerm(GroundAtom(term.FunctionAtom, Substitution), IdManager));
        }
Esempio n. 3
0
        /// <summary>
        /// Checks whether the literal is in the form of a simple object function assignment, e.g. (= (objFunc) constA),
        /// and in such case returns the pair of object function and its assigned value. Otherwise returns null.
        /// </summary>
        /// <returns>Object function assignment with its value, if the literal is in such form. Null otherwise.</returns>
        public Tuple <ObjectFunctionTerm, ConstantTerm> TryGetObjectFunctionAssignment()
        {
            ObjectFunctionTerm objFunc   = LeftArgument as ObjectFunctionTerm;
            ConstantTerm       constTerm = RightArgument as ConstantTerm;

            if (objFunc == null || constTerm == null)
            {
                objFunc   = RightArgument as ObjectFunctionTerm;
                constTerm = LeftArgument as ConstantTerm;
            }

            return((objFunc == null || constTerm == null) ? null : Tuple.Create(objFunc, constTerm));
        }
Esempio n. 4
0
        /// <summary>
        /// Visits expression term.
        /// </summary>
        /// <param name="term">Expression term.</param>
        public void PostVisit(ObjectFunctionTerm term)
        {
            List <int> argumentsList = new List <int>();

            for (int i = 0; i < term.Terms.Count; ++i)
            {
                argumentsList.Add(TermStack.Pop());
            }
            argumentsList.Reverse();

            IGroundedAtom groundedFunctionAtom = new GroundedAtom(term.NameID, argumentsList);

            int groundedConstantValue = ReferenceState.GetObjectFunctionValue(groundedFunctionAtom);

            TermStack.Push(groundedConstantValue);
        }
Esempio n. 5
0
        /// <summary>
        /// Extracts the parameters from the given term.
        /// </summary>
        /// <param name="term">Term.</param>
        private void ExtractParameters(ITerm term)
        {
            VariableTerm variableTerm = term as VariableTerm;

            if (variableTerm != null)
            {
                CollectedParameters.Add(variableTerm.NameId);
                return;
            }

            ObjectFunctionTerm objectFunctionTerm = term as ObjectFunctionTerm;

            if (objectFunctionTerm != null)
            {
                ExtractParameters(objectFunctionTerm.FunctionAtom);
            }
        }
        /// <summary>
        /// Checks whether the term needs a rename and performs the rename.
        /// </summary>
        /// <param name="term">Predicate or function term.</param>
        private void CheckAndRenameTerm(ITerm term)
        {
            VariableTerm variableTerm = term as VariableTerm;

            if (variableTerm != null)
            {
                int newParameterId;
                if (ParametersRemapping.TryGetValue(variableTerm.NameId, out newParameterId))
                {
                    variableTerm.NameId = newParameterId;
                }
                return;
            }

            ObjectFunctionTerm objectFunctionTerm = term as ObjectFunctionTerm;

            if (objectFunctionTerm != null)
            {
                CheckAndRenameAtom(objectFunctionTerm.FunctionAtom);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Visits the expression.
        /// </summary>
        /// <param name="expression">Expression.</param>
        public IElementCNF Visit(EqualsLiteralCNF expression)
        {
            var objectAssignEffects = Effects.GroundedObjectFunctionAssignmentEffects;

            if (objectAssignEffects.Count == 0)
            {
                return(expression.Clone());
            }

            Func <ITerm, ITerm> transformArgument = null;

            transformArgument = (term) =>
            {
                ObjectFunctionTerm objectFunction = term as ObjectFunctionTerm;
                if (objectFunction != null)
                {
                    ITerm assignmentValue;
                    if (objectAssignEffects.TryGetValue(GroundAtom(objectFunction.FunctionAtom), out assignmentValue))
                    {
                        UsedGroundedFunctions.Add(objectFunction.FunctionAtom);
                        return(transformArgument(assignmentValue));
                    }
                }
                return(term.Clone());
            };

            ITerm transformedLeftTerm  = transformArgument(expression.LeftArgument);
            ITerm transformedRightTerm = transformArgument(expression.RightArgument);

            bool termsEqual = transformedLeftTerm.Equals(transformedRightTerm);

            if ((termsEqual && !expression.IsNegated) || (!termsEqual && expression.IsNegated))
            {
                // exact constant assignment (or unassignment with negated equals) -> positively contributing, i.e. remove
                return(null);
            }

            return(new EqualsLiteralCNF(transformedLeftTerm, transformedRightTerm, expression.IsNegated));
        }
Esempio n. 8
0
 /// <summary>
 /// Visits expression term.
 /// </summary>
 /// <param name="term">Expression term.</param>
 public void Visit(ObjectFunctionTerm term)
 {
 }
        /// <summary>
        /// Processes a single CNF literal of operator preconditions.
        /// </summary>
        /// <param name="literal">CNF literal.</param>
        /// <param name="state">Relative state to be applied to.</param>
        private static void ProcessPreconditionLiteral(LiteralCNF literal, IRelativeState state)
        {
            PredicateLiteralCNF predicateLiteral = literal as PredicateLiteralCNF;

            if (predicateLiteral != null)
            {
                if (predicateLiteral.IsNegated)
                {
                    state.AddNegatedPredicate(predicateLiteral.PredicateAtom);
                }
                else
                {
                    state.AddPredicate(predicateLiteral.PredicateAtom);
                }
                return;
            }

            EqualsLiteralCNF equalsLiteral = literal as EqualsLiteralCNF;

            if (equalsLiteral != null)
            {
                ObjectFunctionTerm objFunc   = equalsLiteral.LeftArgument as ObjectFunctionTerm;
                ConstantTerm       constTerm = equalsLiteral.RightArgument as ConstantTerm;

                if (objFunc == null || constTerm == null)
                {
                    objFunc   = equalsLiteral.RightArgument as ObjectFunctionTerm;
                    constTerm = equalsLiteral.LeftArgument as ConstantTerm;
                }

                if (objFunc != null && constTerm != null)
                {
                    if (equalsLiteral.IsNegated)
                    {
                        if (state.GetObjectFunctionValue(objFunc.FunctionAtom) == constTerm.NameId)
                        {
                            state.AssignObjectFunction(objFunc.FunctionAtom, IdManager.InvalidId);
                        }
                    }
                    else
                    {
                        state.AssignObjectFunction(objFunc.FunctionAtom, constTerm.NameId);
                    }
                }
                return;
            }

            NumericCompareLiteralCNF compareLiteral = literal as NumericCompareLiteralCNF;

            if (compareLiteral != null)
            {
                if (compareLiteral.Operator != NumericCompareExpression.RelationalOperator.EQ)
                {
                    return;
                }

                NumericFunction numFunc = compareLiteral.LeftArgument as NumericFunction;
                Number          number  = compareLiteral.RightArgument as Number;

                if (numFunc == null || number == null)
                {
                    numFunc = compareLiteral.RightArgument as NumericFunction;
                    number  = compareLiteral.LeftArgument as Number;
                }

                if (numFunc != null && number != null)
                {
                    if (compareLiteral.IsNegated)
                    {
                        if (state.GetNumericFunctionValue(numFunc.FunctionAtom).Equals(number.Value))
                        {
                            state.AssignNumericFunction(numFunc.FunctionAtom, NumericFunction.DefaultValue);
                        }
                    }
                    else
                    {
                        state.AssignNumericFunction(numFunc.FunctionAtom, number.Value);
                    }
                }
            }
        }