public void setTree(mSectionNode2 treeRoot)
 {
     root = treeRoot;
 }
        public int bestCombine(mSectionNode2 a, mSectionNode2 b)
        {
            int output = 0;

            for (int i = 0; i < chars.Length; i++){
                if (a.chars.Contains(chars[i]))
                {
                    output++;
                }
                if (b.chars.Contains(chars[i]))
                {
                    output--;
                }
            }

            if (a.ifStopHere == ifStopHere)
            {
                output++;
            }
            else if(b.ifStopHere == ifStopHere)
            {

            }

            return output;
        }
 public bool canComabine(mSectionNode2 other)
 {
     bool main = (this.parent == other.parent) && (this.SectionLetter.Equals(other.SectionLetter));
     bool rangesMatch = ((this.minValue >= other.minValue && this.maxValue <= other.maxValue)
         ||  (this.minValue <= other.minValue && this.maxValue >= other.maxValue));
     //bool matchingEndPoint = ifStopHere.Equals(other.ifStopHere) && ifStopHere.Length>0;
     bool aCharContainB = true;
     bool bCharContainA = true;
     for (int i = 0; i < other.chars.Length && aCharContainB; i++)
     {
         aCharContainB = chars.Contains(other.chars[i]);
     }
     for (int i = 0; i < chars.Length && bCharContainA; i++)
     {
         bCharContainA = other.chars.Contains(chars[i]);
     }
     bool validChars = aCharContainB || bCharContainA;
     bool validRoots = true;
     if (ifStopHere != ' ' && other.ifStopHere != ' ')
     {
         validRoots = ifStopHere == other.ifStopHere;
     }
     return main && (rangesMatch ||validChars) && validRoots;
 }
        public mSectionNode2(mSectionNode2 a, mSectionNode2 b)
        {
            this.parent = a.parent;
            this.SectionLetter = a.SectionLetter;
            if (a.minValue < b.minValue)
            {
                this.minValue = a.minValue;
            }
            else
            {
                this.minValue = b.minValue;
            }

            if (a.maxValue > b.maxValue)
            {
                this.maxValue = a.maxValue;
            }
            else
            {
                this.maxValue = b.maxValue;
            }

            chars = "";
            for (int i = 0; i < a.chars.Length; i++)
            {
                addChar(a.chars[i]);
            }
            for (int i = 0; i < b.chars.Length; i++)
            {
                addChar(b.chars[i]);
            }

            ifStopHere = ' ';
            addFinalChar(a.ifStopHere);
            addFinalChar(b.ifStopHere);

            children = new List<mSectionNode2>();
            for (int i = 0; i < a.children.Count; i++)
            {
                children.Add(a.children[i]);
            }
            for (int i = 0; i < b.children.Count; i++)
            {
                children.Add(b.children[i]);
            }
            for (int i = 0; i < children.Count; i++)
            {
                children[i].parent = this;
            }
        }
 public void addChild(mSectionNode2 child)
 {
     child.parent = this;
     children.Add(child);
 }
 public mSectionNode2(String letter, double value, char newChar , bool final)
 {
     parent = null;
     children = new List<mSectionNode2>();
     SectionLetter = letter;
     minValue = value;
     maxValue = value;
     chars = "";
     ifStopHere = ' ';
     if (final)
     {
         addFinalChar(newChar);
     }
     else
     {
         //addChar(newChar);
     }
 }
Example #7
0
 public void updateTree(mSectionNode2 treeRoot)
 {
     //Console.WriteLine(treeRoot.getString());
     myPenToText.setTree(treeRoot);
 }
