starting to work with 6 cluster receptors
This commit is contained in:
parent
abbce40992
commit
f8b487cef7
58
Cluster.cs
58
Cluster.cs
@ -113,6 +113,11 @@ public class Cluster : Nucleus {
|
|||||||
clonedNucleus.nucleiArray = clonedFirstNucleus.nucleiArray;
|
clonedNucleus.nucleiArray = clonedFirstNucleus.nucleiArray;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (Nucleus nucleus in this.clusterNuclei) {
|
||||||
|
if (nucleus is Cluster clonedSubCluster)
|
||||||
|
RestoreAllExternalReceivers(clonedSubCluster, this.prefab, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort the nuclei in a correct evaluation order
|
// Sort the nuclei in a correct evaluation order
|
||||||
@ -204,7 +209,44 @@ public class Cluster : Nucleus {
|
|||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void RestoreAllExternalReceivers(Cluster clonedCluster, ClusterPrefab prefabParent, Cluster clonedParent) {
|
||||||
|
int clonedClusterIx = GetNucleusIndex(clonedParent.clusterNuclei, clonedCluster);
|
||||||
|
if (prefabParent.nuclei[clonedClusterIx] is not Cluster sourceCluster)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (int nucleusIx = 0; nucleusIx < sourceCluster.clusterNuclei.Count; nucleusIx++) {
|
||||||
|
Nucleus sourceNucleus = sourceCluster.clusterNuclei[nucleusIx];
|
||||||
|
if (sourceNucleus is not Neuron sourceNeuron)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Nucleus clonedNucleus = clonedCluster.clusterNuclei[nucleusIx];
|
||||||
|
if (clonedNucleus is not Neuron clonedNeuron)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// copy the receivers (and thus synapses) from the source to the clone
|
||||||
|
foreach (Nucleus receiver in sourceNeuron.receivers) {
|
||||||
|
int ix = GetNucleusIndex(prefabParent.nuclei, receiver);
|
||||||
|
if (ix < 0 || ix >= clonedParent.clusterNuclei.Count)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Nucleus clonedReceiver = clonedParent.clusterNuclei[ix];
|
||||||
|
|
||||||
|
// Find the synapse for the weight
|
||||||
|
float weight = 1;
|
||||||
|
foreach (Synapse synapse in receiver.synapses) {
|
||||||
|
// Find the weight for this synapse
|
||||||
|
if (synapse.nucleus == sourceNucleus) {
|
||||||
|
weight = synapse.weight;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clonedNeuron.AddReceiver(clonedReceiver, weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
protected void RestoreExternalReceivers(Cluster clone, ClusterPrefab prefabParent, Cluster clonedParent) {
|
protected void RestoreExternalReceivers(Cluster clone, ClusterPrefab prefabParent, Cluster clonedParent) {
|
||||||
|
// Loop over all nuclei of this (the prefab of the clone?)
|
||||||
for (int nucleusIx = 0; nucleusIx < this.clusterNuclei.Count; nucleusIx++) {
|
for (int nucleusIx = 0; nucleusIx < this.clusterNuclei.Count; nucleusIx++) {
|
||||||
Nucleus prefabNucleus = this.clusterNuclei[nucleusIx];
|
Nucleus prefabNucleus = this.clusterNuclei[nucleusIx];
|
||||||
if (prefabNucleus is not Neuron prefabNeuron)
|
if (prefabNucleus is not Neuron prefabNeuron)
|
||||||
@ -217,7 +259,7 @@ public class Cluster : Nucleus {
|
|||||||
// Copy the receivers, which will also create the synapses
|
// Copy the receivers, which will also create the synapses
|
||||||
foreach (Nucleus receiver in prefabNeuron.receivers) {
|
foreach (Nucleus receiver in prefabNeuron.receivers) {
|
||||||
int ix = GetNucleusIndex(prefabParent.nuclei, receiver);
|
int ix = GetNucleusIndex(prefabParent.nuclei, receiver);
|
||||||
if (ix < 0)
|
if (ix < 0 || ix >= clonedParent.clusterNuclei.Count)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
//if (clone.clusterNuclei[ix] is not Nucleus clonedReceiver)
|
//if (clone.clusterNuclei[ix] is not Nucleus clonedReceiver)
|
||||||
@ -249,7 +291,7 @@ public class Cluster : Nucleus {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetNucleusIndex(List<Nucleus> nuclei, Nucleus nucleus) {
|
public static int GetNucleusIndex(List<Nucleus> nuclei, Nucleus nucleus) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (Nucleus nucleiElement in nuclei) {
|
foreach (Nucleus nucleiElement in nuclei) {
|
||||||
//for (int i = 0; i < nuclei.Length; i++) {
|
//for (int i = 0; i < nuclei.Length; i++) {
|
||||||
@ -346,13 +388,13 @@ public class Cluster : Nucleus {
|
|||||||
|
|
||||||
//if (current is Neuron neuron) {
|
//if (current is Neuron neuron) {
|
||||||
|
|
||||||
foreach (Nucleus receiver in receivers) {
|
foreach (Nucleus receiver in receivers) {
|
||||||
if (visited.Contains(receiver)) {
|
if (visited.Contains(receiver)) {
|
||||||
inDegree[receiver]--;
|
inDegree[receiver]--;
|
||||||
if (inDegree[receiver] == 0) // If all dependencies resolved
|
if (inDegree[receiver] == 0) // If all dependencies resolved
|
||||||
queue.Enqueue(receiver);
|
queue.Enqueue(receiver);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,7 +31,7 @@ public class ClusterReceptor : Cluster, IReceptor {
|
|||||||
//CloneFields(clone);
|
//CloneFields(clone);
|
||||||
// This cloned the prefab with the clusternuclei,
|
// This cloned the prefab with the clusternuclei,
|
||||||
// but did not clone the receivers outside the cluster
|
// but did not clone the receivers outside the cluster
|
||||||
RestoreExternalReceivers(clone, this.clusterPrefab, parent);
|
//RestoreExternalReceivers(clone, this.clusterPrefab, parent);
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
@ -158,7 +158,7 @@ public class ClusterReceptor : Cluster, IReceptor {
|
|||||||
selectedReceiver.name = baseName + ": " + thingName;
|
selectedReceiver.name = baseName + ": " + thingName;
|
||||||
}
|
}
|
||||||
|
|
||||||
int inputIx = this.GetNucleusIndex(this.clusterNuclei, input);
|
int inputIx = GetNucleusIndex(this.clusterNuclei, input);
|
||||||
if (inputIx < 0)
|
if (inputIx < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@ -1004,8 +1004,8 @@ public class ClusterInspector : Editor {
|
|||||||
if (synapse.nucleus.parent is ClusterReceptor receptor) {
|
if (synapse.nucleus.parent is ClusterReceptor receptor) {
|
||||||
// the new nucleus is part of a (cluster) receptor,
|
// the new nucleus is part of a (cluster) receptor,
|
||||||
// so we have to change all synapses to this nucleus array elements
|
// so we have to change all synapses to this nucleus array elements
|
||||||
int oldNucleusIx = subCluster.GetNucleusIndex(subCluster.clusterNuclei, synapse.nucleus);
|
int oldNucleusIx = Cluster.GetNucleusIndex(subCluster.clusterNuclei, synapse.nucleus);
|
||||||
int newNucleusIx = subCluster.GetNucleusIndex(subCluster.clusterNuclei, newNucleus);
|
int newNucleusIx = Cluster.GetNucleusIndex(subCluster.clusterNuclei, newNucleus);
|
||||||
foreach (Nucleus element in receptor.nucleiArray) {
|
foreach (Nucleus element in receptor.nucleiArray) {
|
||||||
if (element is not ClusterReceptor clusterReceptor)
|
if (element is not ClusterReceptor clusterReceptor)
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user