Пример #1
0
        private void button4_Click(object sender, EventArgs e)
        {
            Form1.direct = checkBox2.Checked;
            int[] N_komplect_sostav = { 2, 4 };
            int[] n    = { 5, 10 };
            int[] l    = { 5, 10 };
            int[] time = { 2, 4, 8, 16, 32 };

            var file = "test/testFile_";
            var str  = "direct";

            if (!Form1.direct)
            {
                str = "first_task";
            }
            var n_kom   = Convert.ToInt32(textBox1.Text);
            var rand    = new Random((int)DateTime.Now.ToBinary());
            var temp    = 0;
            var n_kom_q = Convert.ToInt32(textBox2.Text);
            var fileOut = new StreamWriter(file + "All_" + str + "_" + n_kom + "_" + n_kom_q + "_new.txt", true);

            timeSets = new List <List <int> >();
            //foreach(var n_kom_q in N_komplect_for_type)
            {
                for (int i = 0; i < n_kom; i++)
                {
                    temp = rand.Next(10);
                    if (temp > 5)
                    {
                        temp = 150;
                    }
                    else
                    {
                        temp = 100;
                    }
                    timeSets.Add(new List <int>());
                    for (int j = 0; j < n_kom_q; j++)
                    {
                        timeSets[i].Add((j + 1) * temp);
                    }
                }
                foreach (var n_kom_s in N_komplect_sostav)
                {
                    foreach (var t in n)
                    {
                        _countType      = t;
                        compositionSets = new List <List <int> >();
                        for (int i = 0; i < n_kom; i++)
                        {
                            compositionSets.Add(new List <int>());
                            for (var ind = 0; ind < _countType; ind++)
                            {
                                temp = rand.Next(10);
                                if (temp > 5)
                                {
                                    compositionSets[i].Add(n_kom_s);
                                }
                                else
                                {
                                    compositionSets[i].Add(2);
                                }
                            }
                        }

                        foreach (var _countLine in l)
                        {
                            fileOut.WriteLine("Kq=" + n_kom_q);
                            fileOut.WriteLine("Kqs=" + n_kom_s);
                            fileOut.WriteLine("N=" + t + "L=" + _countLine);
                            fileOut.WriteLine("Times");
                            fileOut.WriteLine(printArray(timeSets));
                            fileOut.WriteLine("Compositions");
                            fileOut.WriteLine(printArray(compositionSets));
                            foreach (var t2 in time)
                            {
                                foreach (var t3 in time)
                                {
                                    _temptS = new List <List <List <int> > >();
                                    _temptT = new List <List <int> >();
                                    _l      = _countLine;
                                    _maxS   = t3;
                                    _maxT   = t2;
                                    RandomTime();
                                    PrintTime();
                                    GetTime();
                                    Shedule.L         = _countLine;
                                    Shedule.Switching = _temptS;
                                    Shedule.Treatment = _temptT;
                                    var listCountButches = new List <int>();
                                    for (var ii = 0; ii < _countType; ii++)
                                    {
                                        listCountButches.Add(0);
                                    }
                                    for (var ii = 0; ii < _countType; ii++)
                                    {
                                        _countBatches = 0;
                                        for (int i = 0; i < n_kom; i++)
                                        {
                                            _countBatches += compositionSets[i][ii];
                                        }
                                        listCountButches[ii] = _countBatches * n_kom_q;
                                    }
                                    var firstLevel = new FirstLevel(_countType, listCountButches, checkBox1.Checked);
                                    var result     = firstLevel.GenetateSolutionForAllTypesSecondAlgorithm();

                                    var gaa       = new GAA(_countType, listCountButches, checkBox1.Checked, _countBatches);
                                    var resultGaa = gaa.calcSetsFitnessList(checkBox2.Checked, GenerationCounter.Value, (int)numericUpDown2.Value);

                                    var first = result[0];
                                    var top   = result[1];
                                    fileOut.WriteLine(first + "\t" + top + "\t" + resultGaa);
                                }
                            }
                        }
                    }
                }
            }
            fileOut.Close();

            MessageBox.Show("Тестовый прогон завершен");
        }
Пример #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            int[] N_komplect_type     = { 2 };
            int[] N_komplect_for_type = { 2, 4 };
            int[] N_komplect_sostav   = { 2, 4 };
            int[] n    = { 5, 10 };
            int[] l    = { 5, 10 };
            int[] time = { 2, 4, 8, 16, 32 };
            using (var file = new StreamWriter("11 - " + checkBox2.Checked + ".txt", false))
            {
                foreach (var n_kom in N_komplect_type)
                {
                    compositionSets = new List <List <int> >();
                    timeSets        = new List <List <int> >();
                    foreach (var n_kom_q in N_komplect_for_type)
                    {
                        for (int i = 0; i < n_kom; i++)
                        {
                            var rand = new Random();
                            var temp = rand.Next(10);
                            if (temp > 5)
                            {
                                temp = 150;
                            }
                            else
                            {
                                temp = 100;
                            }
                            compositionSets.Add(new List <int>());
                            timeSets.Add(new List <int>());
                            for (int j = 0; j < n_kom_q; j++)
                            {
                                timeSets[i].Add((j + 1) * temp);
                            }
                        }
                        foreach (var n_kom_s in N_komplect_sostav)
                        {
                            foreach (var t in n)
                            {
                                _countType = t;
                                for (int i = 0; i < n_kom; i++)
                                {
                                    for (var ind = 0; ind < _countType; ind++)
                                    {
                                        var rand = new Random();
                                        var temp = rand.Next(10);
                                        if (temp > 5)
                                        {
                                            compositionSets[i].Add(n_kom_s);
                                        }
                                        else
                                        {
                                            compositionSets[i].Add(2);
                                        }
                                    }
                                }

                                foreach (var _countLine in l)
                                {
                                    file.WriteLine("Kn=" + n_kom);
                                    file.WriteLine("Kq=" + n_kom_q);
                                    file.WriteLine("Kqs=" + n_kom_s);
                                    file.WriteLine("N=" + t + "L=" + _countLine);
                                    foreach (var t2 in time)
                                    {
                                        foreach (var t3 in time)
                                        {
                                            _temptS = new List <List <List <int> > >();
                                            _temptT = new List <List <int> >();
                                            _l      = _countLine;
                                            _maxS   = t3;
                                            _maxT   = t2;
                                            RandomTime();
                                            PrintTime();
                                            GetTime();
                                            Shedule.L         = _countLine;
                                            Shedule.Switching = _temptS;
                                            Shedule.Treatment = _temptT;
                                            var listCountButches = new List <int>();
                                            for (var ii = 0; ii < _countType; ii++)
                                            {
                                                listCountButches.Add(0);
                                            }

                                            for (var ii = 0; ii < _countType; ii++)
                                            {
                                                _countBatches = 0;
                                                for (int i = 0; i < n_kom; i++)
                                                {
                                                    _countBatches += compositionSets[i][ii] * n_kom_q;
                                                }

                                                listCountButches[ii] = _countBatches;
                                            }

                                            var gaa = new GAA(_countType, listCountButches, checkBox1.Checked, _countBatches);


                                            var result = gaa.calcSetsFitnessList(checkBox2.Checked, GenerationCounter.Value, (int)numericUpDown2.Value);

                                            file.WriteLine(result);
                                        }
                                    }
                                    file.WriteLine();
                                }
                            }
                        }
                    }
                }
            }

            MessageBox.Show("Данные успешно записаны", "Учпешное завершение", MessageBoxButtons.OK);
        }