Esempio n. 1
0
        public void PlotIerarhicalVerticalDiagram(NTree myTree)
        {
            double max = myTree.distance;
            double min = 0;

            step1 = (max - min) / (height * myCoefficient);
            step2 = (double)(myTree.claster.GetObjects().Count) / width;

            int i = 0;

            PointF newPoint = recursivePlotting(myTree);

            foreach (var objects in myTree.claster.GetObjects())
            {
                Font       drawFont  = new Font("Arial", 10, FontStyle.Regular);
                SolidBrush drawBrush = new SolidBrush(Color.Blue);

                PointF drawPoint = new PointF((float)(0.5 / step2 + (i) / step2) - 5, (float)(height * myCoefficient));

                graphics.DrawString((allobjects.IndexOf(objects) + 1).ToString(), drawFont, drawBrush, drawPoint);

                i++;
            }

            pictureBox1.Image = bitmap;
        }
Esempio n. 2
0
        private void RedrawVertClasteriz(NTree mytree)
        {
            WriteNubersObj();

            foreach (var tree in mytree.trees)
            {
                if (tree.is_in_big_claster)
                {
                    graphics.DrawLine(pen, tree.topPoint.X, tree.topPoint.Y, tree.bottomPoint.X,
                                      tree.bottomPoint.Y);
                }


                if (mytree.trees.Count > 1 && mytree.trees[0].is_in_big_claster && mytree.is_in_big_claster)
                {
                    graphics.DrawLine(pen, mytree.trees[0].bottomPoint.X, mytree.trees[0].bottomPoint.Y, (mytree.trees[1].bottomPoint.X + mytree.trees[0].bottomPoint.X) / 2, mytree.trees[1].bottomPoint.Y);
                }
                if (mytree.trees.Count > 1 && mytree.trees[1].is_in_big_claster && mytree.is_in_big_claster)
                {
                    graphics.DrawLine(pen, (mytree.trees[1].bottomPoint.X + mytree.trees[0].bottomPoint.X) / 2, mytree.trees[0].bottomPoint.Y, mytree.trees[1].bottomPoint.X, mytree.trees[1].bottomPoint.Y);
                }
                if (mytree.trees.Count > 1 && mytree.trees[1].is_in_big_claster && mytree.trees[0].is_in_big_claster)
                {
                    graphics.DrawLine(pen, mytree.trees[0].bottomPoint.X, mytree.trees[0].bottomPoint.Y, mytree.trees[1].bottomPoint.X, mytree.trees[1].bottomPoint.Y);
                }


                RedrawVertClasteriz(tree);
            }
            pictureBox1.Image = bitmap;
        }
Esempio n. 3
0
        public List <Claster> GetMeClasters()
        {
            list_of_clasters = new List <Claster>();
            NTree searchingTree = this;

            return(list_of_clasters);
        }
Esempio n. 4
0
        public NTree GetTreeWhereExist(NTree my_tree, NTree tree) // ищем корень этого листа (дерево к котором это дерево - лист)
        {
            NTree res = null;

            foreach (var is_thisTree in my_tree.trees)
            {
                if (is_thisTree == tree)
                {
                    res = my_tree;
                }
                if (res == null)
                {
                    res = GetTreeWhereExist(is_thisTree, tree);
                }
            }

            return(res);
        }
Esempio n. 5
0
        public Claster GetNeighborhoods(MyObject obj)
        {
            NTree   searchingTree = this;
            Claster result        = null;

            while (searchingTree.claster.GetObjects().Count != 1)
            {
                foreach (var nTree in searchingTree.trees)
                {
                    if (nTree.claster.GetObjects().IndexOf(obj) >= 0)
                    {
                        result        = searchingTree.claster;
                        searchingTree = nTree;
                        break;
                    }
                }
            }
            return(result);
        }
