I simulate pedestrian traffic in NetLogo, and I'm having trouble creating an algorithm to avoid obstacles from scratch. There are algorithms online, but they are not suitable for moving obstacles (other pedestrians). In addition, my agents move from their appearance point (point A) to their target (point B).
This is my NetLogo algorithm:
globals [ wall walkway center dest ] turtles-own [ gender goal velocity spawnpoint mid turn ] to setup clear-all ask patches[ set wall patches with [ (pxcor > 3 and pycor > 3) or (pxcor < -3 and pycor > 3) or (pxcor < -3 and pycor < -3) or (pxcor > 3 and pycor < -3) ] set walkway patches with [ (pxcor > -4 and pxcor < 4) or (pycor > -4 and pycor < 4) ] set center patch 0 0 ] ask patches [ set pcolor black ] ask walkway [ set pcolor 9 ] crt population [ set velocity 0.1 set mid 0 set gender random 2 if gender = 0 [set color red] if gender = 1 [set color blue] set spawnpoint random 4 if spawnpoint = 0 [ move-to one-of walkway with [not any? turtles-here and (pxcor < -11)]] if spawnpoint = 1 [ move-to one-of walkway with [not any? turtles-here and (pycor > 11)]] if spawnpoint = 2 [ move-to one-of walkway with [not any? turtles-here and (pxcor > 11)]] if spawnpoint = 3 [ move-to one-of walkway with [not any? turtles-here and (pycor < -11)]] set goal random 4 while [ goal = spawnpoint ] [ set goal random 4 ] if spawnpoint != 0 and goal = 0 [set goal patch -16 0] if spawnpoint != 1 and goal = 1 [set goal patch 0 16] if spawnpoint != 2 and goal = 2 [set goal patch 16 0] if spawnpoint != 3 and goal = 3 [set goal patch 0 -16] ] reset-ticks end to decelerate ifelse velocity > 0.01 [ set velocity velocity - 0.01 ] [ rt 5 ] end to accelerate if velocity < 0.1 [ set velocity velocity + 0.01 ] end to go ask turtles [ ifelse patch-here != goal[ set turn random 2 if distance center < 3 [ set mid 1] if mid = 0 [ set dest center ] if mid = 1 [ set dest goal ] face dest ifelse any? other turtles-on patches in-cone 1.5 60 [ if any? other turtles-on patches in-cone 1.5 60 [ bk velocity rt 90 ] ] [ accelerate face dest fd velocity ] ] [ die ] ] end
The simulated environment of this simulation is the intersection:
http://imgur.com/nQzhA7g,R5ZYJrp#0
(sorry, I need 10 rep to post images :()
Figure 1 shows the state of the environment after installation. Figure 2 shows what happens after the agents move to their goal (target! = Their point of occurrence). Agents facing different directions show agents who have made their way through the disorder of agents in the center and are now on their way to their goal. However, the agents in the center are stuck due to my algorithm. Modeling is more problematic when there are more agents, which means that they will simply interfere in the center of the environment and just stutter when moving.
I based my algorithm on http://files.bookboon.com/ai/Vision-Cone-Example-2.html . Forgive my algorithm, I started programming in NetLogo a week ago, and still I still do not have the proper thinking in programming. I am sure that there is a better way to implement what I mean, but, alas, I am disappointed with the attempt of many implementations that came to my mind (but did not come close to the real thing).
PS: This is my first post / question on StackOverflow! Hope my question (and my question) is not bad.
source share