Exemplo n.º 1
0
        //Ana fonksiyon = SolveProblem

        // Algoritma ile Problemi Çözme
        // İterasyon(Jenarasyon)  Sayısı Kadar İşlemleri Yapar
        public void SolveProblem()
        {
            if (TerminationType)
            {
                for (int i = 0; i < GenarationCount; i++)
                {
                    this.CreatePopulation();
                    this.PurposeFunction();
                    this.RouletteWheelMethod();
                    this.CrossOver();
                    this.Mutation();

                    // Populasyonun Hep Maximum seviyede olması için , belirlene seçkin adedi(ExclusivenessCount) kadar "ExclusivenessPersonList" listesine eklenir
                    // Bir sonraki jenerasyona aktarmak için
                    ExclusivenessPersonList.Clear(); // Eski Bireyleri Temizliyoruz
                    PersonList = PersonList.OrderByDescending(s => s.AccordanceValue).ToList();
                    ExclusivenessPersonList.AddRange(PersonList.Take(ExclusivenessCount));
                }
            }
            else
            {
                this.CreatePopulation();
                this.PurposeFunction();
                this.RouletteWheelMethod();
                this.CrossOver();
                this.Mutation();

                // Populasyonun Hep Maximum seviyede olması için , belirlene seçkin adedi(ExclusivenessCount) kadar "ExclusivenessPersonList" listesine eklenir
                // Bir sonraki jenerasyona aktarmak için
                ExclusivenessPersonList.Clear(); // Eski Bireyleri Temizliyoruz
                PersonList = PersonList.OrderByDescending(s => s.AccordanceValue).ToList();
                ExclusivenessPersonList.AddRange(PersonList.Take(ExclusivenessCount));
            }
        }
Exemplo n.º 2
0
        // Populasyon oluşturma => En büyük ve En küçük değerlere göre random bireyleri oluşturup "PersonList" Listesine ekler
        // İlk Jenarasyon ise "PopulationCount" kadar birey oluşturulur, ilk jenarasyon değil ise "PopulationCount" - "ExclusivenessCount" kadar birey oluşturulur ve
        // Populasyona seçkin bireyleri yani  "ExclusivenessPersonList" listesine ekleyerek "Elitizm" uygulanır
        private void CreatePopulation()
        {
            int Lenght = PopulationCount;

            PersonList.Clear();                                // Yeni Populasyon oluşturacağımız için eskiyi temizliyoruz

            if (ExclusivenessPersonList.Any())                 // Eğer ilk jenerasyon değil ise seçkin bireyleri , yeni populasyona ekliyoruz
            {
                Lenght = PopulationCount - ExclusivenessCount; // Seçkinleri eklediğimiz için , sayıyı azaltıyoruz
                PersonList.AddRange(ExclusivenessPersonList);
            }
            // Populasyonu Oluşturma
            for (int i = 0; i < Lenght; i++)
            {
                Person newPerson = new Person();
                newPerson.Value = rn.Next(MinValueForPerson, MaxValueForPerson); // Min-Max ' a göre random bir birey oluşturuldu

                PersonList.Add(newPerson);                                       // Bireyi populasyona Ekledik
            }
        }