示例#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();
        }
示例#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());
        }
示例#3
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()));
            }
        }
示例#4
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();
        }
示例#5
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();
        }
示例#6
0
        public int[] calcGAFitnessList()
        {
            var        r              = ToArrayList();
            List <int> CountTime      = new List <int>();
            var        FitnessList    = new List <int>();
            var        GaaSecondLevel = new GaaSecondLevel();

            foreach (var elem in r)
            {
                var listint = new List <Shedule>();
                for (var i = 0; i < 50; i++)
                {
                    var shedule = new Shedule(GaaSecondLevel.GetGaaSecondLevelGroup(elem));
                    shedule.ConstructShedule();
                    listint.Add(shedule);
                }
                var timelist = listint.Select(list => list.GetTime());
                FitnessList.Add(timelist.Min());
            }
            _fitnesslist = FitnessList;
            return(CountTime.ToArray());
        }
示例#7
0
        public Form1()
        {
            InitializeComponent();
            InitializeForm();

            var test = new List <List <int> >();

            test.Add(new List <int>());
            test.Add(new List <int>()
            {
                2
            });
            test.Add(new List <int>()
            {
                10, 2
            });
            var t = new Shedule(test);
            //Shedule.L = 5;
            //t.GetTime();
            //var a = t.ReturnRIndex(0);
            //var b = t.ReturnRIndex(1);
        }
示例#8
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()]);
        }
示例#9
0
        public int[] calcFitnessList()
        {
            List <int> FitnessList = new List <int>();
            var        r           = this.ToArrayList();

            int[] ni   = { 8, 12, 16 /*, 24, 32 */ };
            int[] time = { 2, 4, 8, 16, 32 };
            int[] l    = { 5, 10 };
            int[] n    = { 5, 10 };
            int[,] compositionSetsForType =
            {
                { 2, 2, 0, 2, 2, 0, 0, 0, 0, 0 },
                { 2, 0, 2, 2, 2, 0, 0, 0, 0, 0 },
                { 0, 2, 2, 2, 2, 0, 0, 0, 0, 0 },
                { 2, 2, 2, 0, 2, 0, 0, 0, 0, 0 },
                { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0 }
            };

            var CompositionSets = new List <List <int> >();
            var TimeSets        = new List <List <int> >();

            TimeSets.Add(new List <int>());
            TimeSets[0].Add(65);
            TimeSets[0].Add(70);
            TimeSets.Add(new List <int>());
            TimeSets[1].Add(70);
            TimeSets[1].Add(75);
            TimeSets.Add(new List <int>());
            TimeSets[2].Add(65);
            TimeSets[2].Add(75);
            TimeSets.Add(new List <int>());
            TimeSets[3].Add(75);
            TimeSets[3].Add(80);
            TimeSets.Add(new List <int>());
            TimeSets[4].Add(70);
            TimeSets[4].Add(75);
            for (int i = 0; i < 5; i++)
            {
                CompositionSets.Add(new List <int>());
                for (int j = 0; j < 10; j++)
                {
                    CompositionSets[i].Add(compositionSetsForType[i, j]);
                }
            }

            var        test           = new Sets(CompositionSets, TimeSets);
            List <int> CountKit       = new List <int>();
            var        GaaSecondLevel = new GaaSecondLevel();

            foreach (var elem in r)
            {
                var listint = new List <Shedule>();
                for (var i = 0; i < 50; i++)
                {
                    var shedule = new Shedule(GaaSecondLevel.GetGaaSecondLevelGroup(elem));
                    shedule.ConstructShedule();
                    listint.Add(shedule);
                }
                var timelist = listint.Select(list => list.GetTime());
                FitnessList.Add(timelist.Min());
                test.GetSolution(listint[timelist.ToList().IndexOf(timelist.Min())].RetyrnR());
                CountKit.Add(test.GetCriterion());
            }
            _fitnesslist = FitnessList;
            return(CountKit.ToArray());
        }
示例#10
0
        public List <List <List <int> > > Algoritm_2()
        {
            int logi = 0;//номер группы текущий расматриваемый

            //A.Clear();

            /*for (int i = 0; i < 4; i++)
             * {
             *  List<int> w = new List<int>();
             *  A.Add(w);
             * }*/

            //A[0].Add(12); A[0].Add(2); A[0].Add(2);
            //A[1].Add(13); A[1].Add(3);
            //A[2].Add(10); A[2].Add(2); A[2].Add(2); A[2].Add(2);
            //A[3].Add(8); A[3].Add(2); A[3].Add(2); A[3].Add(2); A[3].Add(2);

            if (this.A[0].Count == 0)
            {
                A.RemoveAt(0);
                for (int i = 0; i < A.Count(); i++)
                {
                    A[i].RemoveAt(0);
                }
            }

            for (int i = 0; i < 4; i++)
            {
                groups.Nz1.Add(new List <List <int> >());
            }

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    groups.Nz1[i].Add(new List <int>());
                }
            }


            Q.Nz1.Add(new List <List <int> >());
            for (int i = 0; i < 4; i++)
            {
                Q.Nz1[0].Add(new List <int>());
            }

            for (int i = 0; i < A.Count(); i++)
            {
                for (int j = 0; j < A[i].Count(); j++)
                {
                    if (logi >= 4)
                    {
                        Q.Nz1[0][i].Add(A[i][j]);
                    }
                    else
                    {
                        groups.Nz1[logi][i].Add(A[i][j]);
                        this.shedule = new Shedule(this.BuildR(groups.Nz1[logi]), countL);
                        this.shedule.ConstructShedule();

                        if (this.shedule.GetTime() > Tz)
                        {
                            groups.Nz1[logi][i].RemoveAt(groups.Nz1[logi][i].Count - 1);
                            j--;
                            logi++;
                        }
                    }
                }
            }

            int sum = 0;

            for (int i = 0; i < Q.Nz1[0].Count; i++)
            {
                sum += Q.Nz1[0][i].Count;
            }
            if ((sum > 0) && c)
            {
                Algoritm_3();
            }

            return(groups.Nz1);//изменить
        }