Example #8
0
        public void dataUpdated()
        {
            root = new mSectionNode("", 0, "");
            root2 = new mSectionNode2("", 0, ' ', false);

            List<String> total = new List<String>();
            List<String> LetterNodeStrings = new List<String>();
            mSectionNode2[] roots = new mSectionNode2[alphabet.Length];
            for (int i = 0; i < alphabet.Length; i++)
            {
                pullData(alphabet[i]);
                roots[i] = new mSectionNode2("", 0, ' ', false);
                ((TextBlock)dataView[i].Children[0]).Text = alphabet[i] + ": " + elements.Count;
                LetterNodeStrings = new List<String>();
                for (int j = 0; j < elements.Count; j++)
                {
                    LetterNodeStrings.Add(new mLetterSections(minimumLines( cleanSections(Dominique(elements[j].cleanedData)))).getString(true, .01));
                }
                LetterNodeStrings = LetterNodeStrings.Distinct().ToList();

                for (int j = 0; j < LetterNodeStrings.Count; j++)
                {
                    addToThisTree(roots[i], LetterNodeStrings[j], alphabet[i]);
                    combineTree(roots[i]);
                }

                if (LetterNodeStrings.Count == 0)
                {
                    ((TextBlock)dataView[i].Children[2]).Text = "No Data";
                }
                else
                {
                    String thisText = roots[i].getString();
                    ((TextBlock)dataView[i].Children[2]).Text = thisText;
                }
            }
            for (int i = 0; i < roots.Length; i++)
            {
                root2 = new mSectionNode2(root2, roots[i]);
                combineTree(root2);
            }
                //combineTree();
            manager.updateTree(root2);
        }
Example #9
0
        public void combineTree(mSectionNode2 start)
        {
            Queue<mSectionNode2> frontier = new Queue<mSectionNode2>();
            frontier.Enqueue(start);

            while (frontier.Count > 0)
            {
                mSectionNode2 current = frontier.Dequeue();
                List<mSectionNode2> currentChildren = current.children;
                List<mSectionNode2> nextCildren = new List<mSectionNode2>();
                bool hasChanged = true;
                while (hasChanged)
                {
                    hasChanged = false;
                    int foundLoc = -1;
                    for (int i = 0; i < currentChildren.Count; i++)
                    {
                        bool foundMatch = false;
                        List<int> possibleLocs = new List<int>();
                        for (int j = 0; j < currentChildren.Count && !hasChanged; j++)
                        {
                            if (i != j && currentChildren[i].canComabine(currentChildren[j]))
                            {
                                //hasChanged = true;
                                foundMatch = true;
                                possibleLocs.Add(j);
                                //nextCildren.Add(new mSectionNode2(currentChildren[i], currentChildren[j]));
                            }
                        }
                        if (!foundMatch && i != foundLoc)
                        {
                            nextCildren.Add(currentChildren[i]);
                        }
                        else if(possibleLocs.Count > 0)
                        {
                            hasChanged = true;
                            int bestLoc = 0;
                            for (int j = 1; j < possibleLocs.Count; j++)
                            {
                                //compare values
                                if (currentChildren[i].bestCombine(currentChildren[possibleLocs[bestLoc]], currentChildren[possibleLocs[j]]) < 0)
                                {
                                    bestLoc = j;
                                }
                            }
                            foundLoc = possibleLocs[bestLoc];
                            nextCildren.Add(new mSectionNode2(currentChildren[i], currentChildren[possibleLocs[bestLoc]]));
                        }
                    }
                    /*for (int i = 1; i < currentChildren.Count; i++)
                    {
                        if (currentChildren[i - 1].canComabine(currentChildren[i]))
                        {
                            hasChanged = true;
                            nextCildren.Add(new mSectionNode2(currentChildren[i - 1], currentChildren[i]));
                            i++;
                        }
                    }*/
                    currentChildren = new List<mSectionNode2>(nextCildren);
                    nextCildren = new List<mSectionNode2>();
                }

                current.children = currentChildren;

                for (int i = 0; i < current.children.Count; i++)
                {
                    frontier.Enqueue(current.children[i]);
                }
            }
        }
Example #10
0
        public void addToTree2(String newInfo, char associatedLetter)
        {
            int chunkAt = 0;
            int chunkLength = 6;
            mSectionNode2 current = root2;
            while (newInfo.Length >= (chunkAt + 1) * chunkLength)
            {
                string chunk = newInfo.Substring(chunkAt * chunkLength, chunkLength);
                string sectionString;
                double value = 0.0;
                if (chunk.Equals("Line00"))
                {
                    sectionString = chunk;
                }
                else
                {
                    sectionString = chunk.Substring(0, 1);
                    value = Double.Parse(chunk.Substring(1));
                }

                bool final = (newInfo.Length < (chunkAt + 2) * chunkLength);
                mSectionNode2 next = new mSectionNode2(sectionString, value, associatedLetter, final);

                current.addChild(next);
                current = next;
                chunkAt++;
            }
        }