示例#1
0
 private List <BWTNode> BuildPathToTop(BWTNode node, List <BWTNode> currentPath)
 {
     currentPath.Add(node);
     if (node.Parent == null)
     {
         return(currentPath);
     }
     return(BuildPathToTop(node.Parent, currentPath));
 }
示例#2
0
        private void Colorize(BWTNode node)
        {
            if (node.LeftChild == null && node.RightChild == null)
            {
                return;
            }

            var index = GetLeftColorIndexForLevel(node.Level);

            node.LeftChildColor         = _colors[index];
            node.LeftChild.ParentColor  = _colors[index];
            node.RightChildColor        = _colors[index + 1];
            node.RightChild.ParentColor = _colors[index + 1];
            Colorize(node.LeftChild);
            Colorize(node.RightChild);
        }
示例#3
0
        public int QuantumModeling(int startIndex, int stopIndex)
        {
            BWTNode currentNode = null;

            currentNode = DescendingTree.Find(x => x.Index == startIndex);
            if (currentNode == null)
            {
                currentNode = AscendingTree.Find(x => x.Index == startIndex);
            }
            if (currentNode == null)
            {
                throw new NullReferenceException($"There is no a node with index {startIndex}");
            }

            var currentNodes = new List <BWTNode> {
                currentNode
            };
            var counter = 0;

            while (true)
            {
                counter += 1;
                var newCurrentNodes = new List <BWTNode>();
                foreach (var node in currentNodes)
                {
                    var nodeDoubling1 = RandomStep(node);
                    if (nodeDoubling1.Index == stopIndex)
                    {
                        return(counter);
                    }
                    if (!newCurrentNodes.Contains(nodeDoubling1))
                    {
                        newCurrentNodes.Add(nodeDoubling1);
                    }
                    var nodeDoubling2 = RandomStep(node);
                    if (nodeDoubling2.Index == stopIndex)
                    {
                        return(counter);
                    }
                    if (!newCurrentNodes.Contains(nodeDoubling2))
                    {
                        newCurrentNodes.Add(nodeDoubling2);
                    }
                }
                currentNodes = newCurrentNodes;
            }
        }
示例#4
0
 private void BuildBridges(BWTNode node, List <BWTNode> ascLeafs, List <BWTNode> visited, List <BWTNode> currentPath, List <List <BWTNode> > bridges)
 {
     visited.Add(node);
     currentPath.Add(node);
     if (ascLeafs.Contains(node))
     {
         var currentPathClone = currentPath.Select(x => x.Clone()).ToList();
         bridges.Add(currentPathClone);
     }
     if (!visited.Contains(node.LeftChild))
     {
         BuildBridges(node.LeftChild, ascLeafs, visited, currentPath, bridges);
     }
     if (!visited.Contains(node.RightChild))
     {
         BuildBridges(node.RightChild, ascLeafs, visited, currentPath, bridges);
     }
 }
示例#5
0
        private BWTNode RandomStep(BWTNode currentNode)
        {
            var direction = _rnd.Next(3);

            switch (direction)
            {
            case 0:
                var parent = currentNode.Parent;
                return(parent == null ? currentNode : parent);

            case 1:
                return(currentNode.LeftChild);

            case 2:
                return(currentNode.RightChild);

            default:
                throw new Exception("Incorrect direction");
            }
        }
示例#6
0
        private BWTNode GenerateNode(int?parentIndex, BWTNode parentNode, bool isRight, int level, bool isDescending, int shift = 0, int threshold = 1)
        {
            if (parentIndex == null)
            {
                var root = new BWTNode(0, null, 0, shift, threshold);
                if (isDescending)
                {
                    DescendingTree[0] = root;
                }
                else
                {
                    AscendingTree[0] = root;
                }
                root.ParentColor = 0;
                root.LeftChild   = GenerateNode(0, root, false, level + 1, isDescending, shift);
                root.RightChild  = GenerateNode(0, root, true, level + 1, isDescending, shift);
                return(root);
            }

            if (level > _levels)
            {
                return(null);
            }

            var currentIndex = isRight ? 2 * (int)parentIndex + 2 : 2 * (int)parentIndex + 1;
            var node         = new BWTNode(currentIndex, parentNode, level, shift, threshold);

            if (isDescending)
            {
                DescendingTree[currentIndex] = node;
            }
            else
            {
                AscendingTree[currentIndex] = node;
            }
            node.LeftChild  = GenerateNode(currentIndex, node, false, level + 1, isDescending, shift);
            node.RightChild = GenerateNode(currentIndex, node, true, level + 1, isDescending, shift);
            return(node);
        }
示例#7
0
 private int CountColorByGoToTheTop(BWTNode node, int color, int counter = 0)
 {
     if (node.Parent == null)
     {
         if (node.ParentColor == color)
         {
             return(counter + 1);
         }
         else
         {
             return(counter);
         }
     }
     if (node.ParentColor == color)
     {
         return(CountColorByGoToTheTop(node.Parent, color, counter + 1));
     }
     else
     {
         return(CountColorByGoToTheTop(node.Parent, color, counter));
     }
 }
示例#8
0
        public int NormalModeling(int startIndex, int stopIndex)
        {
            BWTNode currentNode = null;

            currentNode = DescendingTree.Find(x => x.Index == startIndex);
            if (currentNode == null)
            {
                currentNode = AscendingTree.Find(x => x.Index == startIndex);
            }
            if (currentNode == null)
            {
                throw new NullReferenceException($"There is no a node with index {startIndex}");
            }

            var counter = 0;

            do
            {
                currentNode = RandomStep(currentNode);
                counter    += 1;
            }while(currentNode.Index != stopIndex);
            return(counter);
        }