Nano Brain for Unity v0.1
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | Properties | List of all members
Cluster Class Reference

Description

A Cluster combines a collection of Nuclei to implement reusable behaviour.

A Cluster is an instantiation of a ClusterPrefab. Clusters can be nested inside other clusters.

Inheritance diagram for Cluster:
Nucleus

Public Types

enum  Type { None , Neuron , MemoryCell , Cluster }
 The types of Nucleus.
 

Public Member Functions

 Cluster (ClusterPrefab prefab, Cluster parent)
 Instantiate a new copy of a ClusterPrefab in the given parent.
 
 Cluster (ClusterPrefab prefab, ClusterPrefab parent=null)
 Add a new cluster to a ClusterPrefab.
 
override Nucleus ShallowCloneTo (Cluster parent)
 Function to make a partial clone of this nucleus.
 
void AddInstance ()
 Increase the number of instances in an multi-cluster.
 
void AddInstance (ClusterPrefab prefab)
 Create an new instance in a multi-cluster.
 
void RemoveInstance ()
 Decrease the number of instance in a multi-cluster.
 
void RefreshComputeOrders ()
 Refresh the order in which neurons should be computed.
 
void RefreshOutputs ()
 Reset the list of outputs such that they will be re-determined.
 
bool TryGetNucleus (string nucleusName, out Nucleus foundNucleus)
 Try to find a nucleus in this cluster.
 
Nucleus GetNucleus (string nucleusName)
 Get a nucleus in this cluster.
 
Neuron GetNeuron (string neuronName)
 Get a neuron in this cluster.
 
Neuron GetNeuron (int thingId, string neuronName, string thingName=null)
 Get a neuron in an instance of a multi-cluster.
 
bool DeleteNucleus (Nucleus nucleus)
 Delete a nucleus from this clsuter.
 
virtual List< NucleusCollectReceivers (bool removeDuplicates=false)
 Collect all receiving nuclei of signals from this cluster.
 
List< SynapseCollectSynapsesTo (Cluster otherCluster)
 Collect all synapses of senders in another cluster of signals to this cluster.
 
void UpdateFromNucleus (Nucleus startNucleus)
 Update the state of the nucleus and all nuclei receiving from it.
 
override void UpdateStateIsolated ()
 Update the state without updating other Nuclei.
 
void Refresh ()
 Recalculate derived properties.
 

Static Public Member Functions

static int GetNucleusIndex (List< Nucleus > nuclei, Nucleus nucleus)
 Get the index of a nucleus in a list of nuclei.
 
static int GetNucleusIndex (List< Nucleus > nuclei, string nucleusName)
 Get the index of a nucleus with the given name in a list of nuclei.
 

Public Attributes

ClusterPrefab prefab
 The prefab used to create this cluster.
 
Cluster[] instances
 All cluster instance of a multi-cluster.
 
int instanceCount = 1
 The number of cluster instances in a multi-cluster.
 
Dictionary< int, ClusterthingClusters = new()
 The mapping from things to cluster instances.
 
List< Nucleusnuclei = new()
 All nuclei in this cluster.
 
string name
 The name of the Nucleus.
 
Cluster parent
 The cluster instance in which the nucleus is located.
 

Protected Attributes

List< Neuron_outputs = null
 The neurons without outgoing connections.
 

Properties

string baseName [get]
 The base name of the cluster. I don't think this is actively used at this moment.
 
Dictionary< Nucleus, List< Nucleus > > computeOrders [get]
 This gives the order in which nuclei should be computed when a nucleus is updated.
 
virtual Neuron defaultOutput [get]
 The first nucleus in a cluster is the default output.
 
List< Neuronoutputs [get]
 The neurons without outgoing connections.
 

Constructor & Destructor Documentation

◆ Cluster() [1/2]

Cluster ( ClusterPrefab  prefab,
Cluster  parent 
)

Instantiate a new copy of a ClusterPrefab in the given parent.

Parameters
prefabThe prefab to use
parentThe cluster in which this new cluster will be placed

◆ Cluster() [2/2]

Cluster ( ClusterPrefab  prefab,
ClusterPrefab  parent = null 
)

Add a new cluster to a ClusterPrefab.

Parameters
prefabThe prefab to copy
parentThe prefab in which the new copy is placed

Member Function Documentation

◆ ShallowCloneTo()

override Nucleus ShallowCloneTo ( Cluster  parent)

Function to make a partial clone of this nucleus.

Parameters
parentThe cluster in which the cloned nucleus should be placed
Returns

◆ GetNucleusIndex() [1/2]

static int GetNucleusIndex ( List< Nucleus nuclei,
Nucleus  nucleus 
)
static

