Esempio n. 1
0
 public GuideTreeNode(double distanceToLeftChild, double distanceToRightChild, GuideTreeNode leftChild,
                      GuideTreeNode rightChild, string name = "")
 {
     this.distanceToLeftChild  = distanceToLeftChild;
     this.distanceToRightChild = distanceToRightChild;
     this.leftChild            = leftChild;
     this.rightChild           = rightChild;
     this.name = name;
 }
Esempio n. 2
0
        private double CalculateDistanceToLeafOfChild(GuideTreeNode childNode)
        {
            double result = 0;

            while (childNode.leftChild != null)
            {
                result   += childNode.distanceToLeftChild;
                childNode = childNode.leftChild;
            }
            return(result);
        }
Esempio n. 3
0
        public void JoinGroups(int indexOfFirstGroup, int indexOfSecondGroup, double distance)
        {
            double        distanceToLeaf   = distance / 2;
            GuideTreeNode newGuideTreeNode =
                new GuideTreeNode(distanceToLeaf - CalculateDistanceToLeafOfChild(groups[indexOfFirstGroup]),
                                  distanceToLeaf - CalculateDistanceToLeafOfChild(groups[indexOfSecondGroup]),
                                  groups[indexOfFirstGroup], groups[indexOfSecondGroup]);

            UpdateGroups(newGuideTreeNode, indexOfFirstGroup, indexOfSecondGroup);
            if (groups.Count == 1)
            {
                rootNode = groups[0];
            }
        }
Esempio n. 4
0
        private void UpdateGroups(GuideTreeNode newGuideTreeNode, int indexOfFirstGroup, int indexOfSecondGroup)
        {
            List <GuideTreeNode> newGroups = new List <GuideTreeNode>();

            for (int i = 0; i < groups.Count; i++)
            {
                if (i != indexOfFirstGroup && i != indexOfSecondGroup)
                {
                    newGroups.Add(groups[i]);
                }
                else if (i == indexOfSecondGroup)
                {
                    newGroups.Add(newGuideTreeNode);
                }
            }

            groups = newGroups;
        }
Esempio n. 5
0
        private void PrintSubtree(GuideTreeNode subtreeRoot, string indentation)
        {
            if (subtreeRoot == null)
            {
                Console.WriteLine();
            }
            else if (subtreeRoot.leftChild == null || subtreeRoot.rightChild == null)
            {
                Console.WriteLine(indentation + subtreeRoot.name);
            }
            else
            {
                string additionalIndentation = "\t";

                Console.WriteLine(indentation + Math.Round(subtreeRoot.distanceToLeftChild, 3) + " -> ");
                PrintSubtree(subtreeRoot.leftChild, indentation + additionalIndentation);
                Console.WriteLine(indentation + Math.Round(subtreeRoot.distanceToRightChild, 3) + " -> ");
                PrintSubtree(subtreeRoot.rightChild, indentation + additionalIndentation);
            }
        }