Пример #1
0
 void kryptonTextBox1_TextChanged(object sender, EventArgs e)
 {
     try
     {
         double a = double.Parse(kryptonTextBox1.Text);
         double b = double.Parse(kryptonTextBox2.Text);
         kryptonTextBox3.Text = "" + FunctionVariabel.NumberFormat(getfunctionvalue(inp_fungsi.SelectedIndex, a, b));
     }
     catch
     {
         kryptonTextBox3.Text = "Ada penuliasn yang salah";
     }
 }
Пример #2
0
        private void kryptonButton1_Click(object sender, EventArgs e)
        {
            createGridPopulationMember();

            double[] hasil = new double[popmemberawal.GetLongLength(0)];

            for (int i = 0; i < popmemberawal.GetLongLength(0); i++)
            {
                hasil[i] = FunctionVariabel.goldsteinprice(popmemberawal[i, 0], popmemberawal[i, 1]);
            }

            MakeGrid.Build(grid1, (int)popmemberawal.GetLongLength(0), 1, MakeGrid.HeaderColumnsHeader.none);
            MakeGrid.Fill(grid1, hasil);
        }
Пример #3
0
        private double getfunctionvalue(int tipefungsi, double X, double Y)
        {
            switch (tipefungsi)
            {
            case 0:
                return(FunctionVariabel.goldsteinprice(X, Y));

            case 1:
                return(Andi.Fungsi.Bohachevsky.getValue(X, Y, Enums.BohaType.Boha1));

            case 2:
                return(Andi.Fungsi.Bohachevsky.getValue(X, Y, Enums.BohaType.Boha2));

            case 3:
                return(Andi.Fungsi.Bohachevsky.getValue(X, Y, Enums.BohaType.Boha3));

            case 4:
                return(FunctionVariabel.fourpeaks(X, Y));

            default:
                return(0);
            }
        }
