private void BuildTreeView(SharpCluster.Clusters clusters)
        {
            treeView1.Nodes.Clear();
            TreeNode rootNode = treeView1.Nodes.Add("Cluster" + clusters.GetClusters()[0].Id.ToString());

            this.AddNodes(clusters.GetClusters()[0].GetSubClusters(), rootNode);
            treeView1.ExpandAll();
        }
        private void btnExecuteClustering_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            btnExecuteClustering.Enabled = false;
            lines.Clear(); // limpa as linhas
            HashSet <double[]> _dataSet;

            if (txtFilePath.Text.Length > 0)
            {
                if (dataSet == null)
                {
                    _dataSet = this.GenerateDataSet(txtFilePath.Text);
                }
                else
                {
                    _dataSet = dataSet;
                }

                DateTime start = DateTime.Now;
                lblStartTime.Text = start.ToString();

                SharpCluster.Agnes    agnes    = new SharpCluster.Agnes(_dataSet, hasClass);
                SharpCluster.Clusters clusters = agnes.ExecuteClustering((cboStrategy.SelectedItem as ComboboxItem).Value, 1);

                DateTime end = DateTime.Now;
                lblFinishTime.Text = end.ToString();

                TimeSpan span = end - start;
                lblTimeElapsed.Text = span.TotalSeconds.ToString();

                this.BuildTreeView(clusters);
                this.FillTextBox(clusters.GetClusters());

                hierarchicalClusters = clusters;
            }
            else
            {
                MessageBox.Show("Go to Preprocess and select a file!", "Data set file not found");
            }

            btnExecuteClustering.Enabled = true;
        }
        private void btnStartAgnes_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            HashSet <double[]> _dataSet;

            if (txtFilePath.Text.Length > 0)
            {
                if (txtAgnesNumberOfGroups.Text.Trim().Length > 0 && Convert.ToInt32(txtAgnesNumberOfGroups.Text) > 0)
                {
                    if (Convert.ToInt32(txtAgnesNumberOfGroups.Text) > 1)
                    {
                        if (dataSet == null)
                        {
                            _dataSet = this.GenerateDataSet(txtFilePath.Text);
                        }
                        else
                        {
                            _dataSet = dataSet;
                        }


                        SharpCluster.Agnes    agnes    = new SharpCluster.Agnes(_dataSet, hasClass);
                        SharpCluster.Clusters clusters = agnes.ExecuteClustering((cboAgnesStrategy.SelectedItem as ComboboxItem).Value, Convert.ToInt32(txtAgnesNumberOfGroups.Text));

                        //Converte clusters (hierarquico) para clusters (particional) como o k-means, para utilizar Dunn e Davies-Bouldin
                        SharpCluster.Cluster[] flatClusters = agnes.BuildFlatClustersFromHierarchicalClustering(clusters, clusters.GetClusters().Count());

                        ShowAgnesChart(flatClusters);
                        agnesClusters = flatClusters;
                    }
                    else
                    {
                        MessageBox.Show("Number of cluster must be more than 1.");
                    }
                }
                else
                {
                    MessageBox.Show("Enter a number o clusters.");
                }
            }
            else
            {
                MessageBox.Show("Go to Preprocess and select a file!", "Data set file not found");
            }
        }