Esempio n. 6
0
        public double GetDistanseInFirstClasterization(MyObject obj) // расстояние на котором объект вошел в кластер
        {
            NTree  searchingTree = this;
            double result        = 0;

            while (searchingTree.claster.GetObjects().Count != 1 && searchingTree.trees.Count != 0)
            {
                foreach (var nTree in searchingTree.trees)
                {
                    if (nTree.claster.GetObjects().IndexOf(obj) >= 0)
                    {
                        result        = searchingTree.distance;
                        searchingTree = nTree;
                        break;
                    }
                }
            }
            return(result);
        }
Esempio n. 7
0
        private void DelLineInTrassir(NTree mytree, PointF point) // удаление трассировкой(без учета коорд Х)
        {
            foreach (var tree in mytree.trees)
            {
                if (tree.bottomPoint.Y < point.Y && tree.topPoint.Y > point.Y)
                {
                    tree.is_in_big_claster = false;
                    list_of_claster.Add(tree.claster);
                    UpdateListOfClaster();
                }
                else
                {
                    DelLineInTrassir(tree, point);
                }

                if (!mytree.trees[1].is_in_big_claster && !mytree.trees[0].is_in_big_claster)
                {
                    mytree.is_in_big_claster = false;
                    list_of_claster.Remove(mytree.claster);
                }
            }
        }
Esempio n. 8
0
        private void DelLine(NTree mytree, PointF point)
        {
            foreach (var tree in mytree.trees)
            {
                if (tree.topPoint.X + 2 > point.X && tree.topPoint.X - 2 < point.X && tree.bottomPoint.Y < point.Y &&
                    tree.topPoint.Y > point.Y)
                {
                    tree.is_in_big_claster = false;
                    list_of_claster.Add(tree.claster);
                    UpdateListOfClaster();
                }
                else
                {
                    DelLine(tree, point);
                }

                if (!mytree.trees[1].is_in_big_claster && !mytree.trees[0].is_in_big_claster)
                {
                    mytree.is_in_big_claster = false;
                    list_of_claster.Remove(mytree.claster);
                }
            }
        }
