コード例 #1
0
        private void startButton_Click(object sender, EventArgs e)
        {
            double a         = Convert.ToDouble(aBox.Text);
            double b         = Convert.ToDouble(bBox.Text);
            double d         = Convert.ToDouble(dBox.Text);
            double tau       = Convert.ToDouble(tauBox.Text);
            int    T         = Convert.ToInt32(Tbox.Text);
            Random generator = new Random();
            int    round     = 0;
            int    l         = (int)Math.Ceiling(Math.Log(((b - a) * (1 / d)) + 1, 2));

            double pom = d;

            while (pom < 1)
            {
                round++;
                pom *= 10;
            }

            List <Individual> individuals = null;
            List <Individual> ListVb      = new List <Individual>();
            List <Individual> ListVbest   = new List <Individual>();
            Individual        Vbest;

            Individual individual = Geo.MakeFirstInd(a, b, d, l, generator);

            Vbest = individual.Clone();
            ListVb.Add(individual.Clone());
            ListVbest.Add(Vbest.Clone());
            for (int i = 1; i < T; i++)
            {
                individuals = Geo.MakePopulation(individual, a, b, l, round);

                Geo.CountProbability(individuals, tau);

                Geo.MutateInd(individual, individuals, a, b, l, round, generator);

                if (Vbest.Fx < individual.Fx)
                {
                    Vbest = individual.Clone();
                }

                ListVbest.Add(Vbest.Clone());
                ListVb.Add(individual.Clone());
                individuals.Clear();
            }

            individuals.Add(Vbest);
            var bindingList = new BindingList <Individual>(individuals);
            var source      = new BindingSource(bindingList, null);

            table.DataSource = source;

            ToTxt.WriteToFile(ListVb, T, tau, d);
            MakeChart(ListVb, ListVbest);
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: sccamati/HillClimbing
        private void startBtn_Click(object sender, EventArgs e)
        {
            double a         = Convert.ToDouble(aBox.Text);
            double b         = Convert.ToDouble(bBox.Text);
            double d         = Convert.ToDouble(dBox.Text);
            int    T         = Convert.ToInt32(Tbox.Text);
            Random generator = new Random();
            int    round     = 0;
            int    l         = (int)Math.Ceiling(Math.Log(((b - a) * (1 / d)) + 1, 2));

            double pom = d;

            while (pom < 1)
            {
                round++;
                pom *= 10;
            }
            List <Individual>         individuals  = new List <Individual>();
            List <List <Individual> > ListofListVc = new List <List <Individual> >();
            List <Individual>         ListVcBest   = new List <Individual>();
            Individual        Vc;
            Individual        VBest = null;
            Individual        Vn;
            List <Individual> listVc;

            for (int i = 0; i < T; i++)
            {
                listVc = new List <Individual>();
                Vc     = HC.MakeFirstInd(a, b, d, l, generator);
                listVc.Add(Vc.Clone());
                if (i == 0)
                {
                    VBest = Vc.Clone();
                }
                while (true)
                {
                    Vn = HC.MakeVn(Vc, a, b, l, round);
                    if (Vn.Fx > Vc.Fx)
                    {
                        Vc = Vn.Clone();
                        listVc.Add(Vc.Clone());
                    }
                    else
                    {
                        break;
                    }
                }
                ListofListVc.Add(listVc);
                if (VBest.Fx < Vc.Fx)
                {
                    VBest = Vc.Clone();
                }
                ListVcBest.Add(VBest.Clone());
                if (VBest.Xreal == 10.999)
                {
                    break;
                }
            }
            individuals.Add(VBest);
            var bindingList = new BindingList <Individual>(individuals);
            var source      = new BindingSource(bindingList, null);

            table.DataSource = source;
            ToTxt.WriteToFile(ListofListVc, T, d);
            MakeChart(ListofListVc, ListVcBest);
        }