我正在NetLogo中模拟行人的运动,并且在从头开始创建避障算法时遇到了困难。网上有算法,但它们不适合移动障碍物(其他行人)。此外,我的经纪人正在从他们的产卵点(A点)转移到他们的目标(B点)。
这是我的NetLogo算法:
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
此模拟的模拟环境是一个交叉点:
http://imgur.com/nQzhA7g,R5ZYJrp#0
(对不起,我需要10名代表才能发布图片:()
图1显示了设置后的环境状态。图2显示了代理移动到他们的目标(目标!=他们的产卵点)后会发生什么。面对不同方向的特工显示了那些穿过中心杂乱特工的特工,现在正朝着目标前进的特工。然而,由于我的算法,中心的代理被困在那里。当有更多数量的代理时,模拟就更有问题了,这意味着它们只会在环境的中心杂乱无章,在移动时会断断续续。
我的算法基于
http://files.bookboon.com/ai/Vision-Cone-Example-2.html
。原谅我的算法,我一周前开始在NetLogo中编程,直到现在我仍然没有在其中编程的正确心态。我相信有更好的方法来实现我心中的想法,但遗憾的是,我在尝试许多我脑海中的实现时感到沮丧(但从未接近真实的东西)。
附言:这是我在StackOverflow的第一篇帖子/问题!我希望我的问题(以及我的提问方式)不会太糟糕。