Esempio n. 9
0
        public PointF recursivePlotting(NTree tree)
        {
            PointF res = new PointF(0, 0);

            foreach (var my_tree in tree.trees)
            {
                if (my_tree.trees.Count == 0 && my_tree.claster.GetObjects().Count > 1)
                {
                    double distanseForObject = myTree.GetDistanseInFirstClasterization(my_tree.claster.GetObjects()[0]);

                    // горизонтальная линия
                    graphics.DrawLine(pen,
                                      (float)(0.5 / step2 + (myTree.claster.GetObjects().IndexOf(my_tree.claster.GetObjects()[0])) / step2),
                                      (float)(height * myCoefficient),
                                      (float)(0.5 / step2 + ((myTree.claster.GetObjects().IndexOf(my_tree.claster.GetObjects()[my_tree.claster.GetObjects().Count - 1]))) / step2),
                                      (float)(height * myCoefficient));

                    float x = (float)(0.5 * ((myTree.claster.GetObjects().IndexOf(my_tree.claster.GetObjects()[0])) / step2 + (myTree.claster.GetObjects().IndexOf(my_tree.claster.GetObjects()[my_tree.claster.GetObjects().Count - 1])) / step2));

                    // вертикальная линия
                    graphics.DrawLine(pen,
                                      (float)(0.5 / step2 + x),
                                      (float)(height * myCoefficient),
                                      (float)(0.5 / step2 + x),
                                      (float)(height * myCoefficient - distanseForObject / step1));

                    // запоминаем точки вертик линии
                    my_tree.TakePoint(new PointF((float)(0.5 / step2 + x),
                                                 (float)(height * myCoefficient - distanseForObject / step1)),
                                      new PointF((float)(0.5 / step2 + x),
                                                 (float)(height * myCoefficient)));


                    if (res == new PointF(0, 0))
                    {
                        res.X = (float)(0.5 / step2 + x);
                        res.Y = (float)(height * myCoefficient - distanseForObject / step1);
                    }
                    else // соединяем два кластера
                    {
                        graphics.DrawLine(pen, res.X, res.Y,
                                          (float)(0.5 / step2 + x), (float)(height * myCoefficient - distanseForObject / step1));
                        res.X =
                            ((float)
                             ((0.5 / step2 + x) + res.X) / 2);
                        res.Y = (float)(height * myCoefficient - distanseForObject / step1);
                    }
                }
                else
                {
                    if (my_tree.claster.GetObjects().Count == 1)
                    {
                        double distanseForObject = myTree.GetDistanseInFirstClasterization(my_tree.claster.GetObjects()[0]);

                        graphics.DrawLine(pen,
                                          (float)(0.5 / step2 + (myTree.claster.GetObjects().IndexOf(my_tree.claster.GetObjects()[0])) / step2),
                                          (float)(height * myCoefficient),
                                          (float)(0.5 / step2 + ((myTree.claster.GetObjects().IndexOf(my_tree.claster.GetObjects()[0]))) / step2),
                                          (float)(height * myCoefficient - distanseForObject / step1));
                        // запоминаем точки вертик линии
                        my_tree.TakePoint(new PointF((float)(0.5 / step2 + ((myTree.claster.GetObjects().IndexOf(my_tree.claster.GetObjects()[0]))) / step2),
                                                     (float)(height * myCoefficient - distanseForObject / step1)),
                                          new PointF((float)(0.5 / step2 + (myTree.claster.GetObjects().IndexOf(my_tree.claster.GetObjects()[0])) / step2),
                                                     (float)(height * myCoefficient)));


                        if (res == new PointF(0, 0))
                        {
                            res.X = (float)(0.5 / step2 + ((myTree.claster.GetObjects().IndexOf(my_tree.claster.GetObjects()[0]))) / step2);
                            res.Y = (float)(height * myCoefficient - distanseForObject / step1);
                        }
                        else // соединяем два одиночных кластера
                        {
                            graphics.DrawLine(pen, res.X, res.Y,
                                              (float)
                                              (0.5 / step2 +
                                               ((myTree.claster.GetObjects().IndexOf(my_tree.claster.GetObjects()[0]))) /
                                               step2), (float)(height * myCoefficient - distanseForObject / step1));
                            res.X =
                                ((float)
                                 (0.5 / step2 +
                                  ((myTree.claster.GetObjects().IndexOf(my_tree.claster.GetObjects()[0]))) / step2) +
                                 res.X) / 2;
                            res.Y = (float)(height * myCoefficient - distanseForObject / step1);
                        }
                    }
                    else // в кластере не 1 объект
                    {
                        PointF midlepoint = recursivePlotting(my_tree);
                        if (res == new PointF(0, 0))
                        {
                            res = midlepoint;
                        }
                        else
                        {
                            double distanseForClaster = tree.distance;
                            //гориз линия
                            graphics.DrawLine(pen, res.X, (float)(height * myCoefficient - distanseForClaster / step1), midlepoint.X, (float)(height * myCoefficient - distanseForClaster / step1));

                            //2 верт линии левая и правая
                            graphics.DrawLine(pen, res.X, (float)(height * myCoefficient - distanseForClaster / step1), res.X, res.Y);
                            // запоминаем точки вертик линии
                            //    my_tree.trees[0].TakePoint(new PointF(res.X, (float)(height * myCoefficient - distanseForClaster / step1)), res);

                            graphics.DrawLine(pen, midlepoint.X, (float)(height * myCoefficient - distanseForClaster / step1), midlepoint.X, midlepoint.Y);
                            // запоминаем точки вертик линии
                            //     my_tree.trees[1].TakePoint(new PointF(midlepoint.X, (float)(height * myCoefficient - distanseForClaster / step1)), midlepoint);

                            NTree myUppertree = GetTreeWhereExist(myTree, my_tree); // дерево в котором это дерево - поддерево

                            // запоминаем точки вертик линии - если только не одиночный объект, потому что distanseForClaster=0
                            if (myUppertree.trees[0].claster.GetObjects().Count > 1 && myUppertree.trees[0].trees.Count > 0)
                            {
                                myUppertree.trees[0].TakePoint(new PointF(res.X, (float)(height * myCoefficient - distanseForClaster / step1)), res);
                            }
                            if (myUppertree.trees[1].claster.GetObjects().Count > 1 && myUppertree.trees[1].trees.Count > 0)
                            {
                                myUppertree.trees[1].TakePoint(new PointF(midlepoint.X, (float)(height * myCoefficient - distanseForClaster / step1)), midlepoint);
                            }



                            res.X = (res.X + midlepoint.X) / 2;
                            res.Y = (float)(height * myCoefficient - distanseForClaster / step1);
                        }
                    }
                }
            }
            return(res);
        }
