Пример #1
0
            /// <summary>
            /// Generate all possible permutations of length nChosen.
            /// </summary>
            /// <param name="nChosen">nChosen must be ≥ 0 and ≤ data.Length</param>
            public List <double[]> GetPermutations(int nChosen)
            {
                if (nChosen < 0)
                {
                    throw new ArgumentException("nChosen cannot be less than zero. nChosen must be ≥ 0 and ≤ data.Length");
                }
                if (nChosen > _data.Length)
                {
                    throw new ArgumentException("nChosen cannot be less than zero. nChosen must be ≥ 0 and ≤ data.Length");
                }
                if (nChosen == 0)
                {
                    return new List <double[]> {
                               new double[0]
                    }
                }
                ;

                if (nChosen == _data.Length)
                {
                    return(GetPermut(_data));
                }

                CombinationGenerator cg      = new CombinationGenerator(_data);
                List <double[]>      combins = cg.Combinations(nChosen);
                List <double[]>      permuts = new List <double[]>();

                foreach (double[] da in combins)
                {
                    permuts.AddRange(GetPermut(da));
                }
                return(permuts);
            }
Пример #2
0
            /// <summary>
            /// Generate all possible permutations of length nChosen.
            /// </summary>
            /// <param name="nChosen">nChosen must be ≥ 0 and ≤ data.Length</param>
            public List<double[]> GetPermutations(int nChosen)
            {
                if (nChosen < 0)
                    throw new ArgumentException("nChosen cannot be less than zero. nChosen must be ≥ 0 and ≤ data.Length");
                if (nChosen > _data.Length)
                    throw new ArgumentException("nChosen cannot be less than zero. nChosen must be ≥ 0 and ≤ data.Length");
                if (nChosen == 0)
                    return new List<double[]> { new double[0] };

                if (nChosen == _data.Length)
                    return GetPermut(_data);

                CombinationGenerator cg = new CombinationGenerator(_data);
                List<double[]> combins = cg.Combinations(nChosen);
                List<double[]> permuts = new List<double[]>();
                foreach (double[] da in combins)
                {
                    permuts.AddRange(GetPermut(da));
                }
                return permuts;
            }