Ejemplo n.º 1
0
        /// <summary>
        /// Checks whether the operator effects are relevant to the given target relative state.
        /// </summary>
        /// <param name="relativeState">Relative state for the application.</param>
        /// <param name="operatorPreconditions">Operator preconditions.</param>
        /// <returns>True if the operator effects are relevant to the given relative state, false otherwise.</returns>
        public bool IsRelevant(IRelativeState relativeState, ISimpleConditions operatorPreconditions)
        {
            CashedVariablesCollector.Clear();

            bool anyRelevant = false;

            foreach (var effect in this)
            {
                var relevance = effect.IsRelevant(relativeState);
                switch (relevance)
                {
                case EffectRelevance.ANTI_RELEVANT:
                {
                    return(false);
                }

                case EffectRelevance.RELEVANT:
                {
                    anyRelevant = true;
                    CashedVariablesCollector.Add(effect.GetAssignment().GetVariable());
                    break;
                }

                case EffectRelevance.IRRELEVANT:
                {
                    if (effect.GetConditions() != null)
                    {
                        CashedVariablesCollector.Add(effect.GetAssignment().GetVariable());
                    }
                    break;
                }
                }
            }

            if (!anyRelevant)
            {
                return(false);
            }

            // additionally, the relative state has to be checked against operator preconditions ("hidden effects")
            foreach (var constraint in operatorPreconditions)
            {
                int variable = constraint.GetVariable();
                if (!CashedVariablesCollector.Contains(variable))
                {
                    int value = relativeState.GetValue(variable);
                    if (value == RelativeState.WildCardValue)
                    {
                        continue;
                    }

                    if (value != constraint.GetValue())
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks whether the operator effect is relevant to the given target relative state.
        /// </summary>
        /// <param name="relativeState">Relative state.</param>
        /// <returns>Effect relevance result.</returns>
        public override EffectRelevance IsRelevant(IRelativeState relativeState)
        {
            var assignmentRelevance = base.IsRelevant(relativeState);

            if (assignmentRelevance == EffectRelevance.RELEVANT)
            {
                foreach (var constraint in Conditions)
                {
                    if (constraint.GetVariable() == Assignment.GetVariable())
                    {
                        continue;
                    }

                    int value = relativeState.GetValue(constraint.GetVariable());
                    if (value == RelativeState.WildCardValue)
                    {
                        continue;
                    }

                    if (constraint.GetValue() != value)
                    {
                        return(EffectRelevance.IRRELEVANT);
                    }
                }
                return(EffectRelevance.RELEVANT);
            }

            // conditional effect does not have to be used, so it should never be explicitly anti-relevant
            return(EffectRelevance.IRRELEVANT);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Checks whether the operator effect is relevant to the given target relative state.
        /// </summary>
        /// <param name="relativeState">Relative state.</param>
        /// <returns>Effect relevance result.</returns>
        public virtual EffectRelevance IsRelevant(IRelativeState relativeState)
        {
            int value = relativeState.GetValue(Assignment.GetVariable());

            if (value == RelativeState.WildCardValue)
            {
                // not a conflict, but not positively contributing either
                return(EffectRelevance.IRRELEVANT);
            }

            return((Assignment.GetValue() == value) ? EffectRelevance.RELEVANT : EffectRelevance.ANTI_RELEVANT);
        }