Exemple #1
0
        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);
        }
Exemple #2
0
        private void startTestBtn_Click(object sender, EventArgs e)
        {
            double a         = Convert.ToDouble(aBox.Text);
            double b         = Convert.ToDouble(bBox.Text);
            double d         = Convert.ToDouble(dBox.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 <List <Individual> > ListofListVc = new List <List <Individual> >();
            List <Individual>         ListVcBest   = new List <Individual>();
            Individual        Vc;
            Individual        VBest = null;
            Individual        Vn;
            List <Individual> listVc;
            List <Generation> listGen = new List <Generation>();

            for (int i = 0; i < 3000; i++)
            {
                Generation generation = new Generation
                {
                    Iteration = i + 1
                };
                listGen.Add(generation);
            }
            for (int j = 0; j < 10000; j++)
            {
                for (int i = 0; i < 3000; 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)
                    {
                        listGen[i].SolveCount += 1;
                        break;
                    }
                }
            }

            for (int i = 1; i < listGen.Count; i++)
            {
                listGen[i].Cumulation += listGen[i - 1].SolveCount + listGen[i - 1].Cumulation;
            }

            MakeTestChart(listGen);
            var bindingList = new BindingList <Generation>(listGen);
            var source      = new BindingSource(bindingList, null);

            testTable.DataSource = source;
        }