Пример #1
0
        static public void WriteGenerateWithType(string type)
        {
            int[] vectorType = Parsing.ParseType(type);

            using (StreamWriter writer = new StreamWriter("log.txt", true))
            {
                WriteDate(writer);
                WriteLine(writer, "Generating permutations for type: " + type);
                WriteLine(writer);
                int[][] permutations = WithoutRepetition.AllPermutationsOfGivenType(vectorType);
                int     counter      = 1;
                foreach (int[] permutation in permutations)
                {
                    Write(writer, counter + ") ");
                    counter++;
                    WriteVector(writer, permutation);
                    WriteLine(writer);
                }
                WriteLine(writer);
            }
        }
Пример #2
0
        static void Handle3WordCommand(string command)
        {
            string[] words = Parsing.GroupByWords(command);
            int[]    permutation;
            switch (words[0])
            {
            case "composition":
                int[] leftPermutation  = Parsing.ParsePermutation(words[1]);
                int[] rightPermutation = Parsing.ParsePermutation(words[2]);
                Writing.WriteComposition(leftPermutation, rightPermutation);
                break;

            case "power":
                permutation = Parsing.ParsePermutation(words[1]);
                int power = int.Parse(words[2]);
                Writing.WritePower(permutation, power);
                break;

            case "permutation-from-index-lo":     //lexicographical order
                int number = int.Parse(words[1]);
                int n      = int.Parse(words[2]);
                Writing.WritePermutationFromIndexLO(number, n);
                break;

            case "permutation-from-index-alo":     //anti lexicographical order
                int numberALO = int.Parse(words[1]);
                int nALO      = int.Parse(words[2]);
                Writing.WritePermutationFromIndexALO(numberALO, nALO);
                break;

            case "generate-with-order":
                int order  = int.Parse(words[1]);
                int length = int.Parse(words[2]);
                Writing.WritePermutationWithOrder(order, length);
                break;

            default:
                throw new Exception("Bad format of command.");
            }
        }
Пример #3
0
 static void WriteTransposition(StreamWriter writer, int[][] permutation)
 {
     Write(writer, Parsing.CycleToTransposition(permutation));
 }
Пример #4
0
 /*
  * static void WriteCycle(StreamWriter writer, int[][] permutation)
  * {
  *  for(int i=0;i<permutation.Length;i++)
  *  {
  *
  *      if(permutation[i].Length>1)
  *      {
  *          Write(writer, "(");
  *          for (int j=0;j<permutation[i].Length;j++)
  *          {
  *              Write(writer, permutation[i][j]);
  *              if (j != (permutation[i].Length - 1)) Write(writer, " ");
  *          }
  *          Write(writer, ")");
  *      }
  *
  *  }
  *  int indexOfMax = Functions.LenghtArrayWithMax(permutation);
  *  if (permutation[indexOfMax].Length==1) Write(writer, "(" + permutation[indexOfMax][0] + ")");
  * }
  */
 static void WriteCycle(StreamWriter writer, int[][] permutation)
 {
     Write(writer, Parsing.CycleToString(permutation));
 }
Пример #5
0
        static void Handle2WordCommand(string command)
        {
            string[] words = Parsing.GroupByWords(command);
            int[]    permutation;
            switch (words[0])
            {
            case "generate":
                Writing.GeneratePermutations(words[1]);
                break;

            case "generate-random":
                Writing.WriteGenerateRandom(int.Parse(words[1]));
                break;

            case "reverse":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteReverse(permutation);
                break;

            case "notations":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteNotations(permutation);
                break;

            case "order":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteOrder(permutation);
                break;

            case "type":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteType(permutation);
                break;

            case "is-involution":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteIsInvolution(permutation);
                break;

            case "is-deregement":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteIsDeregement(permutation);
                break;

            case "is-even":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteIsEven(permutation);
                break;

            case "is-odd":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteIsOdd(permutation);
                break;

            case "sign1":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteSign1(permutation);
                break;

            case "sign2":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteSign2(permutation);
                break;

            case "sign3":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteSign3(permutation);
                break;

            case "sign4":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteSign4(permutation);
                break;

            case "is-transposition":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteIsTransposition(permutation);
                break;

            case "is-one-cycle":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteIsOneCycle(permutation);
                break;

            case "inversion-vector":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteInversionVector(permutation);
                break;

            case "count-cycles":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteCountCycles(permutation);
                break;

            case "count-even-cycles":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteCountEvenCycles(permutation);
                break;

            case "count-odd-cycles":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteCountOddCycles(permutation);
                break;

            case "count-fixed-points":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteCountFixedPoints(permutation);
                break;

            case "count-inversions":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteCountInversions(permutation);
                break;

            case "inversions":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteInversionCommand(permutation);
                break;

            case "index-from-perm-lo":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WritePermutationIndexLO(permutation);
                break;

            case "index-from-perm-alo":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WritePermutationIndexALO(permutation);
                break;

            case "calculate":
                Writing.WriteCalculate(words[1]);
                break;

            case "generate-with-type":
                Writing.WriteGenerateWithType(words[1]);
                break;

            case "generate-anti":
                Writing.GenerateAntilexicographical(words[1]);
                break;

            case "composition-of-transpositions-1":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteCompositionOfTranposition1(permutation);
                break;

            case "composition-of-transpositions-2":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteCompositionOfTranposition2(permutation);
                break;

            case "composition-of-neigh-trans-1":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteCompositionOfNeighbouringTranposition1(permutation);
                break;

            case "composition-of-neigh-trans-2":
                permutation = Parsing.ParsePermutation(words[1]);
                Writing.WriteCompositionOfNeighbouringTranposition2(permutation);
                break;

            default:
                throw new Exception("Bad format of command.");
            }
        }