Пример #4
0
        private void kryptonButton2_Click(object sender, EventArgs e)
        {
            #region inputan awal
            database.sql_con.Open();
            //object[] datadbiterasi = new object[7];

            int batastoleransiminimal = (int)kryptonNumericUpDown1.Value;
            int settoleransi          = 0;
            int batasinitial          = 0;

            switch (inp_fungsi.SelectedIndex)
            {
            case 0:
                batasinitial = 3;
                break;

            case 1:
            case 2:
            case 3:
                batasinitial = 0;
                break;

            default:
                batasinitial = 0;
                break;
            }

            kryptonButton2.Enabled = false;
            kryptonButton4.Enabled = true;
            kryptonButton5.Enabled = true;
            kryptonButton7.Enabled = false;

            FireflyVariabel.Alpha = double.Parse(inp_alpha.Text);
            FireflyVariabel.Beta  = double.Parse(inp_beta.Text); //beta0
            FireflyVariabel.Delta = double.Parse(inp_delta.Text);
            FireflyVariabel.Gamma = double.Parse(inp_gamma.Text);

            if (dbsave == 1)
            {
                object[] datadb = new object[8];
                datadb[0] = DateTime.Now.ToString();
                datadb[2] = cmb_stop.Text;
                datadb[4] = FireflyVariabel.Alpha.ToString();
                datadb[5] = FireflyVariabel.Beta.ToString();
                datadb[6] = FireflyVariabel.Gamma.ToString();
                datadb[7] = FireflyVariabel.Delta.ToString();

                datadb[1] = "";
                datadb[3] = 0;
                database.InsertKeterangan(datadb);
            }
            popmemberawal = MakeGrid.Return(grid_popmember);

            int value          = (int)val_stop.Value;
            int banyakpopulasi = (int)pop_member.Value;

            thismain.progress.Maximum = value;
            X = new double[banyakpopulasi];
            Y = new double[banyakpopulasi];

            int   tipeberhenti             = cmb_stop.SelectedIndex;
            int   tipefungsi               = inp_fungsi.SelectedIndex;
            bool  statusjeda               = kryptonCheckBox2.Checked;
            bool  statusupdatepopulasidata = kryptonCheckBox1.Checked;
            bool  statusplotpopulasi       = kryptonCheckBox3.Checked;
            int[] rank = new int[banyakpopulasi];
            #endregion

            #region Kebutuhan dalam Thread
            int i = 0, j = 0;

            _shutdownEvent = new ManualResetEvent(false);
            _pauseEvent    = new ManualResetEvent(true);

            DateTime dt = DateTime.Now;
            //TimeSpan ts = DateTime.Now - dt;
            #endregion

            #region Menghapus variable laporan dan membuat grid
            akhir.Clear();
            laporanpopupasi.Clear();
            MakeGrid.Build(grid1, banyakpopulasi, 4, MakeGrid.HeaderColumnsHeader.none);
            //MakeGrid.Build(grid2, 1, 4, MakeGrid.HeaderColumnsHeader.none);
            #endregion

            movedpopinput(banyakpopulasi); // memindahkan variabel

            threadsatu = new Thread(
                new ThreadStart(() =>
            {
                while (j < 4)
                {
                    #region 1. Input Fungsi Fitness
                    double[] zn = new double[banyakpopulasi];

                    for (int k = 0; k < banyakpopulasi; k++)
                    {
                        zn[k] = FunctionVariabel.NumberFormat(getfunctionvalue(tipefungsi, X[k], Y[k]));
                    }

                    rank = FireflyVariabel.RankingIndexList(zn);
                    I    = zn;
                    I    = FireflyVariabel.RankingValueList(zn);
                    #endregion

                    #region 2. ranking X Y dan duplikasi variabel
                    X = FireflyVariabel.SortingValueBy(X, rank);
                    Y = FireflyVariabel.SortingValueBy(Y, rank);

                    I0 = I; // duplikasi
                    X0 = X; // duplikasi
                    Y0 = Y; // duplikasi
                    #endregion

                    double r = 0, beta = 0;

                    #region 3. Movement
                    for (int u = 0; u < banyakpopulasi; u++)
                    {
                        for (int v = 0; v < banyakpopulasi; v++)
                        {
                            if (I[u] > I0[v])
                            {
                                r    = FireflyVariabel.Jarak(X[u], X0[v], Y[u], Y0[v]);
                                beta = FireflyVariabel.Beta1(FireflyVariabel.Beta, r, FireflyVariabel.Gamma);

                                /*xn(i)=xn(i).*(1-beta)+xo(j).*beta+alpha.*(rand-0.5);
                                *  yn(i)=yn(i).*(1-beta)+yo(j).*beta+alpha.*(rand-0.5);*/

                                X[u] = FireflyVariabel.Movement(X[u], X0[v], beta, FireflyVariabel.Alpha, rnd,
                                                                FunctionVariabel.Xmin, FunctionVariabel.Xmax);
                                //MessageBox.Show(r+" / "+beta.ToString());
                                Y[u] = FireflyVariabel.Movement(Y[u], Y0[v], beta, FireflyVariabel.Alpha, rnd,
                                                                FunctionVariabel.Ymin, FunctionVariabel.Ymax);
                            }
                        }
                    }

                    kryptonLabel12.BeginInvoke(new Action(() =>
                    {
                        kryptonLabel12.Text = "Min -> " + FunctionVariabel.NumberFormat(I0[0]) + " [" + FunctionVariabel.NumberFormat(X0[0]) + "," + FunctionVariabel.NumberFormat(Y0[0]) + "]";
                    }));

                    if (FunctionVariabel.NumberFormat(I0.Min()) <= batasinitial)
                    {
                        settoleransi += 1;
                    }
                    else
                    {
                        settoleransi = 0;
                    }

                    kryptonLabel13.BeginInvoke(new Action(() =>
                    {
                        kryptonLabel13.Text = settoleransi + "";
                    }));

                    X = FireflyVariabel.FindRange(X, FunctionVariabel.Xmin, FunctionVariabel.Xmax);
                    Y = FireflyVariabel.FindRange(Y, FunctionVariabel.Ymin, FunctionVariabel.Ymax);
                    #endregion

                    #region 4. Update Alpha
                    FireflyVariabel.Alpha = FireflyVariabel.Alpha * FireflyVariabel.Delta;
                    #endregion

                    #region A. Update Plot dan Grid


                    dataakhir data = new dataakhir();
                    data.Index     = (i + 1);
                    data.minimum   = I.Min();
                    data.maximum   = I.Max();
                    data.average   = I.Average();
                    akhir.Add(data);

                    grid1.BeginInvoke(new Action(() =>
                    {
                        if (statusupdatepopulasidata)
                        {
                            MakeGrid.Fill(grid1, rank, 0);
                            MakeGrid.Fill(grid1, X0, 1);
                            MakeGrid.Fill(grid1, Y0, 2);
                            MakeGrid.Fill(grid1, I0, 3);
                        }
                    }));

                    plot1.BeginInvoke(new Action(() =>
                    {
                        if (statusplotpopulasi)
                        {
                            setplot(plot1, X0, Y0);
                        }
                        else
                        {
                            plot1.Model = null;
                        }
                    }));
                    #endregion

                    #region B. pause state
                    _pauseEvent.WaitOne(Timeout.Infinite);
                    #endregion

                    #region C. update status bar
                    thismain.statusStrip1.BeginInvoke(new Action(() =>
                    {
                        try
                        {
                            if (tipeberhenti == 0)
                            {
                                thismain.progress.Value  = (i + 1);
                                thismain.statusbar1.Text = "Iterasi ke " + (i + 1) + " dengan jeda " + GlobalConfiguration.JedaThread + " milidetik";
                            }
                            else if (tipeberhenti == 1)
                            {
                                thismain.progress.Value  = ((int)(value - (DateTime.Now - dt).TotalSeconds));
                                thismain.statusbar1.Text = "Kurang " + ((int)(value - (DateTime.Now - dt).TotalSeconds)) + " detik lagi | Iterasi Ke : " + i + " dengan jeda " + GlobalConfiguration.JedaThread + " mili detik";
                            }
                            else
                            {
                                thismain.progress.Value  = ((int)(value - (DateTime.Now - dt).TotalMilliseconds));
                                thismain.statusbar1.Text = "Kurang " + ((int)(value - (DateTime.Now - dt).TotalMilliseconds)) + " milidetik lagi | Iterasi Ke : " + i + " dengan jeda " + GlobalConfiguration.JedaThread + " mili detik";
                            }
                        }
                        catch
                        {
                        }
                    }));
                    #endregion

                    #region D. kondisi berhenti
                    if (_shutdownEvent.WaitOne(0))
                    {
                        break;
                    }

                    if (settoleransi >= batastoleransiminimal)
                    {
                        break;
                    }

                    if (statusjeda)
                    {
                        Thread.Sleep(GlobalConfiguration.JedaThread);
                    }

                    if (tipeberhenti == 0)
                    {
                        if (i >= value - 1)
                        {
                            break;
                        }
                    }
                    else if (tipeberhenti == 1)
                    {
                        if ((DateTime.Now - dt).TotalSeconds >= value)
                        {
                            break;
                        }
                    }
                    else
                    {
                        if ((DateTime.Now - dt).TotalMilliseconds >= value)
                        {
                            break;
                        }
                    }
                    #endregion

                    i++;
                }

                if (dbsave == 1)
                {
                    database.UpdateKeterangan(DateTime.Now.ToString(), database.GetLastID(), "date_end");
                    database.UpdateKeterangan(i, database.GetLastID(), "iterasi_end");

                    for (int k = 0; k < akhir.Count; k++)
                    {
                        database.InsertAkhir(database.GetLastID(), k, akhir[k].minimum, X0[X0.Length - 1], Y0[Y0.Length - 1], akhir[k].maximum, akhir[k].average);
                    }
                }

                #region pesan penutup
                grid1.BeginInvoke(new Action(() =>
                {
                    if (kryptonCheckBox4.Checked)
                    {
                        MakeGrid.Fill(grid1, rank, 0);
                        MakeGrid.Fill(grid1, X, 1);
                        MakeGrid.Fill(grid1, Y, 2);
                        MakeGrid.Fill(grid1, I, 3);
                    }
                }));

                kryptonComboBox1.BeginInvoke(new Action(() =>
                {
                    kryptonComboBox1.SelectedIndex = 0;
                }));
                kryptonComboBox1.BeginInvoke(new Action(() =>
                {
                    kryptonComboBox2.SelectedIndex = 0;
                }));
                thismain.statusStrip1.BeginInvoke(new Action(() =>
                {
                    if (tipeberhenti == 0)
                    {
                        thismain.statusbar1.Text = "[selesai] berhenti di iterasi " + (i + 1) + " dengan waktu " + (DateTime.Now - dt).Duration().ToString().Substring(0, 8);
                    }
                }));

                kryptonButton2.BeginInvoke(new Action(() =>
                {
                    kryptonButton2.Enabled = true;
                }));

                kryptonButton4.BeginInvoke(new Action(() =>
                {
                    kryptonButton4.Enabled = false;
                }));

                kryptonButton5.BeginInvoke(new Action(() =>
                {
                    kryptonButton5.Enabled = false;
                }));

                kryptonButton7.BeginInvoke(new Action(() =>
                {
                    kryptonButton7.Enabled = false;
                }));

                navpagetab3.BeginInvoke(new Action(() =>
                {
                    navpagetab3.Enabled = true;
                }));
                database.sql_con.Close();
                #endregion
            }));

            threadsatu.Start();
        }