Class ImmutableConnection

java.lang.Object
net.bmahe.genetics4j.neat.ImmutableConnection
All Implemented Interfaces:
Connection

@Generated("org.immutables.processor.ProxyProcessor") public final class ImmutableConnection extends Object implements Connection
Immutable implementation of Connection.

Use the builder to create immutable instances: new Connection.Builder(). Use the static factory method to create immutable instances: ImmutableConnection.of().

  • Field Details

    • fromNodeIndex

      private final int fromNodeIndex
    • toNodeIndex

      private final int toNodeIndex
    • weight

      private final float weight
    • isEnabled

      private final boolean isEnabled
    • innovation

      private final int innovation
  • Constructor Details

    • ImmutableConnection

      private ImmutableConnection(int fromNodeIndex, int toNodeIndex, float weight, boolean isEnabled, int innovation)
  • Method Details

    • fromNodeIndex

      public int fromNodeIndex()
      Returns the index of the source node for this connection.
      Specified by:
      fromNodeIndex in interface Connection
      Returns:
      the source node index (non-negative)
    • toNodeIndex

      public int toNodeIndex()
      Returns the index of the target node for this connection.
      Specified by:
      toNodeIndex in interface Connection
      Returns:
      the target node index (non-negative)
    • weight

      public float weight()
      Returns the weight of this connection.

      The weight determines the strength and polarity of signal transmission through this connection. Positive weights amplify signals, negative weights invert them, and zero weights effectively disable signal transmission.

      Specified by:
      weight in interface Connection
      Returns:
      the connection weight
    • isEnabled

      public boolean isEnabled()
      Returns whether this connection is enabled.

      Enabled connections participate in network computation and signal propagation. Disabled connections are preserved in the genome but do not affect network output, allowing for topology exploration without gene loss.

      Specified by:
      isEnabled in interface Connection
      Returns:
      true if the connection is enabled, false otherwise
    • innovation

      public int innovation()
      Returns the innovation number for this connection.

      Innovation numbers are unique identifiers that track the historical order of structural mutations in the NEAT algorithm. They enable proper gene alignment during crossover and are used to calculate compatibility distance for speciation.

      Specified by:
      innovation in interface Connection
      Returns:
      the innovation number (non-negative)
    • withFromNodeIndex

      public final ImmutableConnection withFromNodeIndex(int value)
      Copy the current immutable object by setting a value for the fromNodeIndex attribute. A value equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for fromNodeIndex
      Returns:
      A modified copy of the this object
    • withToNodeIndex

      public final ImmutableConnection withToNodeIndex(int value)
      Copy the current immutable object by setting a value for the toNodeIndex attribute. A value equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for toNodeIndex
      Returns:
      A modified copy of the this object
    • withWeight

      public final ImmutableConnection withWeight(float value)
      Copy the current immutable object by setting a value for the weight attribute. A value strict bits equality used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for weight
      Returns:
      A modified copy of the this object
    • withIsEnabled

      public final ImmutableConnection withIsEnabled(boolean value)
      Copy the current immutable object by setting a value for the isEnabled attribute. A value equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for isEnabled
      Returns:
      A modified copy of the this object
    • withInnovation

      public final ImmutableConnection withInnovation(int value)
      Copy the current immutable object by setting a value for the innovation attribute. A value equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for innovation
      Returns:
      A modified copy of the this object
    • equals

      public boolean equals(Object another)
      This instance is equal to all instances of ImmutableConnection that have equal attribute values.
      Overrides:
      equals in class Object
      Returns:
      true if this is equal to another instance
    • equalTo

      private boolean equalTo(int synthetic, ImmutableConnection another)
    • hashCode

      public int hashCode()
      Computes a hash code from attributes: fromNodeIndex, toNodeIndex, weight, isEnabled, innovation.
      Overrides:
      hashCode in class Object
      Returns:
      hashCode value
    • toString

      public String toString()
      Prints the immutable value Connection with attribute values.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the value
    • of

      public static ImmutableConnection of(int fromNodeIndex, int toNodeIndex, float weight, boolean isEnabled, int innovation)
      Construct a new immutable Connection instance.
      Parameters:
      fromNodeIndex - The value for the fromNodeIndex attribute
      toNodeIndex - The value for the toNodeIndex attribute
      weight - The value for the weight attribute
      isEnabled - The value for the isEnabled attribute
      innovation - The value for the innovation attribute
      Returns:
      An immutable Connection instance
    • validate

      private static ImmutableConnection validate(ImmutableConnection instance)
    • copyOf

      public static ImmutableConnection copyOf(Connection instance)
      Creates an immutable copy of a Connection value. Uses accessors to get values to initialize the new immutable instance. If an instance is already immutable, it is returned as is.
      Parameters:
      instance - The instance to copy
      Returns:
      A copied immutable Connection instance