コード例 #1
0
        /// <summary>
        /// Processes primitive effects.
        /// </summary>
        /// <param name="relativeState">Relative state.</param>
        /// <returns>Effect relevance (relevant, irrelevant, or anti-relevant).</returns>
        private EffectRelevance ProcessPrimitiveEffects(IRelativeState relativeState)
        {
            bool anyRelevant = false;

            foreach (var predicateAtom in relativeState.GetPredicates())
            {
                anyRelevant |= Effects.GroundedPositivePredicateEffects.Contains(predicateAtom);
                if (Effects.GroundedNegativePredicateEffects.Contains(predicateAtom))
                {
                    return(EffectRelevance.ANTI_RELEVANT);
                }
            }

            foreach (var predicateAtom in relativeState.GetNegatedPredicates())
            {
                anyRelevant |= Effects.GroundedNegativePredicateEffects.Contains(predicateAtom);
                if (Effects.GroundedPositivePredicateEffects.Contains(predicateAtom))
                {
                    return(EffectRelevance.ANTI_RELEVANT);
                }
            }

            foreach (var function in relativeState.GetObjectFunctions())
            {
                ITerm assignValue;
                if (Effects.GroundedObjectFunctionAssignmentEffects.TryGetValue(function.Key, out assignValue))
                {
                    ConstantTerm constantValue = assignValue as ConstantTerm;
                    if (constantValue == null || constantValue.NameId != function.Value)
                    {
                        // surely assigning different value -> anti-relevant
                        return(EffectRelevance.ANTI_RELEVANT);
                    }
                    anyRelevant = true;
                }
            }

            foreach (var function in relativeState.GetNumericFunctions())
            {
                INumericExpression assignExpression;
                if (Effects.GroundedNumericFunctionAssignmentEffects.TryGetValue(function.Key, out assignExpression))
                {
                    Number numberValue = assignExpression as Number;
                    if (numberValue == null || !numberValue.Value.Equals(function.Value))
                    {
                        // surely assigning different value -> anti-relevant
                        return(EffectRelevance.ANTI_RELEVANT);
                    }
                    anyRelevant = true;
                }
            }

            return((anyRelevant) ? EffectRelevance.RELEVANT : EffectRelevance.IRRELEVANT);
        }