Example #1
0
        /**
         * Creates a number of offspring by combining (using crossover) the current
         * Gene's chromosome with another Gene's chromosome.
         * Usually two parents will produce an equal amount of offpsring, although
         * in other reproduction strategies the number of offspring produced depends
         * on the fitness of the parents.
         * @param other: the other parent we want to create offpsring from
         * @return Array of Gene offspring (default length of array is 2).
         * These offspring will need to be added to the next generation.
         */
        public override GeneAbstract <int>[] Reproduce(GeneAbstract <int> other)
        {
            GeneA[] offspring = new GeneA[2];

            offspring[0].mChromosome = singlePointCrossover(other.mChromosome);
            offspring[1].mChromosome = singlePointCrossover(other.mChromosome);

            return(offspring);
        }
Example #2
0
        // --- functions:

        /**
         * Creates the starting population of Gene classes, whose chromosome contents are random
         * @param size: The size of the popultion is passed as an argument from the main class
         */
        public void InitializeAlgorithm(int size)
        {
            // initialize the arraylist and each gene's initial weights HERE
            mPopulation = new List <GeneA>();

            for (int i = 0; i < size; i++)
            {
                GeneA gene = new GeneA();
                gene.mChromosome = new int[CHROMOSOME_SIZE];
                gene.RandomizeChromosome();
            }
        }