Esempio n. 1
0
        /// <summary>
        /// Подстановка данных из перебора и вычисление решения
        /// </summary>
        /// <param name="_n">Массив индексов решений из А2</param>
        /// <param name="f">Файл для записей логов</param>
        private void GetSolution(List <int> _n)
        {
            var tempA = CopyMatrix(_a);

            for (var j = 0; j < _countType; j++)
            {
                if (_n[j] >= 0)
                {
                    tempA[j] = CopyVector(SetTempAFromA2(j, _n[j])[j]);
                }
            }
            var shedule = new Shedule(tempA);

            shedule.ConstructShedule();
            var r    = shedule.RetyrnR();
            var sets = new Sets(Form1.compositionSets, Form1.timeSets);

            sets.GetSolution(r);
            var time = sets.GetNewCriterion(Form1.direct);
            var s    = PrintA(tempA);

            //f.Write(s + " - " + fBuf);
            //MessageBox.Show(s + " Время обработки " + fBuf);
            if (time < _f1Buf)
            {
                _abuf             = CopyMatrix(tempA);
                _typeSolutionFlag = true;
                _f1Buf            = time;
                //file.Write(" +");
            }
            //f.WriteLine();
        }
Esempio n. 2
0
        public int calcSetsFitnessList(bool directedTime, decimal GenerationCount, int countHromos = 50)
        {
            var flagmanHromosom = new List <List <int> >();


            for (var i = 0; i < _countType; i++)
            {
                flagmanHromosom.Add(new List <int> {
                    _n - 2, 2
                });
            }


            var        r           = ToArrayList();
            var        test        = new Sets(Form1.compositionSets, Form1.timeSets);
            var        FitnessList = new List <int>();
            List <int> CountTime   = new List <int>();

            for (int i = 0; i < GenerationCount + 1; i++)
            {
                this.SetXrom(countHromos);
                r = ToArrayList();
                r.Add(flagmanHromosom);
                foreach (var elem in r)
                {
                    var shedule = new Shedule(elem);
                    shedule.ConstructShedule();
                    test.GetSolution(shedule.RetyrnR());
                    CountTime.Add(test.GetNewCriterion(directedTime));
                }
            }

            return(CountTime.ToArray().Min());
        }
Esempio n. 3
0
        /// <summary>
        /// Алгоритм формирования решения по составам паритй всех типов данных
        /// </summary>
        public int[] GenetateSolutionForAllTypesSecondAlgorithm()
        {
            var sets   = new Sets(Form1.compositionSets, Form1.timeSets);
            var result = new[] { 0, 0 };

            //using (var f = new StreamWriter("standartOutData.txt", true))
            {
                GenerateStartSolution();
                var shedule = new Shedule(_a);
                shedule.ConstructShedule();
                var r = shedule.RetyrnR();
                sets.GetSolution(r);
                var time = sets.GetNewCriterion(Form1.direct);
                var _f1  = time;
                _f1Buf    = _f1;
                result[0] = _f1Buf;
                var maxA = CopyMatrix(_a);
                _typeSolutionFlag = true;
                if (!_staticSolution)
                {
                    while (CheckType(_i))
                    {
                        // Буферезируем текущее решение для построение нового на его основе
                        _ai = CopyMatrix(_a);
                        if (_typeSolutionFlag)
                        {
                            _a1 = new List <List <List <int> > >();
                            for (var i = 0; i < _countType; i++)
                            {
                                _a1.Add(new List <List <int> >());
                                _a1[i].Add(new List <int>());
                                _a1[i][0] = CopyVector(_a[i]);
                            }
                            _typeSolutionFlag = false;
                        }

                        var tempA = CopyMatrix(_ai);
                        _abuf  = CopyMatrix(_ai);
                        _f1Buf = _f1;

                        // Для каждого типа и каждого решения в типе строим новое решение и проверяем его на критерий
                        _a2 = new List <List <List <int> > >();
                        string s;
                        for (var i = 0; i < _countType; i++)
                        {
                            _a2.Add(new List <List <int> >());
                            if (_i[i] <= 0)
                            {
                                continue;
                            }
                            _a2[i] = NewData(i);
                            for (var j = 0; j < _a2[i].Count; j++)
                            {
                                tempA   = SetTempAFromA2(i, j);
                                shedule = new Shedule(tempA);
                                shedule.ConstructShedule();
                                r    = shedule.RetyrnR();
                                sets = new Sets(Form1.compositionSets, Form1.timeSets);
                                sets.GetSolution(r);
                                time = sets.GetNewCriterion(Form1.direct);
                                s    = PrintA(tempA);
                                //f.Write(s + " - " + time);
                                if (time < _f1Buf)
                                {
                                    _abuf             = CopyMatrix(tempA);
                                    _typeSolutionFlag = true;
                                    _f1Buf            = time;
                                }
                                //f.WriteLine();
                            }
                        }
                        if (!_typeSolutionFlag)
                        {
                            List <int> _n = new List <int>();
                            _nTemp = new List <int>();
                            for (int i = 0; i < _countType; i++)
                            {
                                _nTemp.Add(0);
                                _n.Add(_a2[i].Count);
                                if (_n[i] == 0)
                                {
                                    _n[i] = -1;
                                }
                            }
                            GenerateCombination(0, _nTemp);
                        }
                        if (_typeSolutionFlag)
                        {
                            _a  = CopyMatrix(_abuf);
                            _f1 = _f1Buf;
                        }
                        else
                        {
                            for (int i = 0; i < _countType; i++)
                            {
                                _a1[i] = CopyMatrix(_a2[i]);
                                if (!_a1[i].Any() || !_a1[i][0].Any())
                                {
                                    _i[i] = 0;
                                }
                            }
                        }
                        //f.WriteLine("------------------");
                    }
                }
                result[1] = _f1;
                //f.Close();
            }
            return(result);
        }