示例#1
0
        private void button4_Click(object sender, EventArgs e)
        {
            //создание начальной популяции
            endreport        = false;
            button15.Enabled = true;
            Red[0]           = true;
            for (int i = 1; i < 10; i++)
            {
                Red[i] = false;
            }
            m     = 0;
            algst = new Algoritm();
            algst.Init(Ip, K, obl, z, klon, parkl, n, g, eps, sigma, percent);
            algst.FirstPop();
            flag = true;
            t    = 0;
            dataGridView1.Rows[0].Cells[1].Value = t;
            dataGridView1.Rows[1].Cells[1].Value = algst.Pop.Count;
            dataGridView1.Rows[2].Cells[1].Value = m;
            dataGridView1.Rows[3].Cells[1].Value = Math.Round(algst.AverF[t], 6);
            dataGridView1.Rows[5].Cells[1].Value = "(" + Math.Round(algst.Pop[0][0], 4).ToString() + "; " + Math.Round(algst.Pop[0][1], 4).ToString() + ")";
            dataGridView1.Rows[6].Cells[1].Value = Math.Round(algst.Pop[0][2], 6).ToString();
            dataGridView1.Rows[7].Cells[1].Value = exact.ToString();
            dataGridView1.Rows[8].Cells[1].Value = Math.Round(Math.Abs(exact - algst.Pop[0][2]), 6).ToString();
            numb++;
            if ((File.Exists("protocol.dt")))
            {
                Report prot = new Report();
                prot.Prot1(z, Ip, K, klon, parkl, g, algst.Pop, algst.oblast, numb, eps, sigma, percent);
                if ((File.Exists("protocol.dt")))
                {
                    FileStream   fs = new FileStream("protocol.dt", FileMode.Append, FileAccess.Write);
                    StreamWriter r1 = new StreamWriter(fs);
                    r1.Write(prot.toprotocol);
                    r1.Close();
                    fs.Close();
                }
            }

            pictureBox3.Refresh();
            pictureBox1.Refresh();
            pictureBox2.Refresh();
        }
示例#2
0
文件: Form1.cs 项目: Airvann/GWO
        private void button3_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex > -1)
            {
                int z = comboBox1.SelectedIndex;

                double[,] obl = new double[2, 2];

                int error = 0;

                try
                {
                    obl[0, 0] = Convert.ToDouble(dataGridView1.Rows[0].Cells[1].Value);
                    obl[0, 1] = Convert.ToDouble(dataGridView1.Rows[0].Cells[2].Value);
                    obl[1, 0] = Convert.ToDouble(dataGridView1.Rows[1].Cells[1].Value);
                    obl[1, 1] = Convert.ToDouble(dataGridView1.Rows[1].Cells[2].Value);
                }
                catch
                {
                    error = 1;
                }
                if ((obl[0, 1] - obl[0, 0] < 0) || (obl[1, 1] - obl[1, 0] < 0))
                {
                    error = 1;
                }

                int    Ip      = 0;
                int    K       = 0;
                int    Klon    = 0;
                double parkl   = 0;
                double g       = 0;
                double eps     = 0;
                double sigma   = 0;
                int    percent = 0;
                int    n       = 2;
                try
                {
                    Ip      = Convert.ToInt32(dataGridView2.Rows[0].Cells[1].Value);
                    K       = Convert.ToInt32(dataGridView2.Rows[1].Cells[1].Value);
                    Klon    = Convert.ToInt32(dataGridView2.Rows[2].Cells[1].Value);
                    parkl   = Convert.ToDouble(dataGridView2.Rows[3].Cells[1].Value);
                    g       = Convert.ToDouble(dataGridView2.Rows[4].Cells[1].Value);
                    eps     = Convert.ToDouble(dataGridView2.Rows[5].Cells[1].Value);
                    sigma   = Convert.ToDouble(dataGridView2.Rows[6].Cells[1].Value);
                    percent = Convert.ToInt16(dataGridView2.Rows[7].Cells[1].Value);
                }
                catch
                {
                    error = 2;
                }
                if ((Ip <= 0) || (K <= 0) || ((Klon != 1) && (Klon != 2)) ||
                    (parkl < 0) || (g <= 0) || (eps < 0) || (sigma <= 0) || (percent < 0))
                {
                    error = 2;
                }

                if (error == 0)
                {
                    flag2 = false;
                    if ((forma4.IsDisposed) || (first == true))
                    {
                        first  = false;
                        forma4 = new Form4();
                        alg    = new Algoritm();
                        alg.Init(Ip, K, obl, z, Klon, parkl, n, g, eps, sigma, percent);
                        forma4.algst   = alg;
                        forma4.showobl = showobl;
                        forma4.z       = comboBox1.SelectedIndex;
                        forma4.Ar      = Ar;
                        forma4.flines  = flines;
                        forma4.exact   = exact;
                        forma4.Ip      = Ip;
                        forma4.K       = K;
                        forma4.obl     = obl;
                        forma4.klon    = Klon;
                        forma4.parkl   = parkl;
                        forma4.n       = n;
                        forma4.eps     = eps;
                        forma4.sigma   = sigma;
                        forma4.g       = g;
                        forma4.percent = percent;
                        forma4.numb    = numb;

                        forma4.A           = A;
                        forma4.Ar          = Ar;
                        forma4.flines      = flines;
                        forma4.obl         = obl;
                        forma4.showobl     = showobl;
                        forma4.showoblbase = showoblbase;
                        forma4.Fname       = comboBox1.Items[comboBox1.SelectedIndex].ToString().Split('.')[1];
                        forma4.Show();
                    }
                }
                else
                {
                    switch (error)
                    {
                    case 1:
                        MessageBox.Show("Неверно введена область определения функции!");
                        break;

                    case 2:
                        MessageBox.Show("Неверно введены параметры алгоритма!");
                        break;
                    }
                }
            }
            else
            {
                MessageBox.Show("Выберите целевую функцию!");
            }
        }
