This extension is pre-installed in NetLogo 5.0. (For help with extensions in general, see the NetLogo User Manual.)
This extension is experimental. Although it is presently bundled with NetLogo, it should not be considered a standard, fully-supported part of the application.
The source code for the extension is hosted online at https://github.com/NetLogo/Network-Extension
Anywhere a link breed is required, links
is also accepted.
Path lengths are computed based solely on the number of hops. There isn't currently any way to specify a "weight" or "distance" variable for links.
Ideally, instead of taking a link breed as input, the breed could take
the place of link
in the primitive name. Currently the extensions
API doesn't allow primitives that change name like this, but it should
in some future NetLogo version. Anyway, this is why all the names
have link
in them.
TURTLESET network:in-link-radius RADIUS LINK-BREED
TURTLESET network:in-out-link-radius RADIUS LINK-BREED
TURTLESET network:in-in-link-radius RADIUS LINK-BREED
example: ask one-of bankers [ show other bankers network:in-link-radius 5 friendships ]
Returns the set of turtles within the given distance (number of links followed) of the calling turtle. Searches breadth-first from the calling turtle, following links of the given link breed.
The in-link-radius
form works with undirected links. The other two
forms work with directed links; out
or in
specifies whether links
are followed in the normal direction (out
), or in reverse (in
).
network:link-distance TURTLE LINK-BREED
example: ask one-of-bankers [ show network:link-distance the-best-banker friendships ]
Finds the distance to the destination turtle (number of links followed). Searches breadth-first from the calling turtle, following links of the given link breed.
Reports false if no path exists.
network:link-path TURTLE LINK-BREED
network:link-path-turtles TURTLE LINK-BREED
example: ask banker1 [ show network:link-path banker3 friendships ]
-> [(link 1 2) (link 2 3)]
example:ask banker1 [ show network:link-path-turtles banker3 friendships ]
-> [(banker 1) (banker 2) (banker 3)]
Reports a list of turtles or links following the shortest path from the calling turtle to the destination turtle.
Reports an empty list if no path exists.
If network:link-path-turtles
is used, the calling turtle and the
destination are included in the list.
Searches breadth-first from the calling turtle, following links of the given link breed.
Follows links at the same depth in random order. If there are multiple shortest paths, a different path may be returned on subsequent calls, depending on the random choices made during search.
network:mean-link-path-length TURTLE-SET LINK-BREED
Reports the average shortest-path length between all distinct pairs of nodes in the given set of turtles, following links of the given link breed.
Reports false unless paths exist between all pairs.
The primitives in this extension were present in NetLogo 4.1, but with different names. They were renamed as follows:
__network-distance
tonetwork:link-distance
__in-network-radius
tonetwork:in-link-radius
,network:in-out-link-radius
,network:in-in-link-radius
__average-path-length
tonetwork:mean-link-path-length
__network-shortest-path-links
tonetwork:link-path
__network-shortest-path-nodes
tonetwork:link-path-turtles
The following primitives, present in NetLogo 4.1 but not NetLogo 5.0, are not included in this extension either:
__create-network-preferential
__layout-magspring
__layout-quick
__layout-sphere
For the source code for these primitives, see this commit. But note they are written in the style used by built-in NetLogo primitives. To be brought back to life, they'd need to be changed to use the extensions API instead.
Run the bin/sbt
script to build the extension.
If the build succeeds, network.jar
is created.
The first versions of these primitives were written by Forrest Stonedahl.
The NetLogo network extension is in the public domain. To the extent possible under law, Uri Wilensky has waived all copyright and related or neighboring rights.