Class NodeIdManager

java.lang.Object
net.bmahe.genetics4j.neat.NodeIdManager

public class NodeIdManager extends Object
Allocates collision-safe hidden-node IDs for one semantic node layout.

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 Details

  • Constructor Details

    • NodeIdManager

      public NodeIdManager(NeatNodeLayout _nodeLayout)
      Creates a manager for one node layout.
      Parameters:
      _nodeLayout - layout defining the external IDs and hidden-node range
      Throws:
      NullPointerException - if _nodeLayout is null
  • 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 negative
      IllegalStateException - if the hidden-node range is exhausted
    • registerExistingNodeIds

      public void registerExistingNodeIds(Collection<Integer> nodeIds)
      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 is null
      IllegalArgumentException - 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 number
      nodeId - 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()