示例#3
0
文件: Form1.cs 项目: Airvann/GWO
        private void button1_Click(object sender, EventArgs e)
        {
            //dataGridView2.Rows.Add();
            //создать начальную популяцию
            if (comboBox1.SelectedIndex != -1)
            {
                int z = comboBox1.SelectedIndex;

                double[,] obl = new double[2, 2];

                int error = 0;

                try
                {
                    obl[0, 0] = Convert.ToDouble(dataGridView1.Rows[0].Cells[1].Value);
                    obl[0, 1] = Convert.ToDouble(dataGridView1.Rows[0].Cells[2].Value);
                    obl[1, 0] = Convert.ToDouble(dataGridView1.Rows[1].Cells[1].Value);
                    obl[1, 1] = Convert.ToDouble(dataGridView1.Rows[1].Cells[2].Value);
                }
                catch
                {
                    error = 1;
                }
                if ((obl[0, 1] - obl[0, 0] < 0) || (obl[1, 1] - obl[1, 0] < 0))
                {
                    error = 1;
                }

                int    Ip      = 0;
                int    K       = 0;
                int    Klon    = 0;
                double parkl   = 0;
                double g       = 0;
                double eps     = 0;
                double sigma   = 0;
                int    percent = 0;
                int    n       = 2;
                try
                {
                    Ip      = Convert.ToInt32(dataGridView2.Rows[0].Cells[1].Value);
                    K       = Convert.ToInt32(dataGridView2.Rows[1].Cells[1].Value);
                    Klon    = Convert.ToInt32(dataGridView2.Rows[2].Cells[1].Value);
                    parkl   = Convert.ToDouble(dataGridView2.Rows[3].Cells[1].Value);
                    g       = Convert.ToDouble(dataGridView2.Rows[4].Cells[1].Value);
                    eps     = Convert.ToDouble(dataGridView2.Rows[5].Cells[1].Value);
                    sigma   = Convert.ToDouble(dataGridView2.Rows[6].Cells[1].Value);
                    percent = Convert.ToInt16(dataGridView2.Rows[7].Cells[1].Value);
                }
                catch
                {
                    error = 2;
                }
                if ((Ip <= 0) || (K <= 0) || ((Klon != 1) && (Klon != 2)) ||
                    (parkl < 0) || (g <= 0) || (eps < 0) || (sigma <= 0) || (percent < 0))
                {
                    error = 2;
                }

                if (error == 0)
                {
                    alg = new Algoritm();
                    alg.Init(Ip, K, obl, z, Klon, parkl, n, g, eps, sigma, percent);
                    alg.FirstPop();
                    numb++;
                    if ((File.Exists("protocol.dt")))
                    {
                        Report prot = new Report();
                        prot.Prot1(z, Ip, K, Klon, parkl, g, alg.Pop, alg.oblast, numb, eps, sigma, percent);
                        if ((File.Exists("protocol.dt")))
                        {
                            FileStream   fs = new FileStream("protocol.dt", FileMode.Append, FileAccess.Write);
                            StreamWriter r1 = new StreamWriter(fs);
                            r1.Write(prot.toprotocol);
                            r1.Close();
                            fs.Close();
                        }
                    }


                    alg.Work();

                    if ((File.Exists("protocol.dt")))
                    {
                        Report prot = new Report();
                        prot.Prot2(alg.Pop, alg.kpop, alg.LocalS, exact);

                        FileStream   fs = new FileStream("protocol.dt", FileMode.Append, FileAccess.Write);
                        StreamWriter r1 = new StreamWriter(fs);
                        r1.Write(prot.toprotocol);
                        r1.Close();
                        fs.Close();
                    }

                    dataGridView3.Rows[0].Cells[1].Value = alg.kpop.ToString();
                    dataGridView3.Rows[1].Cells[1].Value = alg.LocalS.ToString();
                    dataGridView3.Rows[2].Cells[1].Value = alg.Pop.Count.ToString();
                    dataGridView3.Rows[3].Cells[1].Value = alg.Mfend.ToString();
                    dataGridView3.Rows[4].Cells[1].Value = "(" + Math.Round(alg.Pop[0][0], 4).ToString() + "; " + Math.Round(alg.Pop[0][1], 4).ToString() + ")";
                    dataGridView3.Rows[5].Cells[1].Value = Math.Round(alg.Pop[0][2], 6).ToString();
                    dataGridView3.Rows[6].Cells[1].Value = exact.ToString();
                    dataGridView3.Rows[7].Cells[1].Value = Math.Round((exact - Math.Round(alg.Pop[0][2], 6)), 6).ToString();
                    flag2 = true;
                    pictureBox1.Refresh();
                    //textBox1.BackColor = Color.Green;
                    button8.Enabled = true;
                }
                else
                {
                    switch (error)
                    {
                    case 1:
                        MessageBox.Show("Неверно введена область определения функции!");
                        break;

                    case 2:
                        MessageBox.Show("Неверно введены параметры алгоритма!");
                        break;
                    }
                }
            }
            else
            {
                MessageBox.Show("Выберите целевую функцию!");
            }
        }