コード例 #1
0
ファイル: Keys.cs プロジェクト: Hawkie/Solver
        /// <summary>
        /// This method is looking for a subset that contains values that
        /// the outer set does not contain
        /// </summary>
        /// <param name="outerSet"></param>
        /// <param name="space"></param>
        /// <returns></returns>
        public IPossible ReducedSetValues(IEnumerable <TKey> outerSet, ISpace <TKey> space)
        {
            Keys <TKey> oSet = new Keys <TKey>(outerSet);

            oSet.ExceptWith(this);
            IPossible reducedValues = space.AllValuesAt(this);

            // Get all values in subset combination
            foreach (TKey keyInner in this)
            {
                Possible innerValues = new Possible(space[keyInner]);
                foreach (TKey keyOuter in oSet)
                {
                    innerValues.FilterOut(space[keyOuter]);
                }
                // Each innerKey must have an exclusive value not in the outer set
                if (innerValues.Count > 0)
                {
                    reducedValues.IntersectPossible(innerValues);
                }
                else
                {
                    reducedValues.Clear();
                    break;
                }
            }
            return(reducedValues);
        }