Пример #1
0
        public override float Evaluate(Individual individual)
        {
            BinaryPhenotype binaryPhenotype = (BinaryPhenotype)individual.Phenotype;

            int numBits = binaryPhenotype.NumBits;

            int[] bitVector = binaryPhenotype.BitVector;

            // Sum number of ones
            int sum = 0;

            for (int i = 0; i < numBits; i++)
            {
                if (bitVector[i] == Goal[i])
                {
                    sum++;
                }
            }

            // Make a minimum fitness value
            if (sum == 0)
            {
                return(0.1f);
            }
            else
            {
                return((float)sum);
            }
        }
        public override Phenotype Develop(Genotype genotype)
        {
            BinaryGenotype  binaryGenotype  = (BinaryGenotype)genotype;
            BinaryPhenotype binaryPhenotype = new BinaryPhenotype();

            binaryPhenotype.BitVector = (int[])binaryGenotype.BitVector.Clone();
            binaryPhenotype.NumBits   = binaryGenotype.NumBits;

            return(binaryPhenotype);
        }
Пример #3
0
        public override float Evaluate(Individual individual)
        {
            BinaryPhenotype phenotype = (BinaryPhenotype)individual.Phenotype;

            int sumOnes = 0;

            // Look for leading ones
            for (int i = 0; i < phenotype.NumBits; i++)
            {
                if (phenotype.BitVector[i] == 0)
                {
                    break;
                }
                sumOnes++;
            }

            int sumZeros = 0;

            // Sum up leading zeroes up to threshold Z
            for (int i = 0; i < phenotype.NumBits && i < Z; i++)
            {
                if (phenotype.BitVector[phenotype.NumBits - 1 - i] == 1)
                {
                    break;
                }
                sumZeros++;
            }

            if (sumOnes > sumZeros)
            {
                return(sumOnes);
            }
            else
            {
                return(sumZeros);
            }
        }