コード例 #1
0
 internal static bool isAnyComposition(int[][] permutations)
 {
     for (int i = 0; i < permutations.Length; i++)
     {
         for (int j = 0; j < permutations.Length; j++)
         {
             int[] composition = WithoutRepetition.CompositionOfPermutation(permutations[i], permutations[j]);
             bool  flag        = false;
             for (int k = 0; k < permutations.Length; k++)
             {
                 if (!flag)
                 {
                     if (ArrayFunctions.compareIntArrays(composition, permutations[k]))
                     {
                         flag = true;
                     }
                 }
             }
             if (!flag)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
コード例 #2
0
 internal static bool isIdentity(int[] permutation)
 {
     int[] identity = createIdentityPermutation(permutation.Length);
     if (ArrayFunctions.compareIntArrays(identity, permutation))
     {
         return(true);
     }
     return(false);
 }
コード例 #3
0
        internal static int[] nextElementLexicographical(int[] previousPermutation)
        {
            int[] returnedPermutation = new int[previousPermutation.Length];
            int   index = ArrayFunctions.decreasingSequence(previousPermutation); //index przechowuje indeks pierwszego elementu ciągu malejącego w tablicy

            if (index == 0)
            {
                returnedPermutation = ArrayFunctions.reverseArray(createIdentityPermutation(previousPermutation.Length));
            }
            else
            {
                int        indexMin;
                List <int> list = new List <int>();
                for (int j = previousPermutation.Length - 1; ; j--)
                {
                    if (previousPermutation[j] > previousPermutation[index - 1])
                    {
                        indexMin = j;
                        break;
                    }
                }


                for (int j = 0; j < index - 1; j++)
                {
                    list.Add(previousPermutation[j]);
                }
                list.Add(previousPermutation[indexMin]);

                List <int> toReverse = new List <int>();

                for (int j = index; j < previousPermutation.Length; j++)
                {
                    if (j != indexMin)
                    {
                        toReverse.Add(previousPermutation[j]);
                    }
                    else
                    {
                        toReverse.Add(previousPermutation[index - 1]);
                    }
                }

                List <int> reversedList = ArrayFunctions.reversedList(toReverse);

                foreach (int j in reversedList)
                {
                    list.Add(j);
                }

                returnedPermutation = list.ToArray();
            }

            return(returnedPermutation);
        }
コード例 #4
0
 internal static bool isAnyIdentity(int[][] permutations)
 {
     int[] e = createIdentityPermutation(permutations[0].Length);
     for (int i = 0; i < permutations.Length; i++)
     {
         if (ArrayFunctions.compareIntArrays(permutations[i], e))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #5
0
 internal static bool isAnyReverse(int[][] permutations)
 {
     for (int i = 0; i < permutations.Length; i++)
     {
         bool flag = false;
         for (int j = 0; j < permutations.Length; j++)
         {
             if (!flag)
             {
                 int[] reverse = WithoutRepetition.ReversePermutation(permutations[j]);
                 if (ArrayFunctions.compareIntArrays(permutations[i], reverse))
                 {
                     flag = true;
                 }
             }
         }
         if (!flag)
         {
             return(false);
         }
     }
     return(true);
 }