/// <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);
            List <bool> myMap = new List <bool>();

            if (type == GenerateOption.WithoutRepetition)
            {
                for (int i = 0; i < myValues.Count; ++i)
                {
                    if (i >= myValues.Count - myLowerIndex)
                    {
                        myMap.Add(false);
                    }
                    else
                    {
                        myMap.Add(true);
                    }
                }
            }
            else
            {
                for (int i = 0; i < values.Count - 1; ++i)
                {
                    myMap.Add(true);
                }
                for (int i = 0; i < myLowerIndex; ++i)
                {
                    myMap.Add(false);
                }
            }
            myPermutations = new Permutations <bool>(myMap);
        }
Example #2
0
        public static BigInteger CaclulPermut(bool _repeat, List <string> charsetSelecting, int numberOfChar)
        {
            Utility make = new Utility();

            obj = new Combinations <string>(make.DoubleCapacityList(charsetSelecting, numberOfChar), numberOfChar);

            foreach (IList <string> charset in obj)
            {
                for (int c = 0; c < charset.Count; c++)
                {
                    s += charset[c];
                }
                break;
            }

            for (int c = 0; c < s.Length; c++)
            {
                permutCharset.Add(s[c].ToString());
            }

            if (_repeat == false)
            {
                permut = new Permutations <string>(permutCharset, GenerateOption.WithoutRepetition);
            }
            else if (_repeat == true)
            {
                permut = new Permutations <string>(permutCharset, GenerateOption.WithRepetition);
            }

            return(permut.Count * obj.Count);
        }
Example #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();
 }
Example #4
0
        public void GeneratePermutationString(List <string> charsetSelecting, BigInteger numberOfAllCombination, BigInteger numberLine, int numberOfChar, bool saveFile, bool zip, bool repeat, int typesAtGenerate, string pathBackUpFiles, string extension)
        {
            BigInteger cpt  = 0;
            Utility    make = new Utility();

            foreach (IList <string> charset in obj)
            {
                s = null;
                permutCharset.Clear();

                for (int c = 0; c < charset.Count; c++)
                {
                    s += charset[c];
                }

                for (int c = 0; c < s.Length; c++)
                {
                    permutCharset.Add(s[c].ToString());
                }

                if (repeat == false)
                {
                    permut = new Permutations <string>(permutCharset, GenerateOption.WithoutRepetition);
                }
                else if (repeat == true)
                {
                    permut = new Permutations <string>(permutCharset, GenerateOption.WithRepetition);
                }

                if (saveFile)
                {
                    BigInteger makeFile = 0;

                    foreach (IList <string> str in permut)
                    {
                        if (makeFile == 0)
                        {
                            make.Setting_UpFile(pathBackUpFiles, extension);
                        }

                        for (int c = 0; c < numberOfChar; c++)
                        {
                            s += str[c];
                        }

                        make.WorkFile.WriteLine(s);
                        s = null;

                        makeFile++;
                        cpt++;

                        if (makeFile >= numberLine | cpt >= numberOfAllCombination)
                        {
                            make.WorkFile.Flush();
                            make.WorkFile.Close();
                            extension = make.Zipper(zip, pathBackUpFiles);
                            make.GenerateOut(pathBackUpFiles, extension);
                            makeFile = 0;
                        }
                    }
                }
                else
                {
                    foreach (IList <string> str in permut)
                    {
                        if (cpt >= numberLine & numberLine != 0)
                        {
                            Environment.Exit(0);
                        }

                        s = null;
                        for (int c = 0; c < str.Count; c++)
                        {
                            s += str[c];
                        }

                        Console.WriteLine(s);
                        cpt++;
                    }
                }
            } //End foreach
        }     //End function