private void createTree(ScoreNode root, DataGridView dataGridView1)
        {
            allocateTree(root, dataGridView1.Columns.Count - 2, 0);

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                rowToTree(root, row);
            }
        }
        private void allocateTree(ScoreNode root, int levelsNumber, int currentLevel)
        {
            if (levelsNumber > currentLevel)
            {
                root.setLeft(new ScoreNode(generatedNodes++));
                root.setRight(new ScoreNode(generatedNodes++));

                allocateTree(root.getLeft(), levelsNumber, currentLevel + 1);
                allocateTree(root.getRight(), levelsNumber, currentLevel + 1);
            }
        }
 private void createGraph(ScoreNode root)
 {
     System.Windows.Forms.Form form = new System.Windows.Forms.Form();
     Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer();
     Microsoft.Msagl.Drawing.Graph          graph  = new Microsoft.Msagl.Drawing.Graph(this.name);
     graph           = treeToGraph(root, graph);
     viewer.Graph    = graph;
     viewer.AutoSize = true;
     viewer.FitGraphBoundingBox();
     form.SuspendLayout();
     form.Controls.Add(viewer);
     form.ResumeLayout();
     form.ShowDialog();
 }
        private void buttonViewGraph_Click(object sender, EventArgs e)
        {
            ScoreNode root = new ScoreNode(generatedNodes++);

            //createTree(root, dataGridView1);
            //createGraph(root);
            //List<double> thresholds = new List<double>();
            //Tree.calculateThreshold(thresholds, dataGridView1);

            Tree.createTree(root, dataGridView1);
            createGraph(root);

            //foreach (double x in thresholds)
            //    Console.WriteLine(x);
        }
 private void rowToTree(ScoreNode node, DataGridViewRow row)
 {
     foreach (DataGridViewCell cell in row.Cells)
     {
         if (cell.Value.ToString() == "y")
         {
             node.setScore1(node.getScore1() + 1);
             node = node.getRight();
         }
         if (cell.Value.ToString() == "n")
         {
             node.setScore0(node.getScore0() + 1);
             node = node.getLeft();
         }
     }
 }
        private Graph treeToGraph(ScoreNode root, Graph graph)
        {
            if (root != null)
            {
                if (root.getLeft() != null)
                {
                    graph.AddEdge(root.getNodeText(), root.getLeft().getNodeText());
                    treeToGraph(root.getLeft(), graph);
                }

                if (root.getRight() != null)
                {
                    graph.AddEdge(root.getNodeText(), root.getRight().getNodeText());
                    treeToGraph(root.getRight(), graph);
                }
            }

            return(graph);
        }
 public void setRight(ScoreNode right)
 {
     this.right = right;
 }
 public void setLeft(ScoreNode left)
 {
     this.left = left;
 }
 public void addNode(ScoreNode n)
 {
 }
 public void setRoot(ScoreNode root)
 {
     this.root = root;
 }