/// <summary> /// Generate the permutations according to some algorithm /// </summary> /// <param name = "algorithm">Algorithm of generation of the permutations</param> /// <returns>String to be save into the file</returns> private string Generate(PermutationAlgorithm algorithm) { const string begin = "INSERT INTO Permutations VALUES ("; @from = (int)_nudFrom.Value; to = (int)_nudTo.Value; hashTables = (int)_nudLTables.Value; keysPerTale = (int)_nudKeys.Value; StringBuilder final = new StringBuilder(); Dictionary <int, int[]> perms = null; IMinMutualSelector selector = null; switch (algorithm) { case PermutationAlgorithm.UniqueIndexesAcrossPermutation: /*Unique random permutations*/ perms = permutationGeneratorService.GenerateRandomPermutationsUsingUniqueIndexes(hashTables, keysPerTale, @from, to); break; case PermutationAlgorithm.AgressiveSelector: /*Aggressive selector*/ selector = new AgressiveSelector(); perms = permutationGeneratorService.GeneratePermutationsUsingMinMutualInformation(hashTables, keysPerTale, @from, to, selector); break; case PermutationAlgorithm.SummedAccrossSelector: /*SummedAccross selector*/ selector = new SummedAcrossSelector(); perms = permutationGeneratorService.GeneratePermutationsUsingMinMutualInformation(hashTables, keysPerTale, @from, to, selector); break; case PermutationAlgorithm.ConservativeSelector: /*Conservative selector*/ selector = new ConservativeSelector(); perms = permutationGeneratorService.GeneratePermutationsUsingMinMutualInformation(hashTables, keysPerTale, @from, to, selector); break; } /*Create *.txt string*/ if (perms != null) { foreach (KeyValuePair <int, int[]> perm in perms) { final.Append(begin); StringBuilder permutation = new StringBuilder(); permutation.Append(perm.Key + ",'"); foreach (int t in perm.Value) { permutation.Append(t + ";"); } permutation.Append("');"); final.AppendLine(permutation.ToString()); } } return(final.ToString()); }
/// <summary> /// Generate permutations using Minimal Mutual Information Approach /// </summary> /// <param name="tables"> /// L tables [E.g. 20] /// </param> /// <param name="keysPerTable"> /// K keys per table [E.g. 5] /// </param> /// <param name="startIndex"> /// Start index in the permutation set /// </param> /// <param name="endIndex"> /// End index in the permutation set /// </param> /// <param name="selector"> /// The selector. /// </param> /// <returns> /// Dictionary with index of permutation and the list itself /// </returns> public Dictionary <int, int[]> GeneratePermutationsUsingMinMutualInformation(int tables, int keysPerTable, int startIndex, int endIndex, IMinMutualSelector selector) { Dictionary <int, int[]> randomperms = GetRandomPermutations(PermutationPool, ElementsPerPermutation, startIndex, endIndex); var groups = selector.GetPermutations(randomperms, tables, keysPerTable); Dictionary <int, int[]> result = new Dictionary <int, int[]>(); /*Combine the L Groups between them, in order to get the final set of permutations*/ int count = 0; foreach (KeyValuePair <int, List <int[]> > group in groups) { foreach (int[] perm in group.Value) { result.Add(count++, perm); } } return(result); }