Ejemplo n.º 1
0
        /// <summary>
        /// Initialize the combinations by settings a copy of the values from the
        /// </summary>
        /// <param name="values">List of values to select combinations from.</param>
        /// <param name="lowerIndex">The size of each combination set to return.</param>
        /// <param name="type">The type of Combinations set to generate.</param>
        /// <remarks>
        /// Copies the array and parameters and then creates a map of booleans that will
        /// be used by a permutations object to refence the subset.  This map is slightly
        /// different based on whether the type is with or without repetition.
        ///
        /// When the type is WithoutRepetition, then a map of upper index elements is
        /// created with lower index false's.
        /// E.g. 8 choose 3 generates:
        /// Map: {1 1 1 1 1 0 0 0}
        /// Note: For sorting reasons, false denotes inclusion in output.
        ///
        /// When the type is WithRepetition, then a map of upper index - 1 + lower index
        /// elements is created with the falses indicating that the 'current' element should
        /// be included and the trues meaning to advance the 'current' element by one.
        /// E.g. 8 choose 3 generates:
        /// Map: {1 1 1 1 1 1 1 1 0 0 0} (7 trues, 3 falses).
        /// </remarks>
        private void Initialize(IList <T> values, int lowerIndex, GenerateOption type)
        {
            myMetaCollectionType = type;
            myLowerIndex         = lowerIndex;
            myValues             = new List <T>();
            myValues.AddRange(values);
            var myMap = new List <bool>();

            if (type == GenerateOption.WithoutRepetition)
            {
                for (var i = 0; i < myValues.Count; ++i)
                {
                    if (i >= myValues.Count - myLowerIndex)
                    {
                        myMap.Add(false);
                    }
                    else
                    {
                        myMap.Add(true);
                    }
                }
            }
            else
            {
                for (var i = 0; i < values.Count - 1; ++i)
                {
                    myMap.Add(true);
                }
                for (var i = 0; i < myLowerIndex; ++i)
                {
                    myMap.Add(false);
                }
            }
            myPermutations = new Permutations <bool>(myMap);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initialize the variations for constructors.
 /// </summary>
 /// <param name="values">List of values to select variations from.</param>
 /// <param name="lowerIndex">The size of each variation set to return.</param>
 /// <param name="type">The type of variations set to generate.</param>
 private void Initialize(IEnumerable <T> values, int lowerIndex, GenerateOption type)
 {
     myMetaCollectionType = type;
     myLowerIndex         = lowerIndex;
     myValues             = new List <T>();
     myValues.AddRange(values);
     if (type == GenerateOption.WithoutRepetition)
     {
         var myMap = new List <int>();
         var index = 0;
         for (var i = 0; i < myValues.Count; ++i)
         {
             if (i >= myValues.Count - myLowerIndex)
             {
                 myMap.Add(index++);
             }
             else
             {
                 myMap.Add(Int32.MaxValue);
             }
         }
         myPermutations = new Permutations <int>(myMap);
     }
     else
     {
         ; // myPermutations isn't used.
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Construct a enumerator with the parent object.
 /// </summary>
 /// <param name="source">The source Permutations object.</param>
 public Enumerator(Permutations <T> source)
 {
     myParent = source;
     myLexicographicalOrders = new int[source.myLexicographicOrders.Length];
     source.myLexicographicOrders.CopyTo(myLexicographicalOrders, 0);
     Reset();
 }
        private void Initialize(IList <T> values, int lowerIndex, GenerateOption type)
        {
            this.myMetaCollectionType = type;
            this.myLowerIndex         = lowerIndex;
            this.myValues             = new List <T>();
            this.myValues.AddRange(values);
            List <bool> list = new List <bool>();

            if (type == GenerateOption.WithoutRepetition)
            {
                for (int i = 0; i < this.myValues.Count; i++)
                {
                    if (i >= this.myValues.Count - this.myLowerIndex)
                    {
                        list.Add(false);
                    }
                    else
                    {
                        list.Add(true);
                    }
                }
            }
            else
            {
                for (int j = 0; j < values.Count - 1; j++)
                {
                    list.Add(true);
                }
                for (int k = 0; k < this.myLowerIndex; k++)
                {
                    list.Add(false);
                }
            }
            this.myPermutations = new Permutations <bool>(list);
        }
Ejemplo n.º 5
0
 private void Initialize(IList <T> values, int lowerIndex, GenerateOption type)
 {
     this.myMetaCollectionType = type;
     this.myLowerIndex         = lowerIndex;
     this.myValues             = new List <T>();
     this.myValues.AddRange(values);
     if (type == GenerateOption.WithoutRepetition)
     {
         List <int> list = new List <int>();
         int        num  = 0;
         for (int i = 0; i < this.myValues.Count; i++)
         {
             if (i >= this.myValues.Count - this.myLowerIndex)
             {
                 list.Add(num++);
             }
             else
             {
                 list.Add(2147483647);
             }
         }
         this.myPermutations = new Permutations <int>(list);
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Construct a enumerator with the parent object.
 /// </summary>
 /// <param name="source">The source combinations object.</param>
 public Enumerator(Combinations <T> source)
 {
     myParent = source;
     myPermutationsEnumerator = (Permutations <bool> .Enumerator)myParent.myPermutations.GetEnumerator();
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Construct a enumerator with the parent object.
 /// </summary>
 /// <param name="source">The source Variations object.</param>
 public EnumeratorWithoutRepetition(Variations <T> source)
 {
     myParent = source;
     myPermutationsEnumerator = (Permutations <int> .Enumerator)myParent.myPermutations.GetEnumerator();
 }