public bool MutateByInsertNodeBetweenConnection() { for (int i = 0; i < m_originGenome.connectionGenes.Length; i++) { // The inbetween node int middleNodeIndex = m_originGenome.nodeGenes.Length; Genometype.NodeGenes newNode = new Genometype.NodeGenes(Genometype.NodeGenes.Types.Hidden); // The replacement connection Genometype.ConnectionGenens firstHalfConnection = new Genometype.ConnectionGenens( m_originGenome.connectionGenes[i].inputNodeIndex, middleNodeIndex, 1); Genometype.ConnectionGenens secondHalfConnection = new Genometype.ConnectionGenens( middleNodeIndex, m_originGenome.connectionGenes[i].outputNodeIndex, m_originGenome.connectionGenes[i].weight); // Create the new genome, and disabled the original connection Genometype newGenome = MutateGenome(newNode, new Genometype.ConnectionGenens[] { firstHalfConnection, secondHalfConnection, }); newGenome.connectionGenes[i].enabled = false; mutations.Add(newGenome); } return(false); }
public static bool Compare(Genometype genome1, Genometype genome2) { if (genome1.connectionGenes == null || genome2.connectionGenes == null) { return(genome1.connectionGenes == null && genome2.connectionGenes == null); } for (int i = 0; i < genome1.connectionGenes.Length; i++) { bool matched = true; for (int e = 0; e < genome2.connectionGenes.Length; e++) { if (genome1.connectionGenes[i].innovationNumber == genome2.connectionGenes[i].innovationNumber) { matched = true; break; } } if (!matched) { return(false); } } return(true); }
public GenomeMutationController(Genometype genome) { m_originGenome = genome; dataInputNodes = new List <int>(); dataOutputNodes = new List <int>(); existPairs = new List <NodeIndexPair>(); mutations = new List <Genometype>(); AnalyzeGenome(); }
protected Genometype ChangeWeightInGenome(Genometype genome, bool fullyRandom = false, float weightRange = 1f) { Genometype newGenome = genome.Clone(); for (int i = 0; i < newGenome.connectionGenes.Length; i++) { if (fullyRandom) { newGenome.connectionGenes[i].weight = Random.Range(-weightRange, weightRange); } else { newGenome.connectionGenes[i].weight += Random.Range(-weightRange, weightRange); } } return(newGenome); }
public void Reset() { m_genome = genome.Clone(); // for (int i = 0; i < m_genome.connectionGenes.Length; i++) // m_genome.nodeGenes[i].value = 0; }
public GenomeController(Genometype _genome) { genome = _genome; }