Esempio n. 1
0
        public int[][][] CrossBreed(int[][][] breeders, int popSize)
        {
            var pop    = new int[popSize][][];
            var random = new Random();

            for (var i = 0; i < popSize; i++)
            {
                var idx1 = random.Next() % breeders.Length;
                var idx2 = ArrayByIndex.GetDistinctRandomIndex(breeders, idx1);
                pop[i] = GetBreedersChild(breeders[idx1], breeders[idx2]);
            }

            return(pop);
        }
Esempio n. 2
0
        public void MutatePop(int[][][] pop, float mutationRate)
        {
            var random = new Random();

            foreach (var entity in pop)
            {
                if (random.NextDouble() > mutationRate)
                {
                    continue;
                }
                var idx1 = random.Next() % entity.Length;
                var idx2 = ArrayByIndex.GetDistinctRandomIndex(entity, idx1);
                ArrayByIndex.SwapElement(entity, idx1, idx2);
            }
        }