@@ -481,12 +481,32 @@ namespace NEAT
481481 if ((a_RNG.RandFloat () < a_Parameters.InterspeciesCrossoverRate ) &&
482482 (a_Pop.m_Species .size () > 1 ))
483483 {
484- // Find different species (random one) // !!!!!!!!!!!!!!!!!
485- int t_diffspec = a_RNG.RandInt (0 , static_cast <int >(a_Pop.m_Species .size () - 1 ));
486-
487- t_mom = GetIndividual (a_Parameters, a_RNG);
488- t_dad = a_Pop.m_Species [t_diffspec].GetIndividual (a_Parameters, a_RNG);
489- t_interspecies = true ;
484+ // / Find different species via roulette over average fitness as probability
485+ std::vector<double > probs;
486+ double allp=0 ;
487+ for (int i=0 ; i<a_Pop.m_Species .size (); i++)
488+ {
489+ if ((a_Pop.m_Species [i].m_ID == m_ID))
490+ {
491+ probs.push_back (0.0 );
492+ }
493+ else
494+ {
495+ probs.push_back (a_Pop.m_Species [i].m_AverageFitness );
496+ }
497+ allp += probs[probs.size ()-1 ];
498+ }
499+ if (allp > 0 )
500+ {
501+ int t_diffspec = a_RNG.Roulette (probs);
502+ t_mom = GetIndividual (a_Parameters, a_RNG);
503+ t_dad = a_Pop.m_Species [t_diffspec].GetIndividual (a_Parameters, a_RNG);
504+ t_interspecies = true ;
505+ }
506+ else
507+ {
508+ continue ;
509+ }
490510 }
491511 else
492512 {
@@ -496,7 +516,7 @@ namespace NEAT
496516
497517 // The other parent should be a different one
498518 // number of tries to find different parent
499- int t_tries = 10 ;
519+ int t_tries = 32 ;
500520 while (((t_mom.GetID () == t_dad.GetID ())) && (t_tries--))
501521 {
502522 t_mom = GetIndividual (a_Parameters, a_RNG);
@@ -552,7 +572,7 @@ namespace NEAT
552572 {
553573 if (
554574 (t_baby.CompatibilityDistance (a_Pop.m_TempSpecies [i].m_Individuals [j],
555- a_Parameters) <= a_Parameters.MinDeltaCompatEqualGenomes ) // identical genome?
575+ a_Parameters) < a_Parameters.MinDeltaCompatEqualGenomes ) // identical genome?
556576 )
557577 {
558578 t_baby_exists_in_pop = true ;
@@ -569,7 +589,7 @@ namespace NEAT
569589 {
570590 if (
571591 (t_baby.CompatibilityDistance (a_Pop.m_GenomeArchive [i],
572- a_Parameters) <= a_Parameters.MinDeltaCompatEqualGenomes ) // identical genome?
592+ a_Parameters) < a_Parameters.MinDeltaCompatEqualGenomes ) // identical genome?
573593 )
574594 {
575595 t_baby_exists_in_pop = true ;
@@ -652,10 +672,24 @@ namespace NEAT
652672 else
653673 {
654674 // keep searching for a matching species
655- t_cur_species++;
675+ /* t_cur_species++;
656676 if (t_cur_species != a_Pop.m_TempSpecies.end())
657677 {
658678 t_to_compare = t_cur_species->GetRepresentative(); // was GetRepresentative()
679+ }*/
680+
681+ while (1 )
682+ {
683+ t_cur_species++;
684+ if (t_cur_species == a_Pop.m_TempSpecies .end ())
685+ {
686+ break ;
687+ }
688+ if (t_cur_species->NumIndividuals () > 0 )
689+ {
690+ t_to_compare = t_cur_species->GetRepresentative ();
691+ break ;
692+ }
659693 }
660694 }
661695 }
0 commit comments