public void Crossingover(AbstractTrack firstParent, AbstractTrack secondParent, AbstractTrack firstChild,
                                 AbstractTrack secondChild)
        {
            if (_index == _proxyCrossingoverList.Count)
            {
                _index = 0;
            }
            double currentResult = firstParent.GetTrackLength() < secondParent.GetTrackLength() ? firstParent.GetTrackLength() : secondParent.GetTrackLength();
            double oneProcentGain = (currentResult - _bestResult) / 100;

            DateTime startTime = DateTime.Now;
            _proxyCrossingoverList[_index].GetCrossingover().Crossingover(firstParent, secondParent, firstChild, secondChild);
            DateTime endTime = DateTime.Now;
            TimeSpan time = endTime - startTime;
            _proxyCrossingoverList[_index].AddOperationTime(time);

            double newResult = firstChild.GetTrackLength() < secondChild.GetTrackLength() ? firstChild.GetTrackLength() : secondChild.GetTrackLength();
            double procentGain;
            if (newResult < currentResult)
            {
                procentGain = 100 - (newResult - _bestResult) / oneProcentGain;
                _proxyCrossingoverList[_index].AddGoodStart();
            }
            else
            {
                procentGain = 0;
                _proxyCrossingoverList[_index].AddBadStart();
            }
            _proxyCrossingoverList[_index].IncreaseProgress(procentGain);
            _index++;
        }
        public void Mutation(AbstractTrack mutant)
        {
            if (_index == _proxyMutationList.Count)
            {
                _index = 0;
            }
            double currentResult = mutant.GetTrackLength();
            double oneProcentGain = (currentResult - _bestResult)/100;

            DateTime startTime = DateTime.Now;
            _proxyMutationList[_index].GetMutation().Mutation(mutant);
            DateTime endTime = DateTime.Now;
            TimeSpan time = endTime - startTime;
            _proxyMutationList[_index].AddOperationTime(time);

            double newResult = mutant.GetTrackLength();
            double procentGain;
            if (newResult < currentResult)
            {
                procentGain = 100 - (newResult - _bestResult) / oneProcentGain;
                _proxyMutationList[_index].AddGoodStart();
            }
            else
            {
                procentGain = 0;
                _proxyMutationList[_index].AddBadStart();
            }
            _proxyMutationList[_index].IncreaseProgress(procentGain);
            _index++;
        }
        public void Crossingover(AbstractTrack firstParent, AbstractTrack secondParent, AbstractTrack firstChild,
                                 AbstractTrack secondChild)
        {
            double sumOfProgress = _proxyCrossingoverList.Sum(proxyCrossingover => proxyCrossingover.GetProgress());
            double[] sectorsOfWheel = new double[_proxyCrossingoverList.Count];
            for (int i = 0; i < _proxyCrossingoverList.Count; i++)
            {
                sectorsOfWheel[i] = _proxyCrossingoverList[i].GetProgress() / sumOfProgress * 100; // формула для поиска размера сектров колеса рулетки
            }

            int fallenSector = _random.Next(100);
            double sum = 0;
            for (int j = 0; j < sectorsOfWheel.Length; j++)
            {
                sum += sectorsOfWheel[j];
                if (sum > fallenSector)
                {
                    double currentResult = firstParent.GetTrackLength() < secondParent.GetTrackLength() ? firstParent.GetTrackLength() : secondParent.GetTrackLength();
                    double oneProcentGain = currentResult / 100;

                    DateTime startTime = DateTime.Now;
                    _proxyCrossingoverList[j].GetCrossingover().Crossingover(firstParent, secondParent, firstChild, secondChild);
                    DateTime endTime = DateTime.Now;
                    TimeSpan time = endTime - startTime;
                    _proxyCrossingoverList[j].AddOperationTime(time);

                    double newResult = firstChild.GetTrackLength() < secondChild.GetTrackLength() ? firstChild.GetTrackLength() : secondChild.GetTrackLength();
                    double procentGain;
                    if (newResult < currentResult)
                    {
                        procentGain = 100 - (newResult / oneProcentGain);
                        _proxyCrossingoverList[j].AddGoodStart();
                    }
                    else
                    {
                        procentGain = 0;
                        _proxyCrossingoverList[j].AddBadStart();
                    }
                    _proxyCrossingoverList[j].IncreaseProgress(procentGain);
                    break;
                }
            }
        }
示例#4
0
 private void SaveTrack(AbstractTrack track)
 {
     DB_GeneticsDataSet.PersonsRow newPersonRow = _geneticsDataSet.Persons.NewPersonsRow();
     newPersonRow.Id = Guid.NewGuid();
     newPersonRow.Item = track.GetItem();
     newPersonRow.Track = track.ToString();
     newPersonRow.Length = track.GetTrackLength();
     newPersonRow.TypeOfCrossingover = track.TypeOfCrossingover;
     newPersonRow.TypeOfMutation = track.TypeOfMutation;
     newPersonRow.TypeOfSelection = track.TypeOfSelection;
     newPersonRow.NumberOfGeneration = _numberOfGenerations;
     newPersonRow.FirstParent = track.FirstParent;
     newPersonRow.SecondParent = track.SecondParent;
     newPersonRow.Launch = _launchId;
     newPersonRow.BestRip = track.GetBestRib().ToString();
     newPersonRow.WorstRip = track.GetWorstRib().ToString();
     newPersonRow.TypeOfTrack = track.GetTypeOfTrack();
     _geneticsDataSet.Persons.Rows.Add(newPersonRow);
     _personsTableAdapter.Update(newPersonRow);
     _geneticsDataSet.Persons.AcceptChanges();
 }