コード例 #1
0
ファイル: Population.cs プロジェクト: Oriik/FirstAlgoGen
        public Population(int _populationSize, int _bodySize)
        {
            random         = new Random();
            people         = new List <Individu>();
            populationSize = _populationSize;
            bodySize       = _bodySize;

            for (int i = 0; i < populationSize; i++)
            {
                Individu temp = new Individu(bodySize);
                temp.FirstGeneration();
                people.Add(temp);
            }
        }
コード例 #2
0
ファイル: Population.cs プロジェクト: Oriik/FirstAlgoGen
        internal void Selection()
        {
            List <Individu> bestPeople = new List <Individu>();

            foreach (Individu i in people)
            {
                bestPeople.Add(i);
                if (bestPeople.Count > populationSize / 2)
                {
                    Individu worst = bestPeople.Min();
                    bestPeople.Remove(worst);
                }
            }
            people = bestPeople;
        }
コード例 #3
0
ファイル: Population.cs プロジェクト: Oriik/FirstAlgoGen
        internal void Hybridation()
        {
            while (people.Count < populationSize)
            {
                Individu temp   = new Individu(bodySize);
                int      father = random.Next(0, populationSize / 2);
                int      mother;
                do
                {
                    mother = random.Next(0, populationSize / 2);
                } while (mother == father);


                temp.Hybridation(people[father], people[mother]);
                people.Add(temp);
            }
        }