public int GetMinimumLettersConsidered(IPermutationDictionary <ExtensionMap> permExMaps, Permutation permutation, IPosition positions, int maximumLettersConsidered) { IPermutationBuilderExternal permutationBuilderExternal = permutationBuilder.Clone(); int length = permutation.Length; NumSequenceExtended numSequenceExtended = numSeqExtFactory.GetNumSequenceDefault(1, length, false); Permutation permutationUpfix = permutationBuilderExternal.CreatePattern(new ulong[] { 0 }, permutation.LetterSize, 0); int minimumLettersConsidered = 0; int index; int popCount; for (int i = 0; i < maximumLettersConsidered; i++) { minimumLettersConsidered++; index = positions.GetPosition(length - i - 1); numSequenceExtended.SetLetterMutable(index, 1); popCount = numSequenceExtended.PopCount(index); permutationUpfix = permutationUpfix.InsertPosition(i + 1 - popCount); if (!permutationsUpfixes[i].Contains(permutationUpfix)) { break; } } return(minimumLettersConsidered); }
public List <PermutationContainerPPA> GetSuccessors(IPermutationDictionary <ExtensionMap> collection, IPermutationsCollection avoidedPermutations) { if (Permutation.Length <= lengthLongestPermutationAvoided) { return(ComputeSuccessors(collection, avoidedPermutations, true)); } else { return(ComputeSuccessors(collection, avoidedPermutations, false)); } }
public bool TryGetExtensionMapsDescendants(out IPermutationDictionary <ExtensionMap> extensionMapsDescendants) { if (extensionMapsDescendantsSet) { extensionMapsDescendants = this.extensionMapsDescendants; return(true); } else { extensionMapsDescendants = null; return(false); } }
public List <PatternNodePPA> ComputeChildren(IPermutationDictionary <ExtensionMap> extensionMaps, IPermutationsCollection permutationsAvoided) { List <PermutationContainerPPA> childrenUnfolded = containerPPA.GetSuccessors(extensionMaps, permutationsAvoided); List <PatternNodePPA> childrenNodes; childrenNodes = ComputeChildren(childrenUnfolded); SetChildren(childrenNodes); return(childrenNodes); }
protected List <PermutationContainerPPA> ComputeSuccessors(IPermutationDictionary <ExtensionMap> collection, IPermutationsCollection avoidedPermutations, bool checkAvoidedPermutations) { Permutation newPermutation; PatternBasic newPermutationPositions; ExtensionMap newExtensionMap; int newMinimumLettersConsidered; List <PermutationContainerPPA> containers = new List <PermutationContainerPPA>(); PermutationContainerPPA permutationContainerPPA; int maximumLettersConsidered = Math.Min(lengthLongestPermutationAvoided, Permutation.Length + 1); foreach (var position in extensionMap.Ctz()) { newPermutation = Permutation.InsertPosition(position); if (checkAvoidedPermutations && avoidedPermutations.Contains(newPermutation)) { continue; } newPermutationPositions = PermutationPositions.InsertLetter(position); newPermutationPositions = CorrectPositionsTop(newPermutationPositions); newMinimumLettersConsidered = minimumLettersBeChecked. GetMinimumLettersConsidered(collection, newPermutation, newPermutationPositions, maximumLettersConsidered); newExtensionMap = exMapComputationUnsorted.Compute(collection, newPermutation, newPermutationPositions, newMinimumLettersConsidered); if (checkAvoidedPermutations) { CorrectExtensionMap(newPermutation, newExtensionMap, avoidedPermutations); } permutationContainerPPA = new PermutationContainerPPA(newPermutation, newPermutationPositions, minimumLettersBeChecked, exMapComputationUnsorted, newExtensionMap, lengthLongestPermutationAvoided, newMinimumLettersConsidered); containers.Add(permutationContainerPPA); } return(containers); }
public ExtensionMap Compute(IPermutationDictionary <ExtensionMap> permExMaps, Permutation permutation, IPosition positions, int lettersConsidered) { ExtensionMap extensionMapDefault = extensionMapFactory. GetExtensionMapDefault(permutation.Length + 1, true); if (lettersConsidered <= 0) { return(extensionMapDefault); } ExtensionMap[] extensionMaps = new ExtensionMap[lettersConsidered]; int positionTo = positions.GetPosition(permutation.Length - 1); Permutation newPermutation = permutation.Delete(positionTo, new int[] {}); permExMaps.TryGetValue(newPermutation, out ExtensionMap extensionMap); extensionMap = extensionMap.Insert(positionTo, extensionMap.Get(positionTo)); extensionMaps[0] = extensionMap; int positionFrom; bool positionDiminished = false; for (int i = 0; i < lettersConsidered - 1; i++) { positionFrom = positions.GetPosition(permutation.Length - i - 2); if (positionFrom >= positionTo) { positionFrom--; positionDiminished = true; } newPermutation = newPermutation.Switch(positionFrom, positionTo); if (positionDiminished) { positionFrom++; } permExMaps.TryGetValue(newPermutation, out extensionMap); extensionMap = extensionMap.Insert(positionFrom, extensionMap.Get(positionFrom)); extensionMaps[i + 1] = extensionMap; positionTo = positionFrom; positionDiminished = false; } return(extensionMapDefault.And(extensionMaps)); }
public void SetExtensionMapsDescendants(IPermutationDictionary <ExtensionMap> extensionMapsDescendants) { extensionMapsDescendantsSet = true; this.extensionMapsDescendants = extensionMapsDescendants; }
public override void DisposeDescendants() { base.DisposeDescendants(); extensionMapsDescendants = null; extensionMapsDescendantsSet = false; }
public PatternNodePPA(IPatternNodePPABuilder builder) : base(builder) { containerPPA = builder.ContainerPPA; extensionMapsDescendantsSet = builder.ExtensionMapsDescendantsSet; extensionMapsDescendants = builder.ExtensionMapsDescendants; }