/// <summary> /// Find the same kind of gene in its genes, if there is one. /// </summary> public Gene GetGene(int innovationNb) { if (Genes == null) { return(null); } return(Genes.FirstOrDefault(x => x.InnovationNb == innovationNb)); }
public INode MutateAddNode() { int innovation = (int)RandomHelpers.GetRandomBiasingLow( Genes.Min(g => g.Innovation), Genes.Max(g => g.Innovation) ); IGene oldGene = Genes.FirstOrDefault(g => g.Innovation <= innovation); if (oldGene == null) { oldGene = Genes[new Random().Next(Genes.Count)]; } INode newNode = new Node(NodeType.Hidden); // Disable the old connection oldGene.IsExpressed = false; // Add new connections IGene newGeneIn = new Gene( oldGene.NodeOut, newNode, GetNextInnovation(), 1 ); IGene newGeneOut = new Gene( newNode, oldGene.NodeIn, GetNextInnovation(), oldGene.Weight ); Nodes.Add(newNode); Genes.Add(newGeneIn); Genes.Add(newGeneOut); return(newNode); }
/// <summary> /// cut this Gene and those after /// </summary> /// <param name="gene"></param> public void cut(Gene gene) { Genes.RemoveRange(Genes.FirstOrDefault(x => x == gene), Genes.Count); }