Beispiel #1
0
        public Claster JoinClasters(Claster cl1, Claster cl2)
        {
            List <MyObject> l1 = new List <MyObject>();

            if (cl1 != null)
            {
                l1 = cl1.GetObjects();
            }
            List <MyObject> l2 = cl2.GetObjects();

            List <MyObject> l3 = new List <MyObject>();

            if (cl1 != null)
            {
                foreach (var myObject in l1)
                {
                    l3.Add(myObject);
                }
            }
            foreach (var myObject in l2)
            {
                l3.Add(myObject);
            }
            return(new Claster(l3));
        }
Beispiel #2
0
        public void RunForel(int numOfClaster, int firstElement, Claster myClaster, double radius)
        {
            double[]         radInProection = myClaster.GetDiametrInProection(numRow, numCol); // две удаленные точки и диаметр .. всего 3 элемента в массиве
            List <ArrayList> listOfPoints   = controller.GetListOfClasterPoints();
            ArrayList        arrayList      = listOfPoints[numOfClaster];

            //две выделенные точки
            int point1 = int.Parse(arrayList[(int)radInProection[0]].ToString());
            int point2 = int.Parse(arrayList[(int)radInProection[1]].ToString());
            //


            ////////////////////////////////////////////////////////// painting
            int count = params1.Count;


            double max1 = double.Parse(params1[0].ToString());
            double min1 = double.Parse(params1[0].ToString());

            double max2 = double.Parse(params2[0].ToString());
            double min2 = double.Parse(params2[0].ToString());

            for (int i = 0; i <= count - 1; i++)   // ищем максимумы и минимумы
            {
                if (double.Parse(params1[i].ToString()) > max1)
                {
                    max1 = double.Parse(params1[i].ToString());
                }
                if (double.Parse(params1[i].ToString()) < min1)
                {
                    min1 = double.Parse(params1[i].ToString());
                }

                if (double.Parse(params2[i].ToString()) > max2)
                {
                    max2 = double.Parse(params2[i].ToString());
                }
                if (double.Parse(params2[i].ToString()) < min2)
                {
                    min2 = double.Parse(params2[i].ToString());
                }
            }

            var step1       = ((max1 - min1) / (width * 0.7));
            var step1ForRad = ((width * 0.7) * (double.Parse(params1[point1].ToString()) - min1) / (max1 - min1));
            var step2       = ((max2 - min2) / (height * 0.7));
            var step2ForRad = ((height * 0.7) * (double.Parse(params2[point2].ToString()) - min2) / (max2 - min2));

            //////////////////////////////////////////////////////////////// painting

            List <MyObject> objects = myClaster.GetObjects();

            int countObj = objects.Count;
            int countAtr = objects[0].attrib.Count;

            double[,] vectX = new double[countObj, countAtr];

            for (int i = 0; i < countObj; i++)
            {
                for (int j = 0; j < countAtr; j++)
                {
                    vectX[i, j] = double.Parse(objects[i].attrib[j].ToString());
                }
            }

            double[] xCenter = new double[countAtr];  //  заполняем начальный центр масс.

            for (int j = 0; j < countAtr; j++)
            {
                xCenter[j] = vectX[firstElement, j];
            }

            Boolean flagForCycle = true;

            ArrayList ObjInSphere = new ArrayList();

            for (int i = 0; i < countObj; i++)
            {
                ObjInSphere.Add(i);
            }

            int m = 0; //  tmp counter

            ///////////////////.............

            while (flagForCycle)
            {
                int   num          = ObjInSphere.Count;
                int[] numOfObjects = new int[num];

                ObjInSphere.CopyTo(numOfObjects);

                ObjInSphere.Clear();

                double[] ArrayX = new double[countAtr];  // какой то объект
                int      myCountObjectsInSphere = 0;

                for (int i = 0; i < num; i++)
                {
                    for (int j = 0; j < countAtr; j++)
                    {
                        ArrayX[j] = vectX[i, j];  ////////////////////
                    }

                    double length = myClaster.GetRo(ArrayX, xCenter);

                    if (length <= radius / 2)
                    {
                        myCountObjectsInSphere++;
                        ObjInSphere.Add(i);
                    }
                }

                double[] xNewCenter = new double[countAtr];  // новый центр масс.

                foreach (var nums in ObjInSphere)
                {
                    m = Int32.Parse(nums.ToString());
                    for (int j = 0; j < countAtr; j++)
                    {
                        xNewCenter[j] += vectX[m, j] / ObjInSphere.Count;
                    }
                }

                graph.Clear(Color.White);
                RedrawMe();
                graph.FillEllipse(Brushes.LightPink, (float)(width * 0.05 + (xNewCenter[numRow] - min1) / step1), (float)(height * 0.9 - (xNewCenter[numCol] - min2) / step2), 9, 9);

                graph.DrawEllipse(Pens.LightSkyBlue, (float)(width * 0.05 - step1ForRad / 2 + (xNewCenter[numRow] - min1) / step1), (float)(height * 0.9 - step2ForRad / 2 - (xNewCenter[numCol] - min2) / step2), (float)(step1ForRad), (float)(step2ForRad));


                // отмечаем новый цм
                // рисуем круг радиусом соответствующим

                bool flag = false;
                for (int i = 0; i < countAtr; i++)
                {
                    if (xNewCenter[i] != xCenter[i])
                    {
                        flag = true;
                    }
                }
                flagForCycle = flag;

                if (flagForCycle)
                {
                    xCenter = xNewCenter;
                }
            }

            string res = null;

            for (int i = 0; i < ObjInSphere.Count; i++)
            {
                res += ObjInSphere[i].ToString() + "\n";
            }
            MessageBox.Show(res);
        }