/// <summary> /// Creates and adds the new innovation defined by the in node and out node to the hash table of existing innovations. /// </summary> /// <param name="inNodeId">The id of the node that is at the beginning of the associated connection.</param> /// <param name="outNodeId">The id of the node that is at the end of the associated connection.</param> /// <param name="innovationType">The type of innovation that is being created.</param> public void CreateNewInnovation(int inNodeId, int outNodeId, Innovation.TYPE innovationType) { // Create the new innovation to add Innovation newInnovation = null; // Add a new innovation to the existing innovations depending on whether it is a node or connection innovation if (innovationType == Innovation.TYPE.NEW_NODE) { newInnovation = new Innovation(CurrentInnovation++, innovationType, CurrentNodeId++, inNodeId, outNodeId); } else if (innovationType == Innovation.TYPE.NEW_CONNECTION) { newInnovation = new Innovation(CurrentInnovation++, innovationType, -1, inNodeId, outNodeId); } ExistingInnovations.Add(newInnovation); }
/// <summary> /// Checks the hash table of existing innovations for the innovation specified from the in node and out nodes. /// </summary> /// <param name="inNodeId">The id of the node that is at the beginning of the associated connection.</param> /// <param name="outNodeId">The id of the node that is at the end of the associated connection.</param> /// <param name="innovationType">The type of innovation that is being checked.</param> /// <returns>Returns the node id if this is a node innovation, otherwise returns innovation id. Returns -1 if the innovation does not yet exist.</returns> public int CheckInnovation(int inNodeId, int outNodeId, Innovation.TYPE innovationType) { // Iterate through all existing innovations to check if this innovation exists foreach (Innovation innovation in ExistingInnovations) { if (innovation.InNodeId == inNodeId && innovation.OutNodeId == outNodeId && innovation.Type == innovationType) { if (innovationType == Innovation.TYPE.NEW_NODE) { return(innovation.NodeId); } else if (innovationType == Innovation.TYPE.NEW_CONNECTION) { return(innovation.Id); } } } // Return -1 if this innovation does not yet exist return(-1); }