Simple algorithm to eliminate circular references

We are starting with Neuron XYZ

  • Begin with array of all neurons

  • Create a dictionary

  • Fill dictionary with the GUID of every neuron as the key (value doesn’t really matter)

  • Now remove neuron XYZ from the dictionary (ie. itself)

  • Now iterate through every neuron that XYZ is currently connected to and remove those from the map

  • If we find those in map then repeat removing connected neurons of that neuron - but if the neuron is already present in the map then we are done for that particular neuron.

Example code in Lua:

function CreateNeuronMap(N) local Map = {} for i=1, #N do Map[i] = true end return Map end function FindSuitors(Neurons, Map, ID) if Map[ID] then Map[ID]= nil for i=1, #Neurons[ID] do FindSuitors(Neurons, Map, Neurons[ID][i]) end end end function main() local Neurons = {} Neurons[1] = {2,3} Neurons[2] = {2} Neurons[3] = {} local Map = CreateNeuronMap(Neurons) FindSuitors(Neurons, Map, 3) trace(Map) end