private void nodeMutate(Genome genome) { if (genome.genes.size() == 0) return; genome.maxneuron = genome.maxneuron + 1; int randomIndex = rand.nextInt(genome.genes.size()); Gene gene = genome.genes.get(randomIndex); if (!gene.isEnabled()) return; gene.setEnabled(false); Gene gene1 = gene.copy(); gene1.setOut(genome.maxneuron); gene1.setWeight(1.0f); gene1.innovation = newInnovation(); gene1.setEnabled(true); genome.genes.add(gene1); Gene gene2 = gene.copy(); gene2.setInto(genome.maxneuron); gene2.innovation = newInnovation(); gene2.setEnabled(true); genome.genes.add(gene2); }
public void enableDisableMutate(Genome genome, boolean enable) { List<Gene> candidates = new ArrayList<Gene>(); // find the genes that are not this enablestate for (Gene gene : genome.genes) { if (gene.isEnabled() != enable) { candidates.add(gene); } } if (candidates.isEmpty()) { return; } // flip the enablestate of a random candidate int randomIndex = rand.nextInt(candidates.size()); Gene gene = candidates.get(randomIndex); gene.setEnabled(!gene.isEnabled()); }