示例#1
0
        // ルーレット選択
        public void Reproduce_Roulette(IntArrayChromosomes _intarraychromosomes)
        {
            _intarraychromosomes.SortChromosomes();
            var    random   = new System.Random();
            double scoreSum = 0;

            for (int i = 0; i < _intarraychromosomes.GetPopulation(); i++)
            {
                scoreSum += _intarraychromosomes.ReadScore(i);
            }
            for (int i = ELITE_POPULATION; i < _intarraychromosomes.GetPopulation() &&
                 _intarraychromosomes.GetPopulation() > POPULATION; i++)
            {
                if (random.NextDouble() <= 1 - _intarraychromosomes.ReadScore(i) / scoreSum)
                {
                    _intarraychromosomes.RemoveChromosome(i);
                }
            }
            int population = _intarraychromosomes.GetPopulation();

            for (int i = 0; i < population - POPULATION; i++)
            {
                _intarraychromosomes.RemoveChromosome(random.Next(ELITE_POPULATION, _intarraychromosomes.GetPopulation()));
            }
        }
示例#2
0
        // 選択・淘汰
        //ランキング選択
        public void Reproduce_Ranking(IntArrayChromosomes _intArrayChromosomes)
        {
            _intArrayChromosomes.SortChromosomes();
            var random     = new System.Random();
            int population = _intArrayChromosomes.GetPopulation();

            for (int i = 0; i < population - POPULATION; i++)
            {
                int individual = (int)(DensityFunction(random) * _intArrayChromosomes.GetPopulation()) + ELITE_POPULATION;
                if (individual >= POPULATION)
                {
                    individual = POPULATION - 1;
                }
                _intArrayChromosomes.RemoveChromosome(individual);
            }
        }