Esempio n. 1
0
        public void Algoritm_1()
        {
            int buff, buff2;

            for (int i = 0; i < groups.Nz1.Count; i++)
            {
                for (int j = 0; j < groups.Nz1[i].Count; j++)
                {
                    for (int k = 0; k < groups.Nz1[i][j].Count; k++)
                    {
                        for (int l = 0; l < Q.Nz1[0].Count; l++)
                        {
                            for (int t = 0; t < Q.Nz1[0][l].Count; t++)
                            {
                                this.shedule = new Shedule(this.BuildR(groups.Nz1[i]), countL);
                                this.shedule.ConstructShedule();
                                buff2 = shedule.GetTime();
                                buff  = groups.Nz1[i][j][k];
                                groups.Nz1[i][l][k] = Q.Nz1[0][l][t];
                                this.shedule        = new Shedule(this.BuildR(groups.Nz1[i]), countL);
                                this.shedule.ConstructShedule();
                                if (shedule.GetTime() > buff2)
                                {
                                    groups.Nz1[i][j][k] = buff;
                                }
                            }
                        }
                    }
                }
            }
            Algoritm_3();
        }
Esempio n. 2
0
        public void Algoritm_3()
        {
            int buff = 0;

            for (int k = 0; k < groups.Nz1.Count(); k++)
            {
                for (int i = 0; i < Q.Nz1[0].Count(); i++)
                {
                    for (int j = 0; j < Q.Nz1[0][i].Count(); j++)
                    {
                        groups.Nz1[k][i].Add(Q.Nz1[0][i][j]);

                        this.shedule = new Shedule(this.BuildR(groups.Nz1[k]), countL);
                        this.shedule.ConstructShedule();
                        if (shedule.GetTime() > Tz)
                        {
                            groups.Nz1[k][i].RemoveAt(groups.Nz1[k][i].Count - 1);
                        }
                        else
                        {
                            Q.Nz1[0][i].RemoveAt(j);
                        }
                    }
                }
            }
            for (int k = 0; k < groups.Nz1.Count(); k++)
            {
                this.shedule = new Shedule(this.BuildR(groups.Nz1[k]), countL);
                this.shedule.ConstructShedule();

                Prostoi[k] = Tz - shedule.GetTime();

                //MessageBox.Show(Convert.ToString(Tz - shedule.GetTime()));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Подстановка данных из перебора и вычисление решения
        /// </summary>
        /// <param name="_n">Массив индексов решений из А2</param>
        /// <param name="f">Файл для записей логов</param>
        private void GetSolution(List <int> _n, StreamWriter f)
        {
            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 fBuf = shedule.GetTime();
            var s    = PrintA(tempA);

            //f.Write(s + " - " + fBuf);
            //MessageBox.Show(s + " Время обработки " + fBuf);
            if (fBuf < _f1Buf)
            {
                _abuf             = CopyMatrix(tempA);
                _typeSolutionFlag = true;
                _f1Buf            = fBuf;
                //file.Write(" +");
            }
            //f.WriteLine();
        }
Esempio n. 4
0
        public List <List <int> > calcFitnessList()
        {
            var r           = ToArrayList();
            var FitnessList = new List <int>();
            var tuple       = new Dictionary <int, List <List <int> > >();
            var listint     = new List <int>();

            foreach (var elem in r)
            {
                var shedule = new Shedule(elem);

                var time = shedule.GetTime();

                if (tuple.ContainsKey(time))
                {
                    continue;
                }
                tuple.Add(time, elem);
                listint.Add(time);
            }

            return(tuple[listint.Min()]);
        }
Esempio n. 5
0
        /// <summary>
        /// Алгоритм формирования решения по составам паритй всех типов данных
        /// </summary>
        public void GenetateSolutionForAllTypes(string fileName)
        {
            using (var file = new StreamWriter(fileName))
            {
                GenerateStartSolution();
                var shedule = new Shedule(_a);
                shedule.ConstructShedule();
                _f1 = shedule.GetTime();
                //MessageBox.Show(PrintA(A) + " Время обработки " + f1);
                _f1Buf = _f1;
                file.WriteLine(_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;
                        //file.WriteLine("окрестность 1 вида");
                        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();
                                var fBuf = shedule.GetTime();
                                s = PrintA(tempA);
                                //file.Write(s + " " + fBuf);
                                //MessageBox.Show(s + " Время обработки " + fBuf);
                                if (fBuf < _f1Buf)
                                {
                                    _abuf             = CopyMatrix(tempA);
                                    _typeSolutionFlag = true;
                                    _f1Buf            = fBuf;
                                    //file.Write(" +");
                                }
                                //file.WriteLine();
                            }
                        }
                        if (!_typeSolutionFlag)
                        {
                            //file.WriteLine("комбинации типов");
                            for (var i = 0; i < _countType - 1; i++)
                            {
                                if (_i[i] <= 0)
                                {
                                    continue;
                                }
                                for (var j = i + 1; j < _countType; j++)
                                {
                                    if (_i[j] <= 0)
                                    {
                                        continue;
                                    }
                                    _a2[i] = NewData(i);
                                    _a2[j] = NewData(j);
                                    for (var ii = 0; ii < _a2[i].Count; ii++)
                                    {
                                        for (var jj = 0; jj < _a2[j].Count; jj++)
                                        {
                                            {
                                                tempA               = SetTempAFromA2(i, ii);
                                                tempA[j]            = CopyVector(SetTempAFromA2(j, jj)[j]);
                                                !!!!!!!!!!!!shedule = new Shedule(tempA);
                                                shedule.ConstructShedule();
                                                var fBuf = shedule.GetTime();
                                                s = PrintA(tempA);
                                                //file.Write(s + " " + fBuf);
                                                //MessageBox.Show(s + " Время обработки " + fBuf);
                                                if (fBuf < _f1Buf)
                                                {
                                                    _abuf             = CopyMatrix(tempA);
                                                    _typeSolutionFlag = true;
                                                    _f1Buf            = fBuf;
                                                    //file.Write(" +");
                                                }
                                                //file.WriteLine();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (_typeSolutionFlag)
                        {
                            //MessageBox.Show("Лучшее решение "+PrintA(Abuf) + " Время обработки " + f1Buf);
                            _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;
                                }
                            }
                        }
                    }
                }
                file.WriteLine(_f1);
                file.Close();
                //MessageBox.Show("Решения найдены");
            }
        }