⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 EDA floorplanning 簡易小工具
💻 CS
📖 第 1 页 / 共 2 页
字号:

                    }
                }
            }
            for (int i = 0; i < Totalnode; i++)//calculate D
                D[i] = External[i] - Internal[i];

            //change

            Gxy[] gxy = new Gxy[Totalnode * Totalnode / 4];
            Gxy[] G = new Gxy[Totalnode / 2];
            int[] Label = new int[Totalnode];
            for (int i = 0; i < Totalnode; i++)//to compare which gxy is the largest
                Label[i] = 0;
            int key = 0, label_x = 0, label_y = 0;              //save the largest gxy , gxy.x , gxy.y           
            for (int n = 0; n < Totalnode / 2; n++)
            {
                int count = 0;  //to count how many gxy

                if (n == 0)                                        //first time change
                {

                    for (int i = 0; i < Totalnode / 2; i++)
                    {
                        if (Label[i] == 0)
                        {
                            for (int j = Totalnode / 2; j < Totalnode; j++)
                            {
                                if (Label[j] == 0)
                                {
                                    gxy[count].data = D[i] + D[j] - matrix2[i, j];
                                    gxy[count].x = i;
                                    gxy[count].y = j;
                                    count++;

                                }
                            }
                        }
                    }

                    key = gxy[0].data;
                    label_x = gxy[0].x;
                    label_y = gxy[0].y;
                    for (int k = 1; k < count; k++)
                    {
                        if (gxy[k].data > key)
                        {
                            key = gxy[k].data;
                            label_x = gxy[k].x;
                            label_y = gxy[k].y;
                        }
                    }
                    G[n].data = key;
                    G[n].x = label_x;
                    G[n].y = label_y;
                    Label[label_x] = 1;
                    Label[label_y] = 1;
                    //Console.WriteLine("x={0},y={1}", label_x, label_y);

                }
                else if (n > 0)             //the second to ( Totalnode/2th )  change          
                {
                    for (int i = 0; i < Totalnode; i++)
                    {
                        if (i < Totalnode / 2)
                        {
                            if (Label[i] == 0)
                                D[i] = D[i] + 2 * matrix2[i, label_x] - 2 * matrix2[i, label_y];
                        }
                        else
                        {
                            if (Label[i] == 0)
                                D[i] = D[i] + 2 * matrix2[i, label_y] - 2 * matrix2[i, label_x];
                        }
                    }
                    for (int i = 0; i < Totalnode / 2; i++)
                        if (Label[i] == 0)
                        {
                            for (int j = Totalnode / 2; j < Totalnode; j++)
                                if (Label[j] == 0)
                                {
                                    gxy[count].data = D[i] + D[j] - 2 * matrix2[i, j];
                                    gxy[count].x = i;
                                    gxy[count].y = j;
                                    count++;

                                }
                        }
                    key = gxy[0].data;
                    label_x = gxy[0].x;
                    label_y = gxy[0].y;
                    for (int k = 1; k < count; k++)
                    {
                        if (gxy[k].data > key)
                        {
                            key = gxy[k].data;
                            label_x = gxy[k].x;
                            label_y = gxy[k].y;
                        }
                    }
                    G[n].data = key;
                    G[n].x = label_x;
                    G[n].y = label_y;
                    Label[label_x] = 1;
                    Label[label_y] = 1;
                    //Console.WriteLine("x={0},y={1}", label_x, label_y);
                }
            }
            int gain = G[0].data;
            int temp = G[0].data;        //to save G[0]+G[1]+...G[n]
            int count_G = 0;             //to memorize when the temp is the largest 
            for (int i = 1; i < Totalnode / 2; i++)          //to compare 
            {
                temp += G[i].data;
                if (temp > gain)
                {
                    gain = temp;
                    count_G = i;
                }
            }
            // Console.WriteLine("gain = {0}",gain);
            // Console.WriteLine("sum of G0 + G1 +...+ Gn = {0}", temp);
            // Console.WriteLine("count_G = {0}", count_G);
            Group1 = new int[Totalnode / 2];
            Group2 = new int[Totalnode / 2];
            for (int i = 0; i < Totalnode / 2; i++)    //分組  group1 is 1 to Totalnode/2 , group2 is Totalnode/2+1 to Totalnode
            {
                Group1[i] = i + 1;      //because array begin from 0     
                Group2[i] = i + 1 + Totalnode / 2;
            }
            // to calculate the answer = the original E[] - the largest gain
            sum_of_E = 0;
            for (int i = 0; i < Totalnode / 2; i++)//to calculate the original sum of external weight
                sum_of_E += External[i];

            if ( gain > 0 )           
            {
                sum_of_E = sum_of_E - gain;

                for (int i = 0; i <= count_G; i++)
                {
                    Group1[G[i].x] = G[i].y + 1;
                    Group2[G[i].y - Totalnode / 2] = G[i].x + 1;
                }
            }
        }
        //end of algorithm

        private void output()                                      //output the result
        {
            textBox1.Text = Totalnode.ToString();
            textBox2.Text = sum_of_E.ToString();

            richTextBox1.Text = "";
            richTextBox2.Text = ""; 

            for (int i = 0; i < Totalnode; i++)                   //show Partition A
            {
                if (i < Totalnode / 2)
                {
                    richTextBox1.Text += Group1[i] + " ";
                }
            }
                  
            for (int i = 0; i < Totalnode; i++)                  //show Partition B
            {
                if (i >= Totalnode / 2)
                {
                    richTextBox2.Text += Group2[i - Totalnode / 2] + " ";
                }
            }

            memUsage = memory[0].PrivateMemorySize64;                        //get the memory usage for one time total program executing
            textBox3.Text = memUsage.ToString() + " bytes";
        }

        private void runtime()
        {
            DateTime tStart;
            DateTime tEnd;

            tStart = DateTime.Now;                       //timer start                
            for (int i = 0; i < 500; i++)
            {
                file_open();
                progressBar1.PerformStep();
            }
            tEnd = DateTime.Now;                        //timer end

            TimeSpan tDiff1 = tEnd - tStart;            //calculate the 500-loop time difference

            tStart = DateTime.Now;                      //timer start                
            for (int i = 0; i < 250; i++)
            {
                file_open();
                progressBar1.PerformStep();
            }
            tEnd = DateTime.Now;                        //timer end

            TimeSpan tDiff2 = tEnd - tStart;            //calculate the 250-loop time difference

            tTime = tDiff1 - tDiff2;           //in order to subtract the for-loop time

            double runTime = tTime.TotalSeconds / 250;    //the runtime per iteration
            textBox4.Text = runTime.ToString() + " sec.";

        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
            {
                progressBar1.Visible = true;
            }
            else
            {
                progressBar1.Visible = false;
            }

        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -