private void nodeMutate(newGenome genome) { //NODE MUTATE if (genome.genes.Count == 0) { return; } genome.maxneuron = genome.maxneuron + 1; //GET RANDOM GENE newGene gene = genome.genes[Random(0, genome.genes.Count - 1)]; if (!gene.enabled) //IF FALSE RETURN { return; } gene.enabled = false; //ADD GENE1 newGene gene1 = gene.Copy(); gene1.output = genome.maxneuron; gene1.weight = 1.0; gene1.innovation = newInnovation(Pool); gene1.enabled = true; genome.genes.Add(gene1); //ADD GENE2 newGene gene2 = gene.Copy(); gene2.into = genome.maxneuron; gene2.innovation = newInnovation(Pool); gene2.enabled = true; genome.genes.Add(gene2); }
private newGenome crossover(newGenome g1, newGenome g2) { //MAKE SURE G1 IS THE HIGHER FITNESS GENOME if (g2.fitness > g1.fitness) { newGenome tempg = g1; g1 = g2; g2 = tempg; } newGenome child = new newGenome(); Dictionary <int, newGene> innovations2 = new Dictionary <int, newGene>(); for (int i = 0; i < g2.genes.Count; i++) { newGene gene = g2.genes[i]; innovations2[gene.innovation] = gene; } for (int i = 0; i < g1.genes.Count; i++) { newGene gene1 = g1.genes[i]; newGene gene2 = innovations2[gene1.innovation]; //COPY GENE1 OR GENE2 if (gene2 != null && Random(1, 2) == 1 && gene2.enabled) { child.genes.Add(gene2.Copy()); } else { child.genes.Add(gene1.Copy()); } } //GET MAXIMUM child.maxneuron = Max(g1.maxneuron, g2.maxneuron); foreach (KeyValuePair <string, double> item in g1.mutationRates) { child.mutationRates[item.Key] = item.Value; } return(child); }