コード例 #1
0
        /// <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);
                    }
                }
            }
        }