public bool MutateByAddingConnection() { // Loop through the input node and output node, pair them up if they are new List <NodeIndexPair> possiblePairs = new List <NodeIndexPair>(); for (int i = 0; i < dataInputNodes.Count; i++) { for (int e = 0; e < dataOutputNodes.Count; e++) { if (dataInputNodes[i] != dataOutputNodes[e]) { NodeIndexPair newPair = new NodeIndexPair(dataInputNodes[i], dataOutputNodes[e]); bool overlap = false; // Loop through exist pairs to check for overlap for (int piarIndex = 0; piarIndex < existPairs.Count && !overlap; piarIndex++) { overlap = NodeIndexPair.Compare(newPair, existPairs[piarIndex]); } // Loop through possible pairs to check for overlap for (int piarIndex = 0; piarIndex < possiblePairs.Count && !overlap; piarIndex++) { overlap = NodeIndexPair.Compare(newPair, possiblePairs[piarIndex]); } if (!overlap) { possiblePairs.Add(newPair); } } } } // Loop through possible pairs to generate mutations for (int i = 0; i < possiblePairs.Count; i++) { Genometype.ConnectionGenens newConnection = new Genometype.ConnectionGenens( possiblePairs[i].nodeIndex1, possiblePairs[i].nodeIndex2, Random.Range(randomWeightMin, randomWeightMax), Genometype.ConnectionGenens.OperatorType.Multiply); mutations.Add(MutateGenome(newConnection)); newConnection = new Genometype.ConnectionGenens( possiblePairs[i].nodeIndex1, possiblePairs[i].nodeIndex2, Random.Range(randomWeightMin, randomWeightMax), Genometype.ConnectionGenens.OperatorType.Plus); mutations.Add(MutateGenome(newConnection)); } return(false); }
public static bool Compare(NodeIndexPair pair1, NodeIndexPair pair2) { // Check pair's node index 1 is same as pair's node index 1 if (pair1.nodeIndex1 == pair2.nodeIndex1) { return(pair1.nodeIndex2 == pair2.nodeIndex2); } // Check pair's node index 1 is same as pair's node index 2 else if (pair1.nodeIndex1 == pair2.nodeIndex2) { return(pair1.nodeIndex2 == pair2.nodeIndex1); } return(false); }