Class ImmutableConnection
- All Implemented Interfaces:
Connection
Connection.
Use the builder to create immutable instances:
new Connection.Builder().
Use the static factory method to create immutable instances:
ImmutableConnection.of().
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate final intprivate final booleanprivate final intprivate final float -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateImmutableConnection(int fromNodeIndex, int toNodeIndex, float weight, boolean isEnabled, int innovation) -
Method Summary
Modifier and TypeMethodDescriptionstatic ConnectioncopyOf(Connection instance) Creates an immutable copy of aConnectionvalue.booleanThis instance is equal to all instances ofImmutableConnectionthat have equal attribute values.private booleanequalsByValue(ImmutableConnection another) intReturns the index of the source node for this connection.inthashCode()Computes a hash code from attributes:fromNodeIndex,toNodeIndex,weight,isEnabled,innovation.intReturns the innovation number for this connection.booleanReturns whether this connection is enabled.static Connectionof(int fromNodeIndex, int toNodeIndex, float weight, boolean isEnabled, int innovation) Construct a new immutableConnectioninstance.intReturns the index of the target node for this connection.toString()Prints the immutable valueConnectionwith attribute values.private static ImmutableConnectionvalidate(ImmutableConnection instance) floatweight()Returns the weight of this connection.final ImmutableConnectionwithFromNodeIndex(int value) Copy the current immutable object by setting a value for thefromNodeIndexattribute.final ImmutableConnectionwithInnovation(int value) Copy the current immutable object by setting a value for theinnovationattribute.final ImmutableConnectionwithIsEnabled(boolean value) Copy the current immutable object by setting a value for theisEnabledattribute.final ImmutableConnectionwithToNodeIndex(int value) Copy the current immutable object by setting a value for thetoNodeIndexattribute.final ImmutableConnectionwithWeight(float value) Copy the current immutable object by setting a value for theweightattribute.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface net.bmahe.genetics4j.neat.Connection
check
-
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:
fromNodeIndexin interfaceConnection- Returns:
- the source node index (non-negative)
-
toNodeIndex
public int toNodeIndex()Returns the index of the target node for this connection.- Specified by:
toNodeIndexin interfaceConnection- 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:
weightin interfaceConnection- 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:
isEnabledin interfaceConnection- 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:
innovationin interfaceConnection- Returns:
- the innovation number (non-negative)
-
withFromNodeIndex
Copy the current immutable object by setting a value for thefromNodeIndexattribute. A value equality check is used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for fromNodeIndex- Returns:
- A modified copy or the
thisobject
-
withToNodeIndex
Copy the current immutable object by setting a value for thetoNodeIndexattribute. A value equality check is used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for toNodeIndex- Returns:
- A modified copy or the
thisobject
-
withWeight
Copy the current immutable object by setting a value for theweightattribute. A value strict bits equality used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for weight- Returns:
- A modified copy or the
thisobject
-
withIsEnabled
Copy the current immutable object by setting a value for theisEnabledattribute. A value equality check is used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for isEnabled- Returns:
- A modified copy or the
thisobject
-
withInnovation
Copy the current immutable object by setting a value for theinnovationattribute. A value equality check is used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for innovation- Returns:
- A modified copy or the
thisobject
-
equals
This instance is equal to all instances ofImmutableConnectionthat have equal attribute values. -
equalsByValue
-
hashCode
public int hashCode()Computes a hash code from attributes:fromNodeIndex,toNodeIndex,weight,isEnabled,innovation. -
toString
Prints the immutable valueConnectionwith attribute values. -
of
public static Connection of(int fromNodeIndex, int toNodeIndex, float weight, boolean isEnabled, int innovation) Construct a new immutableConnectioninstance.- Parameters:
fromNodeIndex- The value for thefromNodeIndexattributetoNodeIndex- The value for thetoNodeIndexattributeweight- The value for theweightattributeisEnabled- The value for theisEnabledattributeinnovation- The value for theinnovationattribute- Returns:
- An immutable Connection instance
-
validate
-
copyOf
Creates an immutable copy of aConnectionvalue. 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
-