我正在模拟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进行编程,直到现在我仍然没有正确的编程心态。我确信有更好的方法来实现我的想法,但是我很沮丧地尝试了许多我想到的实现(但从未接近真实的实现)。
P.S:这是我在StackOverflow中的第一篇帖子/问题!我希望我的问题(以及我的提问方式)也不错。
答案 0 :(得分:1)
这是我能提出的最简单的工作版本:
turtles-own [ goal dest velocity ]
to setup
clear-all
let walkway-color white - 1
ask patches [
set pcolor ifelse-value (abs pxcor < 4 or abs pycor < 4) [ walkway-color ] [ black ]
]
let goals (patch-set patch -16 0 patch 0 16 patch 16 0 patch 0 -16)
ask n-of population patches with [ pcolor = walkway-color and distance patch 0 0 > 10 ] [
sprout 1 [
set velocity 0.1
set color one-of [ red blue ] ; representing gender
set dest patch 0 0 ; first head towards center
set goal one-of goals with [ distance myself > 10 ]
]
]
reset-ticks
end
to go
ask turtles [
if patch-here = goal [ die ] ; the rest will not execute
if dest = patch 0 0 and distance patch 0 0 < 3 [ set dest goal ]
face dest
if-else any? other turtles in-cone 1.5 60
[ rt 5
bk velocity ]
[ fd velocity ]
]
tick
end
除了我完全重写了您的设置程序之外,它与您自己的版本没有什么不同。我认为你的主要问题是在转向之前支持:因为你face dest
在下一个go
周期开始时再次rt
,你的{{1}}基本没用。