示例#1
0
        private void FindBestResult()
        {
            List <ChildOfPopulation> childOfPopulations = new List <ChildOfPopulation>();

            foreach (ChildOfPopulation elem in population)
            {
                childOfPopulations.Add(elem);
            }

            //сортируем по валидности
            childOfPopulations.Sort(delegate(ChildOfPopulation child1, ChildOfPopulation child2)
                                    { return(child2.Valid.CompareTo(child1.Valid)); });

            //берем самую валидную раскраску
            color_array = childOfPopulations[0].Color_Array;
            List <int> result_set = new List <int>();

            for (int i = 0; i <= count - 1; i++)
            {
                //количество цветов
                if (!result_set.Contains((color_array[i])))
                {
                    min_chromatic++;
                }
                result_set.Add(color_array[i]);
                MyPoint myPoint = list_of_points.GetPoint(i);
                myPoint.Draw(1, colors[color_array[i]]);
            }
        }
        public void RunExactSolution()
        {
            HashSet <int> result_set = new HashSet <int>();

            for (int i = 0; i <= count - 1; i++)
            {
                color_array[i] = 0;
            }

            for (int i = 0; i <= count - 1; i++)
            {
                result_set.Add(i);
                color_array[i] = ExactSolution(i, result_set);
                MyPoint myPoint = list_of_points.GetPoint(i);
                myPoint.Draw(1, colors[color_array[i]]);
            }
        }
示例#3
0
        private void pictureBoxGraph_MouseDown(object sender, MouseEventArgs e)
        {
            var location = e.Location;

            //Правая кнопка мыши - создание точки
            if (e.Button == MouseButtons.Right)
            {
                MyPoint myPointExact   = new MyPoint(location.X, location.Y, graphicsExact, radius);
                MyPoint myPointGenetic = new MyPoint(location.X, location.Y, graphicsGenetic, radius);
                if (!list_of_points_exact.Cross(myPointExact.GetX(), myPointExact.GetY()))
                {
                    myPointExact.Draw(0);
                    myPointGenetic.Draw(0);
                    list_of_points_exact.Add(myPointExact);
                    list_of_points_genetic.Add(myPointGenetic);

                    if (graph.Length > 0)
                    {
                        int count = list_of_points_exact.Count();
                        int[,] result = new int[count, count];
                        for (int i = 0; i < count - 1; i++)
                        {
                            for (int j = 0; j < count - 1; j++)
                            {
                                result[i, j] = graph[i, j];
                            }
                            result[i, count - 1] = 0;
                        }
                        graph = result;

                        int[] temp_result_exact = new int[count];
                        for (int i = 0; i < count - 2; i++)
                        {
                            temp_result_exact[i] = color_array_exact[i];
                        }
                        color_array_exact = temp_result_exact;

                        int[] temp_result_genetic = new int[count];
                        for (int i = 0; i < count - 2; i++)
                        {
                            temp_result_genetic[i] = color_array_genetic[i];
                        }
                        color_array_genetic = temp_result_genetic;
                    }
                    else
                    {
                        color_array_exact   = new int[1];
                        color_array_genetic = new int[1];
                        graph = new int[1, 1];
                    }
                }
                else
                {
                    int     i            = list_of_points_exact.IndexOfPoint(myPointExact.GetX(), myPointExact.GetY());
                    MyPoint temp         = list_of_points_exact.GetPoint(i);
                    MyPoint temp_genetic = list_of_points_genetic.GetPoint(i);
                    temp.SetChoose(false);
                    temp_genetic.SetChoose(false);
                    temp.Draw(0);
                    temp_genetic.Draw(0);
                }
            }
            //Левая кнопка мыши - выделение узла для установки связи
            if (e.Button == MouseButtons.Left)
            {
                if (list_of_points_exact.Cross(location.X, location.Y))
                {
                    int     i            = list_of_points_exact.IndexOfPoint(location.X, location.Y);
                    MyPoint temp         = list_of_points_exact.GetPoint(i);
                    MyPoint temp_genetic = list_of_points_genetic.GetPoint(i);
                    temp.SetChoose(true);
                    temp_genetic.SetChoose(true);
                    temp.Draw(0);
                    temp_genetic.Draw(0);
                    temp.Draw(2);
                    temp_genetic.Draw(2);
                    if (list_of_points_exact.Selected() == 2)
                    {
                        temp.Draw(0);
                        temp_genetic.Draw(0);
                        temp.SetChoose(false);
                        temp_genetic.SetChoose(false);
                        int     j                    = list_of_points_exact.GetChoosen();
                        MyPoint temp_point_2         = list_of_points_exact.GetPoint(j);
                        MyPoint temp_point_2_genetic = list_of_points_genetic.GetPoint(j);
                        temp_point_2.Draw(0);
                        temp_point_2_genetic.Draw(0);
                        temp_point_2.SetChoose(false);
                        temp_point_2_genetic.SetChoose(false);
                        Pen pen_line = new Pen(Color.Black, 2);
                        graphicsExact.DrawLine(pen_line, temp.GetX(), temp.GetY(), temp_point_2.GetX(), temp_point_2.GetY());
                        graphicsGenetic.DrawLine(pen_line, temp_genetic.GetX(), temp_genetic.GetY(), temp_point_2_genetic.GetX(), temp_point_2_genetic.GetY());
                        graph[i, j] = 1;
                        graph[j, i] = 1;
                    }
                }
            }
        }