Example #1
0
 DetermineBestParent(CGenome mum, CGenome dad)
 {
     if (mum.Fitness() == dad.Fitness())
     {
         if (mum.NumGenes() == dad.NumGenes())
         {
             if (Random.value < 0.5)
             {
                 return(ParentType.Mum);
             }
             else
             {
                 return(ParentType.Dad);
             }
         }
         else
         {
             /*
              * Choose the parent with the fewest genes because
              * the fitness is the same.
              */
             if (mum.NumGenes() < dad.NumGenes())
             {
                 return(ParentType.Mum);
             }
             else
             {
                 return(ParentType.Dad);
             }
         }
     }
     else
     {
         if (mum.Fitness() > dad.Fitness())
         {
             return(ParentType.Mum);
         }
         else
         {
             return(ParentType.Dad);
         }
     }
 }
Example #2
0
        GetCompatibilityScore(CGenome other)
        {
            /*
             * Keep track of these numbers because genomes with different
             * topologies are unlikely to group together well. Therefore
             * the compatability score is based on how different the
             * topologies of the genomes are.
             */
            float numDisjointGenes = 0;
            float numExcessGenes   = 0;
            float numMatchedGenes  = 0;

            /*
             * The combined error/difference between the weights of the genomes.
             * A lower score means the behaviour is more probable to be
             * similar.
             */
            float weightDifference = 0;

            CalculateTopologyDifference(out numDisjointGenes, out numExcessGenes,
                                        out numMatchedGenes, out weightDifference,
                                        other);

            float longest = Mathf.Max(NumGenes(), other.NumGenes());

            /*
             * Coeffecients that are tweaked to influence the score
             * roughly the same amount.
             */
            const float coefDisjoint = 1.0f;
            const float coefExcess   = 1.0f;
            const float coefMatched  = 0.4f;

            return((coefExcess * numExcessGenes / longest) +
                   (coefDisjoint * numDisjointGenes / longest) +
                   (coefMatched * weightDifference / numMatchedGenes));
        }