Implementing StarLogo: diffusion
May 31 2021 07:01
This is trickier than I thought. Here is a fragment of StarLogo code:
to patch-setup
activate-demon [evaporation-demon diffusion-demon]
end
to evaporation-demon
set-pheromone peromone * 0.9
end
to diffusion-demon
diffuse pheromone
end
StarLogo specifies simulations in terms of turtles - mobile agents - and patches - fixed pieces of ground. Turtles and patches can have properties and can execute code. Demons are procedures that, once activated, execute repeatedly and concurrently for each patch (or turtle, but in the example above, only two patch demons have been activated.)
So the intent of the code above is that a patch of ground may have had some pheromone deposited on it, and that the pheromone both evaporates and diffuses to neighboring patches (‘diffuse’ is a StarLogo primitive.)
StarLogo simulations should be thought of as massively parallel: each demon runs on each of their subjects simultaneously and in lock-step. All the patches are subject to evaporation and diffusion at the same time. That is woefully underspecified: in this simulation, does evaporation happen first, and some of the remaining pheromone diffuses? Or vice versa? Or do evaporation and diffusion occur in chance order for different patches? And does the amount diffusing in participate in the evaporation and diffusion in the current step?
For that last question, I decided on the classic Conway Game of Life solution: the current step changes a new copy of the world. The amount diffusing in doesn’t affect the current step. That leaves the question of the order of diffusion and evaporation. Since the simulation is intended to be qualitative and exploratory, I decided it doesn’t matter.
For simplicity, the demons will be executed in the order in which they were activated; each demon will run on each of its subjects before the next demon is run. Demons will operate on a copy of the world, and the final results will be copied back. That means that diffusion, for example, is calculated on the current stock of pheromone, and the results of all diffusing out and diffusing in are summed into a ’next’ array and then copied back.
It might be interesting to experiment with different implementation choices (for example, always work on the current world, so that the order in which patches are processed impacts the final result, or allow the demons to interleave) and see if there is much differece in the progression of the simulation. I wish I knew the mathematics needed to make predictions about the effects of these choices. There must be “process models” or reasoning techniques for such things?