Environment search

Author: Lukas Breitwieser
In this tutorial we will show how to execute a function for each neighbor of an agent.

Let's start by setting up BioDynaMo notebooks.

We create three agents in a row along the x-axis with identical y and z values.

We finalize the initialization and update the environment so it can be used later. Please not that this is usually done automatically inside Scheduler::Simulate.

Let's define the function that we want to execute for each neighbor. It prints the unique id of the neighbor and its distance from the querying agent.

The agents have the following ids (in order of increasing x-value) 0-0, 1-0, 2-0

We start by executing print_id_distance for the first agent. We ask for all neighbors within distance 101. Therefore the function should be executed for the agent in the middle with id 1-0

Let's repeat the experiment for the middle agent. We expect to see two lines for the left and right neighbor.

Lastly, we want to execute the function print_id_distance for all neighbors of the righ-most agent. We expect to see one line printing the middle agent as neighbor (1-0)