LazyAgentset - NetLogo/NetLogo GitHub Wiki

What is it?

LazyAgentSet is a lazy implementation of NetLogo's AgentSet. It keeps track of others and withs called on it, and lazily filters them out when needed. It would potentially replace the current system of essentially hard-coding specific optimizations for compounded filter cases (e.g. otherwith, countotherwith, etc) as well as cover other cases currently not accounted for (e.g. withwith).

Assumptions

  1. agents only accessed after force
  2. agents only modified by side-effects of filters within force
  3. agents that pass filters are immediately included in the resulting AgentSet
  4. filters don't change between calls to hasNext
  5. once a lazy agent set is forced, it will never need to be forced again.

Design Choices

  • LazyAgentSet's underlying data structure for storing agents is an ArrayAgentSet (as opposed to holding an array like ArrayAgentSet)
  • LazyAgentSet stores other and withs to be lazily forced later
  • assume other is always a single agent or null
  • use java.util.ArrayList to store other and withs
  • Add getArray to AgentSet so LazyAgentSet has access to its underlying ArrayAgentSet's array of agents
  • Pass RNG to random methods
  • Random functions and toLogoList force
  • Count, iterator, and shufflerator do not force
  • force at Statement boundaries for semantics

Results

As evident from numerous benchmarks, LazyAgentSet performs significantly worse for some benchmark models. Part of this is due to the necessary overhead of repeatedly generating and managing an extra layer of lazy abstraction. For a simple baseline comparison between the two, a simple Benchmark was run on both branches:

globals [result]

to setup
  clear-all
  crt 10000
end

to go
  ask turtles with [heading < 90] with [heading > 270] []
end

to benchmark
  random-seed 1
  reset-timer
  setup
  repeat 100 [ go ]
  set result timer
end

LazyAgentSet was marginally faster with 0.087 compared to hexy's 0.089.

Agentset-Involved Primitives Table

primitive name can / should return lazy agentset can / should accept lazy agentset
any? N/A yes
count N/A yes
oneof N/A yes
with yes yes
other yes yes
n-of no yes
member N/A yes
with-max no can (no speedup)
with-min no can (no speedup)
all? N/A can (no speedup)
in-cone can (maybe shouldn't?) can (maybe shouldn't?)
in-radius can (maybe shouldn't?) can (maybe shouldn't?)
at-points can (maybe shouldn't?) can (maybe shouldn't?)
max-one-of N/A can (no speedup)
max-n-of no can (no speedup)
min-one-of N/A can (no speedup)
min-n-of no can (no speedup)
sortby N/A can (no speedup)
sorton N/A can (no speedup)
turtlesat no N/A
mylinks no N/A
inlinkneighbors no N/A
links no N/A
nolinks no N/A
outlinkneighbors no N/A
noturtles no N/A
neighbors4 no N/A
myoutlinks no N/A
turtleson no N/A
turtles no N/A
turtleshere no N/A
nopatches no N/A
linkneighbors no N/A
linkset no N/A
turtleset no N/A
myinlinks no N/A
patchset no N/A
neighbors no N/A
patches no N/A
bothends no N/A
word no N/A
askconcurrent N/A no
of N/A no
createlinksto N/A no
sort N/A no
layouttutte N/A no
layoutradial N/A no
createlinksfrom N/A no
layoutspring N/A no
setdefaultshape N/A no
list N/A no
run N/A no
runresult no no
layoutcircle N/A no
sentence N/A no
createlinkswith N/A no
ask N/A no

Recommendations

To best help further LazyAgentSet's development, next steps might include setting up a Netlogo LazyAgentSet Extension as well as making code optimizations to improve performance to its full potential.

⚠️ **GitHub.com Fallback** ⚠️