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 int
private final int
private final boolean
private final int
private final float
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
ImmutableConnection
(int fromNodeIndex, int toNodeIndex, float weight, boolean isEnabled, int innovation) -
Method Summary
Modifier and TypeMethodDescriptionstatic ImmutableConnection
copyOf
(Connection instance) Creates an immutable copy of aConnection
value.boolean
This instance is equal to all instances ofImmutableConnection
that have equal attribute values.private boolean
equalTo
(int synthetic, ImmutableConnection another) int
Returns the index of the source node for this connection.int
hashCode()
Computes a hash code from attributes:fromNodeIndex
,toNodeIndex
,weight
,isEnabled
,innovation
.int
Returns the innovation number for this connection.boolean
Returns whether this connection is enabled.static ImmutableConnection
of
(int fromNodeIndex, int toNodeIndex, float weight, boolean isEnabled, int innovation) Construct a new immutableConnection
instance.int
Returns the index of the target node for this connection.toString()
Prints the immutable valueConnection
with attribute values.private static ImmutableConnection
validate
(ImmutableConnection instance) float
weight()
Returns the weight of this connection.final ImmutableConnection
withFromNodeIndex
(int value) Copy the current immutable object by setting a value for thefromNodeIndex
attribute.final ImmutableConnection
withInnovation
(int value) Copy the current immutable object by setting a value for theinnovation
attribute.final ImmutableConnection
withIsEnabled
(boolean value) Copy the current immutable object by setting a value for theisEnabled
attribute.final ImmutableConnection
withToNodeIndex
(int value) Copy the current immutable object by setting a value for thetoNodeIndex
attribute.final ImmutableConnection
withWeight
(float value) Copy the current immutable object by setting a value for theweight
attribute.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods 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:
fromNodeIndex
in interfaceConnection
- 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 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:
weight
in 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:
isEnabled
in 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:
innovation
in interfaceConnection
- Returns:
- the innovation number (non-negative)
-
withFromNodeIndex
Copy the current immutable object by setting a value for thefromNodeIndex
attribute. 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 of the
this
object
-
withToNodeIndex
Copy the current immutable object by setting a value for thetoNodeIndex
attribute. 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 of the
this
object
-
withWeight
Copy the current immutable object by setting a value for theweight
attribute. 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 of the
this
object
-
withIsEnabled
Copy the current immutable object by setting a value for theisEnabled
attribute. 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 of the
this
object
-
withInnovation
Copy the current immutable object by setting a value for theinnovation
attribute. 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 of the
this
object
-
equals
This instance is equal to all instances ofImmutableConnection
that have equal attribute values. -
equalTo
-
hashCode
public int hashCode()Computes a hash code from attributes:fromNodeIndex
,toNodeIndex
,weight
,isEnabled
,innovation
. -
toString
Prints the immutable valueConnection
with attribute values. -
of
public static ImmutableConnection of(int fromNodeIndex, int toNodeIndex, float weight, boolean isEnabled, int innovation) Construct a new immutableConnection
instance.- Parameters:
fromNodeIndex
- The value for thefromNodeIndex
attributetoNodeIndex
- The value for thetoNodeIndex
attributeweight
- The value for theweight
attributeisEnabled
- The value for theisEnabled
attributeinnovation
- The value for theinnovation
attribute- Returns:
- An immutable Connection instance
-
validate
-
copyOf
Creates an immutable copy of aConnection
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
-