Get the index of a nucleus in a list of nuclei.

Parameters
nucleiThe list of nuclei to search
nucleusThe nucleus to find
Returns
The index of the nucleus in the list or -1 when it has not been found

◆ GetNucleusIndex() [2/2]

static int GetNucleusIndex ( List< Nucleus nuclei,
string  nucleusName 
)
static

Get the index of a nucleus with the given name in a list of nuclei.

Parameters
nucleiThe list of nuclei to search
nucleusNameThe name of the nucleus to find
Returns
The index of the nucleus in the list or -1 when it has not been found

◆ AddInstance() [1/2]

void AddInstance ( )

Increase the number of instances in an multi-cluster.

/remark Note this does not create the instances. This is only intended to be used for prefabs.

◆ AddInstance() [2/2]

void AddInstance ( ClusterPrefab  prefab)

Create an new instance in a multi-cluster.

Parameters
prefabThe prefab to use to create the new instance

/remark This does not change the instanceCount. It should only be used at runtime.

◆ TryGetNucleus()

bool TryGetNucleus ( string  nucleusName,
out Nucleus  foundNucleus 
)

Try to find a nucleus in this cluster.

Parameters
nucleusNameThe name of the nucleus to find
foundNucleusThe found nucleus or null if it is not found
Returns
True when the nucleus is found, false otherwise

◆ GetNucleus()

Nucleus GetNucleus ( string  nucleusName)

Get a nucleus in this cluster.

Parameters
nucleusNameThe name of the nucleus to find
Returns
The found nucleus or null when it is not found

◆ GetNeuron() [1/2]

Neuron GetNeuron ( string  neuronName)

Get a neuron in this cluster.

Parameters
neuronNameThe name of the neuron to find
Returns
The found neuron or null when it is not found

◆ GetNeuron() [2/2]

Neuron GetNeuron ( int  thingId,
string  neuronName,
string  thingName = null 
)

Get a neuron in an instance of a multi-cluster.

Parameters
thingIdThe id of the thing mapped to the cluster instance
neuronNameThe name of the neuron to find
thingNameThe name of the thing mapped to the cluster instance
Returns
The found neuron or null when it is not found

The cluster instance mapped to the thing will be neuron.parent if a neuron is found.

◆ DeleteNucleus()

bool DeleteNucleus ( Nucleus  nucleus)

Delete a nucleus from this clsuter.

Parameters
nucleusThe nucleus to delete
Returns
True if a nucleus was deleted, false if the nucleus could not be found

◆ CollectReceivers()

virtual List< Nucleus > CollectReceivers ( bool  removeDuplicates = false)
virtual

Collect all receiving nuclei of signals from this cluster.

Parameters
removeDuplicatesEnsure that a receiver is only listed once in the result
Returns
The list of receivers

◆ CollectSynapsesTo()

List< Synapse > CollectSynapsesTo ( Cluster  otherCluster)

Collect all synapses of senders in another cluster of signals to this cluster.

Parameters
otherClusterThe other cluster with sending neurons
Returns
A list of synapses to the neurons in the other clusters

◆ UpdateFromNucleus()

void UpdateFromNucleus ( Nucleus  startNucleus)

Update the state of the nucleus and all nuclei receiving from it.

Parameters
startNucleusThe nucleus to start updating

◆ UpdateStateIsolated()

override void UpdateStateIsolated ( )

Update the state without updating other Nuclei.

◆ Refresh()

void Refresh ( )

Recalculate derived properties.

This can be used to recalculate derived properties after the set of nuclei has been changed

Member Data Documentation

◆ prefab

ClusterPrefab prefab

The prefab used to create this cluster.

Cluster should always be created from prefabs

◆ instances

Cluster [] instances

All cluster instance of a multi-cluster.

A cluster is a multi-cluster when there is more than one instance. The actual instances are only created at runtime. The value instanceCount determines how many instances will be present at runtime.

◆ instanceCount

int instanceCount = 1

The number of cluster instances in a multi-cluster.

A cluster is a multi-clsuter when there is more than one instance.

◆ thingClusters

Dictionary<int, Cluster> thingClusters = new()

The mapping from things to cluster instances.

In a multi-cluster each instance can be used for a thing. Cluster instance may also not (yet) be mapped to a thing.

◆ _outputs

List<Neuron> _outputs = null
protected

The neurons without outgoing connections.

These neurons can potentially be connected to neurons in other clusters

Property Documentation

◆ outputs

List<Neuron> outputs
get

The neurons without outgoing connections.

These neurons can potentially be connected to neurons in other clusters