Libraries‎ > ‎Library‎ > ‎Linking‎ > ‎

All reachable nodes

BehaviourComposer: ignore everything before this.
Begin micro-behaviour:
Begin description:
Define a NetLogo reporter that computes all the nodes that can be reached from an initial list of nodes.
End description

All reachable nodes

Begin NetLogo code:
to-report all-nodes-reachable-from [nodes]
 report all-nodes-reachable-from-2 nodes []

to-report all-nodes-reachable-from-2 [nodes nodes-already-visited]
 if nodes = [] [report nodes-already-visited]
 let new-nodes-already-visited sentence nodes nodes-already-visited
 let new-nodes []
 forEach nodes
    [ask ? 
         [ask link-neighbors
             [if not member? self new-nodes-already-visited and 
                  not member? self new-nodes 
                  [set new-nodes fput self new-nodes]]]]        
 report all-nodes-reachable-from-2 new-nodes new-nodes-already-visited
End NetLogo code

How this works

This repeatedly searches for the nodes reachable from the initial list of nodes or the most recent nodes found accumulating them all into a list.


All reachable nodes was implemented by Ken Kahn on 8 July, 2010.

BehaviourComposer: ignore everything after this.