Example #1
0
        public void create_Optimal_of_One_Max_Tree(string file_Name, int num_Vertex)
        {
            Random   rnd       = new Random();
            Evaluate eva_class = new Evaluate();

            int[] prufer_Number = initialize_Prufer(num_Vertex, rnd);
            int[,] edge_Weight = eva_class.convert_Prufer_to_Tree(prufer_Number, num_Vertex);

            ReadWriteFile ioFile = new ReadWriteFile();

            ioFile.write_Optimal_of_One_Max_Tree(file_Name, num_Vertex, edge_Weight);
            ioFile.draw_Plot_in_Matlab(Path.GetFileNameWithoutExtension(file_Name) + @".m", num_Vertex, edge_Weight);
        }
Example #2
0
        /*********************************************************************************************************************************************
         *  G. R. Raidl and B. A. Julstrom, “Edge sets: an effective evolutionary coding of spanning trees,” IEEE Transactions on evolutionary computation, vol. 7, no. 3, pp. 225–239, 2003.
         *  Lai ghép cho biểu diễn cây sử dụng thuậ toán PrimRST để tạo cây
         *
         ********************************************************************************************************************************************/
        private double[,] primRST_Crossover(double[,] par1, double[,] par2, int num_Vertex, Random rnd)
        {
            double[,] G_cr = new double[num_Vertex, num_Vertex];
            int[,] aaa     = new int[num_Vertex, num_Vertex];
            Initialize_Chromosome init_Chrome = new Initialize_Chromosome();

            //01. Tao do thi Gcr
            for (int i = 0; i < num_Vertex; i++)
            {
                for (int j = 0; j < num_Vertex; j++)
                {
                    G_cr[i, j] = par1[i, j] + par2[i, j];
                }
            }


            ReadWriteFile ioFile = new ReadWriteFile();

            //for (int i = 0; i < num_Vertex; i++)
            //{
            //    for (int j = 0; j < num_Vertex; j++)
            //    {
            //        aaa[i, j] = (int)par1[i, j];
            //    }
            //}
            //ioFile.draw_Plot_in_Matlab("par_1" + @".m", num_Vertex, aaa);
            //for (int i = 0; i < num_Vertex; i++)
            //{
            //    for (int j = 0; j < num_Vertex; j++)
            //    {
            //        aaa[i, j] = (int)par2[i, j];
            //    }
            //}
            //ioFile.draw_Plot_in_Matlab("par_2" + @".m", num_Vertex, aaa);

            //for (int i = 0; i < num_Vertex; i++)
            //{
            //    for (int j = 0; j < num_Vertex; j++)
            //    {
            //        aaa[i, j] = (int)par1[i, j] + (int)par2[i, j];
            //    }
            //}
            //ioFile.draw_Plot_in_Matlab("aaa" + @".m", num_Vertex, aaa);

            //02. Ap dung PrimRST de tao ca the con
            double[,] aaaaa = init_Chrome.primRST(num_Vertex, G_cr, rnd);

            //if (aaaaa == null)
            //{
            //    //ReadWriteFile ioFile = new ReadWriteFile();
            //    ioFile.writeMatrixToFile("G_cr.txt", G_cr, num_Vertex, false);
            //    Console.WriteLine("null child");

            //    for (int i = 0; i < num_Vertex; i++)
            //    {
            //        for (int j = 0; j < num_Vertex; j++)
            //        {
            //            aaa[i, j] = (int)par1[i, j];
            //        }
            //    }
            //    ioFile.draw_Plot_in_Matlab("par_1" + @".m", num_Vertex, aaa);
            //    for (int i = 0; i < num_Vertex; i++)
            //    {
            //        for (int j = 0; j < num_Vertex; j++)
            //        {
            //            aaa[i, j] = (int)par2[i, j];
            //        }
            //    }
            //    ioFile.draw_Plot_in_Matlab("par_2" + @".m", num_Vertex, aaa);

            //    for (int i = 0; i < num_Vertex; i++)
            //    {
            //        for (int j = 0; j < num_Vertex; j++)
            //        {
            //            aaa[i, j] = (int)par1[i, j] + (int)par2[i, j];
            //        }
            //    }
            //    ioFile.draw_Plot_in_Matlab("aaa" + @".m", num_Vertex, aaa);
            //    Console.ReadKey();
            //}

            //for (int i = 0; i < num_Vertex; i++)
            //{
            //    for (int j = 0; j < num_Vertex; j++)
            //    {
            //        aaa[i, j] = (int)aaaaa[i, j];
            //    }
            //}
            //ioFile.draw_Plot_in_Matlab("child" + @".m", num_Vertex, aaa);

            return(aaaaa);
        }