Пример #1
0
        /// <summary>
        /// Creates a disjunction of the current conditions and the specified other conditions.
        /// </summary>
        /// <param name="other">Other conditions.</param>
        /// <returns>Disjunction of the current conditions and the given other conditions.</returns>
        public IConditions DisjunctionWith(IConditions other)
        {
            if (other is ConditionsContradiction)
            {
                return((IConditions)Clone());
            }

            ConditionsClause newClause = (ConditionsClause)Clone();

            ConditionsClause otherClause = other as ConditionsClause;

            if (otherClause != null)
            {
                foreach (var conditions in otherClause)
                {
                    newClause.Add((Conditions)conditions.Clone());
                }
            }
            else
            {
                Debug.Assert(other is Conditions);
                newClause.Add((Conditions)other.Clone());
            }

            return(newClause);
        }
Пример #2
0
        /// <summary>
        /// Applies the effect backwards to the given conditions.
        /// </summary>
        /// <param name="conditions">Conditions.</param>
        public override IConditions ApplyBackwards(IConditions conditions)
        {
            if (IsRelevant(conditions) == EffectRelevance.RELEVANT)
            {
                IConditions newConditions = (IConditions)conditions.Clone();
                newConditions.RemoveConstraint(Assignment);
                newConditions = newConditions.ConjunctionWith(Conditions);

                return(conditions.DisjunctionWith(newConditions));
            }
            return(conditions);
        }
Пример #3
0
        /// <summary>
        /// Applies the operator backwards to the given target conditions. The result is a new set of conditions.
        /// </summary>
        /// <param name="conditions">Conditions for the application.</param>
        /// <param name="operatorPreconditions">Operator preconditions.</param>
        /// <returns>Preceding conditions.</returns>
        public IConditions ApplyBackwards(IConditions conditions, ISimpleConditions operatorPreconditions)
        {
            IConditions newConditions = (IConditions)conditions.Clone();

            foreach (var effect in this)
            {
                newConditions = effect.ApplyBackwards(newConditions);
            }
            newConditions = newConditions.ConjunctionWith(operatorPreconditions);

            return(newConditions);
        }
Пример #4
0
        /// <summary>
        /// Creates a disjunction of the current conditions and the specified other conditions.
        /// </summary>
        /// <param name="other">Other conditions.</param>
        /// <returns>Disjunction of the current conditions and the given other conditions.</returns>
        public IConditions DisjunctionWith(IConditions other)
        {
            if (Count == 0)
            {
                // empty conditions always evaluate as true, so any disjunction with this conditions
                // would also be a tautology -> we don't create a clause in this case and just return
                return((IConditions)Clone());
            }

            if (other is ConditionsClause || other is ConditionsContradiction)
            {
                return(other.DisjunctionWith(this));
            }

            Debug.Assert(other is Conditions);
            return(new ConditionsClause((Conditions)Clone(), (Conditions)other.Clone()));
        }
Пример #5
0
 /// <summary>
 /// Creates a disjunction of the current conditions and the specified other conditions.
 /// </summary>
 /// <param name="other">Other conditions.</param>
 /// <returns>Disjunction of the current conditions and the given other conditions.</returns>
 public IConditions DisjunctionWith(IConditions other)
 {
     return((IConditions)other.Clone());
 }