My Mathematica (both version 10.4 and the new 11) crash in the following loop:
count = 0;
findConnectedNodes[start_] := Module[{positions, i},
count++;
positions = adjmatrix[[start]] // ArrayRules // Keys;
positions = positions[[1 ;; -2]] // Flatten;
For[i = 1, i <= Length[positions], i++,
If[Not[MemberQ[connectedNodes, positions[[i]]]],
findConnectedNodes[positions[[i]]]];
AppendTo[connectedNodes, positions[[i]]];
connectedNodes = connectedNodes // DeleteDuplicates;
]
];
findConnectedAddresses[1];
The variable adjmatrix is a SparseArray and this code is to find all connected nodes in an adjacency matrix.
Interestingly the code works very well up to about 14'000 "counts" (the variable count) and after that Mathematica just crashes.
$RecursionLimit is set to Infinity.
Thank you very much for your help. And also any other suggestions for the code are much appreciated.
adjmatrix = SparseArray[{{i_, i_} -> 12, {i_, j_} /; Abs[i - j] == 1 -> 1}, {5, 5}]@Michael Gwerder - Conor CosnettDoin the documentation it has better performance thanFor. AlsoTableandParallelTable- Conor CosnettconnectedNodes@Michael Gwerder - Conor CosnettNeighborhoodGraph- agentp