示例#11
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);
        }
示例#12
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("Решения найдены");
            }
        }
示例#13
0
        public List <int> CalcFitnessList(List <List <int> > r, out int criteria, out int firstLevelCrit)
        {
            criteria       = 0;
            firstLevelCrit = 0;
            PartyList.Add(new List <List <int> > {
                new List <int>()
            });
            var countParty     = 0;
            var timeList       = new List <int>();
            var timeListResult = new List <int>();
            var time           = 0;

            foreach (var type in r)
            {
                if (countParty >= countGroup)
                {
                    break;
                }
                foreach (var party in type)
                {
                    PartyList[countParty][r.IndexOf(type)].Add(party);

                    time += new Shedule(PartyList[countParty]).GetTimeWithCriterium(Tz, out criteria);

                    timeList.Add(time);
                    if (time >= Tz)
                    {
                        timeList.RemoveAt(timeList.Count - 1);
                        if (timeList.Count == 0)
                        {
                            return(new List <int> {
                                0
                            });
                        }
                        timeListResult.Add(timeList.Last());
                        PartyList.Add(new List <List <int> >());
                        PartyList[countParty][r.IndexOf(type)].Remove(PartyList[countParty][r.IndexOf(type)].Last());
                        countParty++;

                        if (countParty >= countGroup)
                        {
                            break;
                        }
                        while (PartyList[countParty].Count <= r.IndexOf(type))
                        {
                            PartyList[countParty].Add(new List <int>());
                        }
                        PartyList[countParty][r.IndexOf(type)].Add(party);
                        time = 0;
                    }
                }
                PartyList[countParty].Add(new List <int>());
            }
            firstLevelCrit = PartyList.Take(countGroup).Select(list => list.Select(ints => ints.Sum()).Sum()).Sum();
            var critList = new List <int>();
            var resTime  = new List <int>();

            foreach (var group in  PartyList.Take(countGroup))
            {
                resTime.Add(new Shedule(group).GetTimeWithCriterium(Tz, out criteria));
                critList.Add(criteria);
            }

            criteria = Tz * countGroup - resTime.Sum();
            return(timeListResult);
        }
示例#14
0
        public List <int> CalcOptimalFitnessList(List <List <int> > r, out int criteria, out int firstLevelCrit)
        {
            criteria       = 0;
            firstLevelCrit = 0;

            r.ForEach(ints => ints.Reverse());

            PartyList.Add(new List <List <int> > {
                new List <int>()
            });
            var countParty     = 0;
            var timeList       = new List <int>();
            var timeListResult = new List <int>();
            var time           = 0;

            var canWrite = true;

            while (r.Any(ints => ints.Count != 0) && canWrite)
            {
                canWrite = false;
                var innerr = r.Select(ints => ints.Select(i => i).ToList()).ToList();

                foreach (var type in innerr)
                {
                    foreach (var party in type)
                    {
                        PartyList[countParty][innerr.IndexOf(type)].Add(party);
                        time += new Shedule(PartyList[countParty]).GetTimeWithCriterium(Tz, out criteria);

                        timeList.Add(time);
                        if (time >= Tz)
                        {
                            timeList.RemoveAt(timeList.Count - 1);
                            if (timeList.Count == 0)
                            {
                                time = 0;
                                continue;
                            }

                            PartyList[countParty][innerr.IndexOf(type)].RemoveAt(PartyList[countParty][innerr.IndexOf(type)].Count - 1);
                            while (PartyList[countParty].Count <= innerr.IndexOf(type))
                            {
                                PartyList[countParty].Add(new List <int>());
                            }

                            time = timeList.Last();
                        }
                        else
                        {
                            canWrite = true;
                            r[innerr.IndexOf(type)].Remove(party);
                        }
                    }

                    PartyList[countParty].Add(new List <int>());
                }

                PartyList.Add(new List <List <int> > {
                    new List <int>()
                });
                timeListResult.Add(time);
                time = 0;
                countParty++;
            }

            var a = timeListResult.Select(i => i).ToList();

            a.Sort();
            a.Reverse();

            var partyList = new List <List <List <int> > >();

            foreach (var timeInterval in a.Take(countGroup))
            {
                partyList.Add(PartyList[timeListResult.IndexOf(timeInterval)]);
            }

            var critList = new List <int>();
            var resTime  = new List <int>();

            timeListResult.Sort();
            timeListResult.Reverse();
            criteria = Tz * countGroup - timeListResult.Take(countGroup).Sum();


            firstLevelCrit = partyList.Select(list => list.Select(ints => ints.Sum()).Sum()).Sum();

            timeListResult.Sort();
            timeListResult.Reverse();
            return(timeListResult.Take(countGroup).ToList());
        }