private NodeList CreateNetworkNodeList()
{
// Count the total number of nodes.
int nodeCount = 0;
foreach(SubstrateNodeSet set in _nodeSetList) {
nodeCount += set.NodeList.Count;
}
// Count the additional bias node (not explicitly defined on the substrate).
nodeCount++;
// Allocate storage for the nodes.
NodeList nodeList = new NodeList(nodeCount);
// Create bias node.
// Note. The nodes are created in the order of inputs, outputs and then hidden. This is the order required when constructing
// instances of the NeatGenome and NetworkDefinition classes. The requirement comes about through internal implementation of
// those classes - see comments on those classes for more info.
nodeList.Add(new NetworkNode(0u, NodeType.Bias, _activationFnId));
// Create input nodes. By convention the first nodeset describes the input nodes (not including the bias).
SubstrateNodeSet nodeSet = _nodeSetList[0];
int setNodeCount = nodeSet.NodeList.Count;
// Create input nodes.
for(int i=0; i<setNodeCount; i++) {
nodeList.Add(new NetworkNode(nodeSet.NodeList[i]._id, NodeType.Input, _activationFnId));
}
// Create output nodes. By convention the second nodeset describes the output nodes.
nodeSet = _nodeSetList[1];
setNodeCount = nodeSet.NodeList.Count;
for(int i=0; i<setNodeCount; i++) {
nodeList.Add(new NetworkNode(nodeSet.NodeList[i]._id, NodeType.Output, _activationFnId));
}
// Create hidden nodes (if any). All nodesets after the input and output nodesets define hidden nodes.
int setCount = _nodeSetList.Count;
for(int nodeSetIdx=2; nodeSetIdx<setCount; nodeSetIdx++)
{
nodeSet = _nodeSetList[nodeSetIdx];
setNodeCount = nodeSet.NodeList.Count;
for(int i=0; i<setNodeCount; i++) {
nodeList.Add(new NetworkNode(nodeSet.NodeList[i]._id, NodeType.Hidden, _activationFnId));
}
}
return nodeList;
}