public void ConsoleWriteLines() { var shift = 0; for (int i = 0; i <= _levels; i++) { var nodesNumber = (int)Math.Pow(2, i); var nodesInLine = DescendingTree.GetRange(shift, nodesNumber); shift += nodesNumber; WriteParentColors(nodesInLine); WriteIndexes(nodesInLine); if (i == _levels) { WriteChildColors(nodesInLine); } } for (int i = _levels; i >= 0; i--) { var nodesNumber = (int)Math.Pow(2, i); shift -= nodesNumber; var nodesInLine = AscendingTree.GetRange(shift, nodesNumber); if (i == _levels) { WriteChildColors(nodesInLine, true); } WriteIndexes(nodesInLine, true); WriteParentColors(nodesInLine, true); } }
public List <BWTNode> FindPath(int color, FindCriterion findCriterion) { var leafsNumber = (int)Math.Pow(2, _levels); var descLeafs = DescendingTree.GetRange(DescendingTree.Count - leafsNumber, leafsNumber); var ascLeafs = AscendingTree.GetRange(AscendingTree.Count - leafsNumber, leafsNumber); var descLeafColorCountGoToTheTop = LeafColorCountDictionaryGoToTheTop(descLeafs, color); var ascLeafColorCountGoToTheTop = LeafColorCountDictionaryGoToTheTop(ascLeafs, color); var bridges = new List <List <BWTNode> >(); foreach (var node in descLeafs) { BuildBridges(node, ascLeafs, visited: new List <BWTNode>(), currentPath: new List <BWTNode>(), bridges); } var result = new Dictionary <int, List <BWTNode> >(); foreach (var bridge in bridges) { var counter = 0; for (int i = 0; i < bridge.Count; i++) { if (i != 0) { if (i == bridge.Count - 1) { counter += ascLeafColorCountGoToTheTop[bridge[bridge.Count - 1]]; } else { if (bridge[i].LeftChild.Equals(bridge[i - 1])) { if (bridge[i].LeftChildColor == color) { counter += bridge[i].LeftChildColor; } } if (bridge[i].RightChild.Equals(bridge[i - 1])) { if (bridge[i].RightChildColor == color) { counter += bridge[i].RightChildColor; } } } } else { counter += descLeafColorCountGoToTheTop[bridge[0]]; } } if (!result.Keys.Contains(counter)) { result.Add(counter, bridge); } } if (findCriterion == FindCriterion.MaxBranchesOfColor) { return(BuildPath(result[result.Keys.Max()])); } else { return(BuildPath(result[result.Keys.Min()])); } }