Pinned Project Overview Post

Project Overview

Introduction There have been numerous researches conducted for the development of algorithms that can be used for environment exploration an...

Tuesday, September 12, 2023

[Post :09] NetLogo Simulation Progress Part - 2

In addition to the links I shared in the previous post, I found this super useful document to learn about NetLogo programming. 

In the simulation, I managed to implement the following behaviors in the agents. In my simulation, I refer to agents as bots. The bots are capable of doing the following tasks,

  • Can detect if the target enters into the vision range
  • Can calculate freedom (what freedom is that?)
  • Can detect the agent with maximum freedom in the local region
  • Can follow a specific bot
  • Can avoid colliding with obstacles in the environment
  • Can detect the edges of the world and turn around 
Let me tell you what each of the mentioned features does and how I managed to implement them.

Detecting targets in the vision range
Before detecting the target, we need to specify the vision range of the bot. The vision range is going to be a circular region around the bot. This is implemented by using the 'in-radius' primitive. The primitive requires the radius as a parameter. in the code, it looks something like this.


Visual representation of the code


The good thing with NetLogo is it is easy to understand written code. The bad thing is it is not easy to write the code to do something I want as it is required to format it to comply with NetLogo rules.

A GUI slide is added to the main interface named 'vision-distance' so that it can be used to adjust and fine-tune the radius value for best performance



Calculating freedom
The algorithm uses a value called 'freedom score' to identify the amount of free space a bot has in its local environment to move around. Whenever there are other agents in the local area, they use this value to decide whether they need to follow someone or move on their own. While it is best to use proximity sensor reading for this purpose which gives a distance value, in NetLogo, a primitive called 'neighbors' is used. This primitive reports the 8 patches around the agent. (The floor area in NetLogo is divided into patches). Accordingly, if there is an obstacle in the neighborhood with the color yellow, it causes the freedom value to be reduced by 1 unit 

Visual representation of freedom score and an example where freedom = 5

Once the freedom score is calculated, in order to convey this score to others, agents use their color. While the base color of a bot is green, depending on the freedom, this color takes different shades. Accordingly, if an agent has maximum freedom of 8, its color is a brighter green. Any agent with a freedom score of 5 or lower will take a darker shade of green. The color representations are as follows,




Obstacle avoidance and world edge detection
The obstacles in the environment are represented in yellow color. Hence agents check for any yellow color patches in front of it in a cone-shaped vision range. To detect the edges of the world, agents use a primitive called 'patch-ahead'. While this primitive reports the patch matches the filtering criteria, it reports the 'nobody' value if the patch being checked lies outside the world edge. In both cases, the agent takes a random maneuver to avoid moving forward and hitting an obstacle or edge.


Following an agent

3 rules are enforced to be followed by agents when following another. 
  • The distance between 2 agents should not exceed a maximum value
  • The distance between 2 agents should not be below a minimum value
  • A cone-shaped region in front of the agent should be empty
These 3 rules combined with freedom score logic, make the whole swarm split into several groups and explore different regions. This helps to explore the area much quicker.

In order to interact with the simulation area, additional procedures are to be developed. These procedures will give the user to ability to place or remove bots on the floor using a mouse, add/remove obstacles, save or load an obstacle map, etc. I will post another article with that information.



Sunday, September 3, 2023

[Post :08] NetLogo Simulation Progress

When you open the NetLogo, The first interface you see is the simulation area. In order to access the coding area you need to click on the 'code' tab which is located just under the menu bar.

There are 5 types of entities in the NetLogo world; Obsever, Turtles, Patches, Links, and Utilities. All the built-in functions (they are called primitives) fall under one of the five mentioned above. Click on this link to go to the interactive primitives dictionary of NetLogo. Before jumping right into the coding just like me and getting frustrated, I recommend you to refer to these 3  links; What is NetLogo?What is a primitive?The first 11 primitives to learn  

Compared to programming in a language like Java, there are differences in building simulations in NetLogo. The main difference I noticed is instead of curly brackets, square brackets are being used when using conditionals. When using the keyword 'self', we are not referring to the turtle itself, but to the turtle, we are asking something to do. To refer to the agent itself the keyword 'myself' should be used. 
The best thing is, that whenever I place a button or a slider in the GUI area, I can refer to their values simply by mentioning the name of the element. 
There are several other important things to keep in mind when dealing with NetLogo programs I noticed so far (There should be more) but those can be found in the interactive dictionary.  

NetLogo refers to the agents in the simulations as turtles. If I need only one type of agent, I can simply go with the turtles. However, I need two types of agents in the simulation. In my case the bots who do the searching and the target which is being searched for. So need to create two types of turtles. I can do this by using 'breed' primitive. For each of these types, I can assign features and their own variables which will be used during the simulation. 

Here is the very first NetLogo program I created after hours of experimenting by myself and then going through the documentation. (There are some additional GUI elements as I am experimenting now) It simply creates 2 types of breeds. As of now the bots will just spawn in random places in the environment and move forward. The target stays in the middle. No goal detection or any other logic is implemented as of now.




Friday, September 1, 2023

[Post :07] Starting with NetLogo

 When I first saw the NetLogo program, my first impression was not a good one. Because it looks so old. But then I saw the simulations that have been developed using it I changed my mind. Once you install NetLogo, all these simulations are also going to be available under File-> Models Library (Ctrl+M).

NetLogo Interface


If installing NetLogo is not an option, it is possible to use the online version of NetLogo in the browser as well. Click this link to access the web version.


One feature that made me like NetLogo is the scripting language that needs to be used to develop the models (Initially I was trying to develop a simulator just for my simulation from scratch using Python. So I knew how hard it is to create a fully functioning simulator). When I was reading the code, it was almost reading like a sentence written in English. Because each word explained what it was supposed to do. Check the following sample line which can be used to find if there is a target around a specific agent.

So developing a model to simulate my algorithm is going to be far less complicated than I expected.
(PS: I was wrong)