有没有办法在NetLogo中创建无法逾越的障碍? [英] Is there a way to create impassable barriers in NetLogo?

查看:410
本文介绍了有没有办法在NetLogo中创建无法逾越的障碍?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一种寻路行为,其中代理将在环境中定位一个最佳补丁,并沿着围栏导航以到达所述补丁.我创建了一个补丁变量'f',将其设置为1表示围栏,将其设置为0表示其他任何补丁.

我想使这些围栏无法通行(即我希望它们成为特工不会使用的补丁),但是特工似乎仍然能够在一定程度上行进,甚至在某些情况下甚至能够完全移动穿过他们.

这是特工越过障碍物的图片,我不希望它越过

代理商的相关决策代码如下:

{let moveset patches in-radius 30 with [f = 0 and n > 0]

let target max-one-of moveset [n]

 ifelse patch-here != target 
 [ 
  set heading towards target

  ]
 []

let chance random-float 10
if chance >= 5 [let pick -145]
if chance < 5 [let pick 145] 

ask patches in-radius 1 
[if f = 1 
[ask myself

  [set heading towards min-one-of patches [distance myself] + 180 - random 10 + random 10 ]

]
]

fd 1}

为清楚起见,"n"只是一个变量,表示我想让我的经纪人定位并冒险前往的补丁.

有人知道NetLogo中一种简单的方法来将某些补丁排除为决策过程中可行的移动区域(即硬障碍)吗?

解决方案

如果还没有,请看看模型库中的向前看"示例-这是使用色块颜色控制乌龟的简单演示.移动.下面是基于该模型的一些代码.使用此设置:

breed [ seekers seeker ]
breed [ goals goal ]
patches-own [ steps-from-goal ]

to setup
  ca
  ask patches [ 
    set steps-from-goal 999
  ]
  ask patches with [ pxcor mod 10 = 0 ] [
    set pcolor red
  ]
  ask patches with [ pycor mod 10 = 0 ] [
    set pcolor black
  ]
  ask one-of patches with [ pcolor = black ] [
    sprout-seekers 1 [
      set color blue
      pd
    ]
  ]
  ask one-of patches with [ pcolor = black ] [
    sprout-goals 1 [
      set color white
      set shape "circle"
    ]
  ] 
  reset-ticks
end

您可以让seekers品种在黑色方块周围徘徊,直到它们与goal乌龟共享一个斑块为止:

to random-wander 
  ask seekers [
    if any? goals-here [
      stop
    ]
    rt random 61 - 30
    ifelse can-move? 1 and [pcolor] of patch-ahead 1 = black [ 
      fd 1
    ] [
      rt one-of [ 90 -90 ]
    ]
  ]
  tick
end

但是,请注意,乌龟仍然可以使用此方法跳动"斑块的角,因为它们能够以任意角度评估patch-ahead 1-因此,可以在角点处评估海龟前方一个空格的斑块另一个补丁.乌龟绝对不应该落在禁止的斑块上,但是您可能会注意到它们的路径可以穿越那些被阻止的斑块.

请参见在方形笼子中困住"乌龟的简化代码:

to setup
  ca
  crt 1 [ 
    setxy 5 5
    set heading 180
    repeat 4 [
      repeat 10 [
        ask patch-here [ set pcolor red ]
        fd 1 
      ]
      rt 90
    ]
    die
  ]

  crt 1 [ pd ]
  reset-ticks
end

to go
  ask turtles [
    rt random 61 - 30
    ifelse can-move? 1 and [pcolor] of patch-ahead 1 = black [
      fd 1
    ] [
      rt one-of [ 90 -90 ]
    ]
  ]
  tick
end

1100次滴答之后:

13300次滴答之后:

I am attempting to code a path-finding behavior wherein agents will locate an optimal patch in the environment and navigate their way around fences to reach said patch. I've created a patch variable 'f', which is set to 1 to indicate fences and 0 for any other patch.

I want to make these fences impassable (i.e. I want them to be patches the agents will not use for movement), but agents still seem to be able to travel on them to some extent and in some cases are even able to fully cross them.

Here is a picture of an agent crossing a barrier I don't want it to cross

Relevant decision-making code for the agents is as follows:

{let moveset patches in-radius 30 with [f = 0 and n > 0]

let target max-one-of moveset [n]

 ifelse patch-here != target 
 [ 
  set heading towards target

  ]
 []

let chance random-float 10
if chance >= 5 [let pick -145]
if chance < 5 [let pick 145] 

ask patches in-radius 1 
[if f = 1 
[ask myself

  [set heading towards min-one-of patches [distance myself] + 180 - random 10 + random 10 ]

]
]

fd 1}

For clarity, 'n' is simply a variable to denote the patch I want my agent to locate and venture to.

Is anyone aware of a simple way in NetLogo to exclude certain patches as viable zones for movement in the decision making process (i.e. hard barriers)?

解决方案

If you haven't yet, have a look at the "Look Ahead" example in the Models Library- it's a simple demonstration of using patch color to control turtle movement. Some code based on that model is below. With this setup:

breed [ seekers seeker ]
breed [ goals goal ]
patches-own [ steps-from-goal ]

to setup
  ca
  ask patches [ 
    set steps-from-goal 999
  ]
  ask patches with [ pxcor mod 10 = 0 ] [
    set pcolor red
  ]
  ask patches with [ pycor mod 10 = 0 ] [
    set pcolor black
  ]
  ask one-of patches with [ pcolor = black ] [
    sprout-seekers 1 [
      set color blue
      pd
    ]
  ]
  ask one-of patches with [ pcolor = black ] [
    sprout-goals 1 [
      set color white
      set shape "circle"
    ]
  ] 
  reset-ticks
end

You can have the seekers breed wander around the black squares until they share a patch with a goal turtle:

to random-wander 
  ask seekers [
    if any? goals-here [
      stop
    ]
    rt random 61 - 30
    ifelse can-move? 1 and [pcolor] of patch-ahead 1 = black [ 
      fd 1
    ] [
      rt one-of [ 90 -90 ]
    ]
  ]
  tick
end

However, note that turtles can still 'jump' corners of patches using this method, because they are able to assess the patch-ahead 1 at any angle- so, a patch one space ahead of a turtle may be assessed across the corner of another patch. The turtle should never actually land on the forbidden patch, but you may notice that their path can cross those blocked patches.

Edit:

See simplified code that "traps" a turtle in a square cage:

to setup
  ca
  crt 1 [ 
    setxy 5 5
    set heading 180
    repeat 4 [
      repeat 10 [
        ask patch-here [ set pcolor red ]
        fd 1 
      ]
      rt 90
    ]
    die
  ]

  crt 1 [ pd ]
  reset-ticks
end

to go
  ask turtles [
    rt random 61 - 30
    ifelse can-move? 1 and [pcolor] of patch-ahead 1 = black [
      fd 1
    ] [
      rt one-of [ 90 -90 ]
    ]
  ]
  tick
end

After 1100 ticks:

After 13300 ticks:

这篇关于有没有办法在NetLogo中创建无法逾越的障碍?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