public bool TryAddLinkGene(CPPNNEATLinkGene gene) { if (linkGeneMap.ContainsKey(gene.InnovationNumber) && linkGeneMap[gene.InnovationNumber].Enabled) { return(false); } linkGeneMap[gene.InnovationNumber] = gene; AddNeuronGene(gene.From); AddNeuronGene(gene.To); if (gene.Enabled) { possibleConnections.Remove(Tuple.Create(gene.From, gene.To)); } sortedLinkGenesCacheExpired = true; HasBeenUnOrphaned(gene.To, gene, link => link.From, link => link.To); HasBeenUnOrphaned(gene.From, gene, link => link.To, link => link.From); Parent.Update(); return(true); }
private void EnableLinkGene(CPPNNEATLinkGene selectedLink) { selectedLink.Enabled = true; possibleConnections.Remove(Tuple.Create(selectedLink.From, selectedLink.To)); HasBeenUnOrphaned(selectedLink.To, selectedLink, link => link.From, link => link.To); HasBeenUnOrphaned(selectedLink.From, selectedLink, link => link.To, link => link.From); Parent.Update(); }
private void CreateNeuronGene(CPPNNEATLinkGene selectedLink) { DisableLinkGene(selectedLink); var newNeuron = ParentGA.GetHiddenNeuron(selectedLink.InnovationNumber); TryAddLinkGene(new CPPNNEATLinkGene(ParentGA.GetEdgeInnovationNumber(selectedLink.From, newNeuron), selectedLink.From, newNeuron, 1)); TryAddLinkGene(new CPPNNEATLinkGene(ParentGA.GetEdgeInnovationNumber(newNeuron, selectedLink.To), newNeuron, selectedLink.To, selectedLink.Weight)); }
private void HasBeenUnOrphaned(CPPNNEATNeuronGene neuron, CPPNNEATLinkGene propogatingLink, Func <CPPNNEATLinkGene, CPPNNEATNeuronGene> parentFunction, Func <CPPNNEATLinkGene, CPPNNEATNeuronGene> childFunction) { if (neuron.Type != CPPNNeuronType.Hidden || !orphanedNeurons.Contains(neuron) || orphanedNeurons.Contains(parentFunction(propogatingLink))) { return; } orphanedNeurons.Remove(neuron); var enabledLinks = LinkGenes.Where(link => link.Enabled); foreach (var enabledLink in enabledLinks.Where(link => parentFunction(link) == neuron).ToList()) { HasBeenUnOrphaned(childFunction(enabledLink), enabledLink, parentFunction, childFunction); } }
private void HasBeenOrphaned(CPPNNEATNeuronGene neuron, CPPNNEATLinkGene propogatingLink, Func <CPPNNEATLinkGene, CPPNNEATNeuronGene> parentFunction, Func <CPPNNEATLinkGene, CPPNNEATNeuronGene> childFunction) { if (neuron.Type != CPPNNeuronType.Hidden || orphanedNeurons.Contains(neuron)) { return; } var validLinks = ValidLinks; if (validLinks.Where(link => link != propogatingLink && childFunction(link) == neuron).Count() == 0) { orphanedNeurons.Add(neuron); foreach (var validLink in validLinks.Where(link => parentFunction(link) == neuron).ToList()) { HasBeenOrphaned(childFunction(validLink), validLink, parentFunction, childFunction); } } }
private void HasBeenUnOrphaned(CPPNNEATNeuronGene neuron, CPPNNEATLinkGene propogatingLink, Func<CPPNNEATLinkGene, CPPNNEATNeuronGene> parentFunction, Func<CPPNNEATLinkGene, CPPNNEATNeuronGene> childFunction) { if (neuron.Type != CPPNNeuronType.Hidden || !orphanedNeurons.Contains(neuron) || orphanedNeurons.Contains(parentFunction(propogatingLink))) { return; } orphanedNeurons.Remove(neuron); var enabledLinks = LinkGenes.Where(link => link.Enabled); foreach (var enabledLink in enabledLinks.Where(link => parentFunction(link) == neuron).ToList()) { HasBeenUnOrphaned(childFunction(enabledLink), enabledLink, parentFunction, childFunction); } }
private void HasBeenOrphaned(CPPNNEATNeuronGene neuron, CPPNNEATLinkGene propogatingLink, Func<CPPNNEATLinkGene, CPPNNEATNeuronGene> parentFunction, Func<CPPNNEATLinkGene, CPPNNEATNeuronGene> childFunction) { if (neuron.Type != CPPNNeuronType.Hidden || orphanedNeurons.Contains(neuron)) { return; } var validLinks = ValidLinks; if (validLinks.Where(link => link != propogatingLink && childFunction(link) == neuron).Count() == 0) { orphanedNeurons.Add(neuron); foreach (var validLink in validLinks.Where(link => parentFunction(link) == neuron).ToList()) { HasBeenOrphaned(childFunction(validLink), validLink, parentFunction, childFunction); } } }
public bool TryAddLinkGene(CPPNNEATLinkGene gene) { if (linkGeneMap.ContainsKey(gene.InnovationNumber) && linkGeneMap[gene.InnovationNumber].Enabled) { return false; } linkGeneMap[gene.InnovationNumber] = gene; AddNeuronGene(gene.From); AddNeuronGene(gene.To); if (gene.Enabled) { possibleConnections.Remove(Tuple.Create(gene.From, gene.To)); } sortedLinkGenesCacheExpired = true; HasBeenUnOrphaned(gene.To, gene, link => link.From, link => link.To); HasBeenUnOrphaned(gene.From, gene, link => link.To, link => link.From); Parent.Update(); return true; }
public Match(CPPNNEATLinkGene firstCollection, CPPNNEATLinkGene secondCollection) { this.FirstCollection = firstCollection; this.SecondCollection = secondCollection; }