Exemple #1
0
 public static void Main(string[] args)
 {
     Combinatorics obj = new Combinatorics();
     int[] array = new int[] { 1, 2, 3, 4, 5};
     obj.Permute(array);
     obj.Combine(array);
 }
Exemple #2
0
        public static void Main(string[] args)
        {
            Combinatorics obj = new Combinatorics();

            int[] array = new int[] { 1, 2, 3, 4, 5 };
            obj.Permute(array);
            obj.Combine(array);
        }
Exemple #3
0
        /// <summary>
        /// Создает ConvexHull из системы линейных уравнений A*x <= b
        /// </summary>
        /// <param name="A">Матрица A</param>
        /// <param name="b">вектор b</param>
        /// <returns></returns>
        public static ConvexHull CreateFromHPolytope(double[][] A, double[] b)
        {
            int[]           rowsNumbers = A.Select((x, i) => i).ToArray();
            int             varsCount   = A[0].Count();
            List <double[]> vertices    = new List <double[]>();

            foreach (var combination in Combinatorics.Combinations(rowsNumbers, varsCount))
            {
                double[,] Acomb = new double[varsCount, varsCount];
                double[] bcomb = new double[varsCount];
                for (int i = 0; i < varsCount; i++)
                {
                    for (int j = 0; j < varsCount; j++)
                    {
                        Acomb[i, j] = A[combination[i]][j];
                    }
                    bcomb[i] = b[combination[i]];
                }

                if (!Acomb.IsSingular())
                {
                    var potentialV = Acomb.Solve(bcomb);
                    if (A.Dot(potentialV).Subtract(b).All(x => x <= EPS))
                    {
                        vertices.Add(potentialV);
                    }
                }
            }

            if (vertices.Count() > 0)
            {
                return(new ConvexHull(vertices));
            }
            else
            {
                return(null);
            }
        }