Exemplo n.º 1
0
        /// <summary>
        /// Checks whether the operator effects are relevant to the given target conditions.
        /// </summary>
        /// <param name="conditions">Conditions for the application.</param>
        /// <param name="operatorPreconditions">Operator preconditions.</param>
        /// <returns>True if the operator effects are relevant to the given conditions, false otherwise.</returns>
        public bool IsRelevant(IConditions conditions, ISimpleConditions operatorPreconditions)
        {
            // Besides the effects relevance, we need to check whether the operator preconditions are not in conflict with the resulting
            // conditions (after backward-apply). This can be done via affected variables: if some effect is relevant, then it modifies a
            // variable, and a constraint corresponding to this variable can be removed from the preconditions. At the end, we check the
            // modified precondition constraints with the target conditions and if there are conflicts, we consider the operator not
            // relevant. This approach works even for conditional-effects, because we take the worst case scenario.

            IConditions nonAffectedPreconditions = (IConditions)operatorPreconditions.Clone();

            bool anyRelevant = false;

            foreach (var effect in this)
            {
                var relevance = effect.IsRelevant(conditions);
                if (relevance == EffectRelevance.ANTI_RELEVANT)
                {
                    return(false);
                }
                else if (relevance == EffectRelevance.RELEVANT)
                {
                    anyRelevant = true;
                    nonAffectedPreconditions.RemoveConstraint(effect.GetAssignment());
                }
            }

            return(anyRelevant && !nonAffectedPreconditions.IsConflictedWith(conditions));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Applies the effect backwards to the given conditions.
 /// </summary>
 /// <param name="conditions">Conditions.</param>
 public virtual IConditions ApplyBackwards(IConditions conditions)
 {
     if (!conditions.IsConflictedWith(Assignment))
     {
         conditions.RemoveConstraint(Assignment);
         return(conditions);
     }
     return(new ConditionsContradiction());
 }
Exemplo n.º 3
0
 /// <summary>
 /// Checks whether the conditions are in conflict with the other conditions (i.e. different constraints on the same variables).
 /// </summary>
 /// <param name="other">Other conditions.</param>
 /// <returns>True if the conditions are conflicted with the other conditions, false otherwise.</returns>
 public bool IsConflictedWith(IConditions other)
 {
     foreach (var assignment in this)
     {
         if (other.IsConflictedWith(assignment))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Checks whether the operator effect is relevant to the given target conditions.
        /// </summary>
        /// <param name="conditions">Conditions.</param>
        /// <returns>Effect relevance result.</returns>
        public override EffectRelevance IsRelevant(IConditions conditions)
        {
            var assignmentRelevance = base.IsRelevant(conditions);

            if (assignmentRelevance == EffectRelevance.RELEVANT)
            {
                IConditions nonAffectedConditions = (IConditions)Conditions.Clone();
                nonAffectedConditions.RemoveConstraint(Assignment);
                if (!nonAffectedConditions.IsConflictedWith(conditions))
                {
                    return(EffectRelevance.RELEVANT);
                }
            }

            // conditional effect does not have to be used, so it should never be explicitly anti-relevant
            return(EffectRelevance.IRRELEVANT);
        }