Esempio n. 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            Shedule.L         = _l;
            Shedule.Switching = _temptS;
            Shedule.Treatment = _temptT;
            _countType        = (int)numericUpDown1.Value;
            _countBatches     = Convert.ToInt32(countBatchesTB.Text);
            var listCountButches = new List <int>();

            for (var ii = 0; ii < _countType; ii++)
            {
                listCountButches.Add(_countBatches);
            }
            var gaa = new GAA(_countType, listCountButches, checkBox1.Checked);

            gaa.SetXrom((int)numericUpDown2.Value);
            gaa.calcFitnessList();
            int s;
            var result = gaa.getSelectionPopulation(_selectionType, out s);

            using (var file = new StreamWriter("outputGAA.txt", true))
            {
                int i = 0;
                foreach (var elem in gaa.nabor)
                {
                    foreach (var elem2 in elem.GenList)
                    {
                        foreach (var elem3 in elem2)
                        {
                            file.Write(elem3 + " ");
                        }
                        file.WriteLine();
                    }
                    file.WriteLine("_________________________");
                    file.WriteLine(gaa._fitnesslist[i]);
                    file.WriteLine("_________________________");
                    i++;
                }
                file.WriteLine("***************************");
                file.WriteLine(result);
                file.WriteLine("***************************");
            }
            MessageBox.Show("Данные успешно записаны", "Учпешное завершение", MessageBoxButtons.OK);
        }
Esempio n. 2
0
        private void button5_Click(object sender, EventArgs e)
        {
            var massi = new[] { 8, 12, 16, 24, 32 };

            foreach (var intt in massi)
            {
                countBatchesTB.Text = intt.ToString();
                for (int z = 5; z <= 10; z += 5)
                {
                    numericUpDown1.Text = z.ToString();
                    for (int z1 = 5; z1 <= 10; z1 += 5)
                    {
                        LTB.Text = z1.ToString();
                        using (var file = new StreamWriter("outputGAASimpleResult.txt", true))
                        {
                            file.WriteLine("________________(CB = " + intt + ")");
                            file.WriteLine();
                            file.WriteLine("________________(L = " + LTB.Text + ")(N=" + numericUpDown1.Value + ")_____");
                        }
                        for (int p = 2; p <= 32; p *= 2)
                        {
                            timeTreatmentingTB.Text = Convert.ToString(p);
                            for (int i = 2; i <= 32; i *= 2)
                            {
                                timeSwitchingTB.Text = Convert.ToString(i);

                                Shedule.L         = _l;
                                Shedule.Switching = _temptS;
                                Shedule.Treatment = _temptT;
                                _countType        = (int)numericUpDown1.Value;
                                _countBatches     = Convert.ToInt32(countBatchesTB.Text);
                                var listCountButches = new List <int>();
                                for (var ii = 0; ii < _countType; ii++)
                                {
                                    listCountButches.Add(_countBatches);
                                }
                                var gaa = new GAA(_countType, listCountButches, checkBox1.Checked);
                                gaa.SetXrom((int)numericUpDown2.Value);
                                var countSourceKit = gaa.calcFitnessList();
                                int s;
                                var result = gaa.getSelectionPopulation(_selectionType, out s);

                                using (var file = new StreamWriter("outputGAA.txt", true))
                                {
                                    int k = 0;
                                    foreach (var elem in gaa.nabor)
                                    {
                                        foreach (var elem2 in elem.GenList)
                                        {
                                            foreach (var elem3 in elem2)
                                            {
                                                file.Write(elem3 + " ");
                                            }
                                            file.WriteLine();
                                        }
                                        file.WriteLine("_________________________");
                                        file.WriteLine(gaa._fitnesslist[i]);
                                        file.WriteLine("+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=");
                                        file.WriteLine("Kit" + countSourceKit[i]);
                                        file.WriteLine("+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=");
                                        file.WriteLine("_________________________");
                                        k++;
                                    }

                                    file.WriteLine("***************************");
                                    file.WriteLine(result);
                                    file.WriteLine("***************************");
                                }
                                using (var file = new StreamWriter("outputGAASimpleResult.txt", true))
                                {
                                    file.WriteLine(result);
                                }
                            }
                            using (var file = new StreamWriter("outputGAASimpleResult.txt", true))
                            {
                                file.WriteLine("_____________________");
                            }
                        }
                    }
                }
            }
            MessageBox.Show("Данные успешно записаны", "Учпешное завершение", MessageBoxButtons.OK);
        }
Esempio n. 3
0
        private void OldSecondLevelAll_Click(object sender, EventArgs e)
        {
            var massi = new[] { 2, 4, 8, 16, 32 };

            using (var file = new StreamWriter("Га, оптимизации групп " + OptimizationSecondLevel.Checked + " N=" + numericUpDown1.Value + "L=" + LTB.Text + ".txt", false))
            {
                foreach (var intt in massi)
                {
                    timeSwitchingTB.Text = intt.ToString();
                    foreach (var item in massi)
                    {
                        for (var tz = 50; tz <= 200; tz = tz + 50)
                        {
                            for (var countGroup = 2; countGroup <= 8; countGroup += 2)
                            {
                                timeTreatmentingTB.Text = item.ToString();
                                _countType    = (int)numericUpDown1.Value;
                                _countBatches = Convert.ToInt32(countBatchesTB.Text);
                                var listCountButches = new List <int>();
                                for (var ii = 0; ii < _countType; ii++)
                                {
                                    listCountButches.Add(_countBatches);
                                }

                                _l    = Convert.ToInt32(LTB.Text);
                                _maxS = Convert.ToInt32(timeSwitchingTB.Text);
                                _maxT = Convert.ToInt32(timeTreatmentingTB.Text);
                                GetTime();
                                Shedule.L         = _l;
                                Shedule.Switching = _temptS;
                                Shedule.Treatment = _temptT;

                                var gaa = new GAA(_countType, listCountButches, checkBox1.Checked, _countBatches);
                                gaa.SetXrom((int)numericUpDown2.Value);
                                var sostav = gaa.calcFitnessList();

                                //var firstLevel = new FirstLevel(_countType, listCountButches, checkBox1.Checked);
                                //firstLevel.GenetateSolutionForAllTypes("outputFirstAlgorithm.txt");
                                var oldSecondLevel = new OldSecondLevel(tz, countGroup, _l);

                                int criteria;
                                int flCrit;
                                var listInt = !OptimizationSecondLevel.Checked
                                    ? oldSecondLevel.CalcFitnessList(sostav, out criteria, out flCrit)
                                    : oldSecondLevel.CalcOptimalFitnessList(sostav, out criteria, out flCrit);
                                var stringTime = listInt.Select(i => i.ToString());
                                var join       = string.Join(" ", stringTime);
                                file.WriteLine("Tz = " + tz.ToString() + Environment.NewLine +
                                               "Tp = " + intt + Environment.NewLine +
                                               "Z = " + countGroup + Environment.NewLine +
                                               "Crit = " + criteria + Environment.NewLine +
                                               "fLCrit = " + flCrit + Environment.NewLine +
                                               "To = " + item + Environment.NewLine +
                                               listInt.Sum().ToString() + join + Environment.NewLine + Environment.NewLine);
                            }
                        }
                    }
                }
            }
            MessageBox.Show(@"Решения найдены");
        }
Esempio n. 4
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("Тестовый прогон завершен");
        }
Esempio n. 5
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);
        }