public void makeN1PointToN2(ref NodeGene n1, ref NodeGene n2) { if (n1.getNodeType() == NodeGene.NodeType.HIDDEN && n2.getNodeType() == NodeGene.NodeType.INPUT || n1.getNodeType() == NodeGene.NodeType.OUTPUT && n2.getNodeType() == NodeGene.NodeType.INPUT || n1.getNodeType() == NodeGene.NodeType.OUTPUT && n2.getNodeType() == NodeGene.NodeType.HIDDEN) { NodeGene temp = n1; n1 = n2; n2 = temp; } }
public void Make_Node_One_Point_To_Node_Two() { NodeGene n1 = new NodeGene(NodeGene.NodeType.HIDDEN, 0); NodeGene n2 = new NodeGene(NodeGene.NodeType.INPUT, 1); genome.makeN1PointToN2(ref n1, ref n2); Assert.AreEqual(NodeGene.NodeType.HIDDEN, n2.getNodeType()); }
public bool addConnectionMutation(Random random) { bool uniqueMatch = false; NodeGene n1 = null; NodeGene n2 = null; if (allConnectionsMade()) { return(false); } // to be used in circular loop checker Utility.nodeConnections.Clear(); foreach (KeyValuePair <int, ConnectionGene> c in connections) { //if key already exists add to hashset if (Utility.nodeConnections.ContainsKey(c.Value.getOut())) { Utility.nodeConnections[c.Value.getOut()].Add(c.Value.getIn()); } else { Utility.nodeConnections.Add(c.Value.getOut(), new HashSet <int>() { c.Value.getIn() }); } } while (!uniqueMatch) { uniqueMatch = true; n1 = nodes[nodeNumbers[random.Next(nodeNumbers.Count)]]; n2 = getDifferentNode(random, n1, nodes); if (circularConnectionFound(n1.getNodeNumber(), n2.getNodeNumber())) { return(false); } // if n1 and n1 aren't INPUT nodes if (!(n1.getNodeType() == NodeGene.NodeType.INPUT && n2.getNodeType() == NodeGene.NodeType.INPUT)) { makeN1PointToN2(ref n1, ref n2); foreach (KeyValuePair <int, ConnectionGene> c in connections) { // checks to see if connection already exists if (c.Value.getIn() == n1.getNodeNumber() && c.Value.getOut() == n2.getNodeNumber()) { uniqueMatch = false; } } } else { uniqueMatch = false; } } InnovationUtility.incrementGlobalInnovation(); addConnectionGene(new ConnectionGene(n1.getNodeNumber(), n2.getNodeNumber(), getRandomFloatBetweenPoints(random, -1.0, 1.0), true, InnovationUtility.getGlobalInnovation())); return(true); }