4

我在 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 中编程,直到现在我仍然没有正确的心态来编程。我确信有更好的方法来实现我的想法,但是我在尝试许多我想到的实现时感到沮丧(但从未接近真实的东西)。

PS:这是我在 StackOverflow 中的第一篇文章/问题!我希望我的问题(以及我的提问方式)还不错。

4

1 回答 1

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基本上没用。

于 2013-04-13T16:02:57.140 回答