public CPPNNEATGenome(ICPPNNEATGA parentGA, CPPNNEATGenome <PType> parent, CPPNNEATGenome <PType> partner) : this(parentGA) { var differences = new DifferenceAnalysis(parent.GeneCollection, partner.GeneCollection); var disjointAndExcessSource = differences.FirstCollection; if (partner.Score > parent.Score) { disjointAndExcessSource = differences.SecondCollection; } else if (partner.Score == parent.Score) { disjointAndExcessSource = (MathExtensions.RandomNumber() <= 0.5) ? differences.FirstCollection : differences.SecondCollection; } Func <CPPNNEATLinkGene, CPPNNEATLinkGene, Complex> weightSelector = null; if (MathExtensions.RandomNumber() <= parentGA.MateByAveragingRate) { weightSelector = (first, second) => (first.Weight + second.Weight) / 2; } else { weightSelector = (first, second) => (MathExtensions.RandomNumber() <= 0.5) ? first.Weight : second.Weight; } foreach (var match in differences.Matches) { var geneToCopy = match.FirstCollection; var newGene = geneToCopy.Copy(); newGene.Enabled = true; newGene.Weight = weightSelector(match.FirstCollection, match.SecondCollection); GeneCollection.TryAddLinkGene(newGene); if ((!match.FirstCollection.Enabled || !match.SecondCollection.Enabled) && MathExtensions.RandomNumber() <= parentGA.DisableGeneRate) { GeneCollection.DisableLinkGene(newGene.InnovationNumber); } } foreach (var linkGene in disjointAndExcessSource .Disjoint.Union(disjointAndExcessSource.Excess)) { GeneCollection.TryAddLinkGene(linkGene.Copy()); } }
public CPPNNEATGenome(ICPPNNEATGA parent) : base(parent) { this.GeneCollection = new CPPNNEATGeneCollection(this); }