Esempio n. 10
0
 public void TakeTree(NTree myNewTree)
 {
     myTree = myNewTree;
 }
Esempio n. 11
0
        public NTree Do_Ierarhical_Clasterization()
        {
            int counter;

            while (trees.Count > 1)
            {
                counter            = trees.Count;
                double[,] distance = new double[counter, counter];
                double minDist = double.MaxValue;  //!!!!!!!!!!!!!!!!!!!!!!!!! TODO error was here because int less than double
                int    tmp     = 0;

                for (int i = 0; i < counter; i++)
                {
                    for (int j = i + 1; j < counter; j++)
                    {
                        if (i != j)
                        {
                            //  MyObject obj1 = Claster.GetCenterOfMassInThisClaster(trees[i].claster.GetObjects());
                            //MyObject obj2 = Claster.GetCenterOfMassInThisClaster(trees[j].claster.GetObjects());
                            // distance[i, j] = Claster.GetDistanceFromObjectToCentroid(obj1, obj2);
                            if (trees[j].claster != null && trees[i].claster != null)
                            {
                                distance[i, j] = trees[j].claster.GetAverangeIntergroupDistanceBetweenClasters(
                                    trees[i].claster.GetObjects(), trees[j].claster.GetObjects()
                                    );
                            }
                            // теперь без самопересечений
                            if (minDist > distance[i, j])
                            {
                                minDist = distance[i, j];
                                tmp     = i;
                            }
                        }
                    }
                }

                Claster new_claster = null;
                NTree   new_tree    = null;
                int[]   nums        = new int[trees.Count]; // смотрим какие кластеры на этом шаге попали в объединение

                //  for (int k = 0; k < counter; k++)
                //  {
                int k = tmp;
                for (int j = k + 1; j < counter; j++)
                {
                    if (minDist == distance[k, j])
                    {
                        nums[k] = 1;
                        nums[j] = 1;
                        break;     // для бинарности добавления
                    }
                }
                //   }

                new_tree = new NTree(minDist, new_claster);
                for (int i = 0; i < counter; i++)
                {
                    if (nums[i] == 1)
                    {
                        new_claster = JoinClasters(new_claster, trees[i].claster);
                        new_tree.trees.Add(trees[i]);
                    }
                }
                /////
                if (new_claster == null)
                {
                    System.Windows.Forms.MessageBox.Show("axaxaxax!");
                }
                //////


                new_tree.claster = new_claster;
                for (int i = counter - 1; i >= 0; i--)
                {
                    if (nums[i] == 1)
                    {
                        trees.Remove(trees[i]);
                    }
                }
                if (new_tree != null && new_tree.claster != null) //на нуль проверку сделал
                {
                    trees.Add(new_tree);
                }

                ////
                foreach (var tree in trees)
                {
                    if (tree.claster == null)
                    {
                        System.Windows.Forms.MessageBox.Show("axaxaxax!");
                    }
                }
                /////
                this.distance = minDist;
            }
            return(this);
        }