Class NodeIdManager
A manager is intended to be shared by every chromosome in an evolving population. It tracks IDs already present in chromosomes and assigns one stable hidden-node ID to each ancestral connection innovation that is split by an add-node mutation. Consequently, homologous mutations receive the same node ID even when they occur in different genomes.
Allocation and registration methods are synchronized so a manager can safely be used by concurrent mutation
workers. IDs are drawn exclusively from the layout's hidden-node range and exhaustion is reported with an
IllegalStateException.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicLongprivate final NeatNodeLayoutprivate final ConcurrentHashMap<Integer, Integer> private final ConcurrentHashMap<Integer, Integer> -
Constructor Summary
ConstructorsConstructorDescriptionNodeIdManager(NeatNodeLayout _nodeLayout) Creates a manager for one node layout. -
Method Summary
Modifier and TypeMethodDescriptionprivate intintnodeIdForSplit(int connectionInnovation) Returns the hidden-node ID associated with splitting an ancestral connection.voidregisterExistingNodeIds(Collection<Integer> nodeIds) Registers node IDs already present in a chromosome before new IDs are allocated.voidregisterSplit(int connectionInnovation, int nodeId) Registers a known relationship between an ancestral connection and an existing hidden node.
-
Field Details
-
nodeLayout
-
nextNodeId
-
allocatedNodeIds
-
splitNodeIds
-
splitInnovationsByNodeId
-
-
Constructor Details
-
NodeIdManager
Creates a manager for one node layout.- Parameters:
_nodeLayout- layout defining the external IDs and hidden-node range- Throws:
NullPointerException- if_nodeLayoutisnull
-
-
Method Details
-
nodeIdForSplit
public int nodeIdForSplit(int connectionInnovation) Returns the hidden-node ID associated with splitting an ancestral connection.The first call allocates an ID; subsequent calls with the same innovation return that ID.
- Parameters:
connectionInnovation- non-negative connection innovation number- Returns:
- the stable hidden-node ID for the split
- Throws:
IllegalArgumentException- if the innovation number is negativeIllegalStateException- if the hidden-node range is exhausted
-
registerExistingNodeIds
Registers node IDs already present in a chromosome before new IDs are allocated.External IDs are accepted but do not consume hidden-node allocation slots. Every other ID must belong to the layout's hidden-node range.
- Parameters:
nodeIds- IDs referenced by an existing chromosome- Throws:
NullPointerException- if the collection or one of its elements isnullIllegalArgumentException- if an ID is outside the layout namespaces
-
registerSplit
public void registerSplit(int connectionInnovation, int nodeId) Registers a known relationship between an ancestral connection and an existing hidden node.- Parameters:
connectionInnovation- non-negative connection innovation numbernodeId- hidden-node ID assigned to the split- Throws:
IllegalArgumentException- if the ID is outside the hidden range or either value conflicts with a previous registration
-
allocateNodeId
private int allocateNodeId()
-