【问题标题】:Make turtles finish between 2 elements in NetLogo使海龟在 NetLogo 中的 2 个元素之间完成
【发布时间】:2018-02-28 13:45:57
【问题描述】:

我是 NetLogo 的新手,我正在尝试模拟一组海龟必须从一个随机空间移动到目标点和墙壁之间,但到目前为止,我刚刚检索了一个代码让它们在目标点周围的各个方向放置自己(海龟有能力相互交谈)。

但是,我无法让它们向一侧完成...有什么提示吗?

非常感谢

【问题讨论】:

  • 您能否在您的第一张图片的上下文中进一步解释一下您所说的“在球门点和墙壁之间”是什么意思?我假设墙是顶部的蓝线,但目标点在哪里,你想让乌龟去哪里?
  • 感谢您的回复卢克!目标点将是第一张图像中的绿色补丁,因此海龟将随机放置在 max-pxcor 和 max-pycor 周围,目标是它们向“安全区域”移动,在这种情况下,它将位于顶部之间蓝线(墙)和“目标点”(绿色补丁),在我的模拟中,它们代表他们被标记为“安全”的点(将其视为他们必须排队才能离开的紧急出口)。现在的问题是,只有不到一半的海龟会被标记为安全。感谢您的帮助!

标签: netlogo


【解决方案1】:

我不确定您是否仍然想让它们聚集在目标点周围,或者只是移动到目标点上方。这是一种可以得到你想要的东西的方法。它定义了一个目标点和一组安全补丁。目标点下方的海龟试图通过目标点到达安全区域。 cmets中的更多详细信息/解释

设置:

globals [ goal-spot safe-patches ]

to setup
  ca
  ;   Set the wall
  ask patches with [ pycor = max-pycor ] [ set pcolor blue ]

  ;  Set the goal-patch
  set goal-spot patch 0 0
  ask goal-spot [ set pcolor green ]

  ;     Set up a triangular safe-patches zone
  let check ( [pycor] of goal-spot - [pxcor] of goal-spot ) - 1
  let gpx [pxcor] of goal-spot
  set safe-patches patches with [
    pycor > [pycor] of goal-spot and
    pycor < max-pycor and
    ( ( pxcor < gpx and pycor + pxcor > check ) or
      ( pxcor >= gpx and pycor - pxcor > check ) ) ]

  ;  Make some turtles
  let n-turtles 255
  if n-turtles > count safe-patches [
    set n-turtles count safe-patches 
  ]
  crt n-turtles [
    set shape "person"
    set color green
    move-to one-of patches with [ pycor < [pycor] of goal-spot and pycor < max-pycor]
    if pycor <= [pycor] of goal-spot [
      set color red
    ]
  ]
  ask turtles [pd]
  reset-ticks
end

运动:

to go
  ;   Any turtles that are not on the safe spot, or share a patch
  ask turtles with [not member? patch-here safe-patches or any? other turtles-here] [
    let target nobody

    ;     If below the goal spot, target it. If not, target a free safe patch
    ifelse pycor < [pycor] of goal-spot [
      set target goal-spot
    ] [
      set target min-one-of ( safe-patches with [ 
        not any? other turtles-here ] ) [distance myself
      ]
    ]

    ;     Face target, move to it.
    if target != nobody [
      face target
      move-to patch-ahead 1
    ]
  ]

  ;  Stop when all turtles are safe and on their own patch
  if not any? turtles with [ 
    not member? patch-here safe-patches or
    any? other turtles-here 
  ] [
    stop
  ]

  tick
end

希望这能让你开始!

行为示例:

编辑

根据您的评论-是的,您可以这样做。当然有很多方法可以解决这个问题,但实际实现会根据您的实际模型和意图等而改变。例如,这里有一个使用两个安全区域的修改:

globals [ goal-spots safe-patches ]

to setup
  ca

  ;   Set the walls
  ask ( patch-set 
    patches with [ pycor = max-pycor ] 
    patches with [ pxcor = max-pxcor ] 
    )
    [
    set pcolor blue
  ]

  let possible-safe patches with [ pcolor = black ]

  ;     Set up two triangular safe-patches
  crt 1 [
    set heading 0 
    fd 7 
    set goal-spots patch-here
    set safe-patches possible-safe in-cone 20 90
    set heading 90
    setxy 7 0
    set goal-spots ( patch-set goal-spots patch-here )
    set safe-patches ( 
      patch-set 
      safe-patches 
      possible-safe in-cone 20 90 ) 
    die
  ]

  ask safe-patches [
    set pcolor green - 4
  ]

  ;  Make some turtles
  let n-turtles 100
  if n-turtles > count safe-patches [
    set n-turtles count safe-patches
  ]
  crt n-turtles [
    set shape "person"
    set color green
    move-to one-of patches with [ pycor < 0 and pxcor < 0 ]
    set color red
  ]
  ask turtles [pd]

  reset-ticks
end


to go
  ;   Any turtles that are not on the safe spot, or share a patch
  ask turtles with [not member? patch-here safe-patches or any? other turtles-here] [
    let target nobody

    ;     If below the goal spot, target it. If not, target a free safe patch
    ifelse not member? patch-here safe-patches [
      set target min-one-of goal-spots [ distance myself ]
    ] [
      set target min-one-of ( safe-patches with [
        not any? other turtles-here ] ) [distance myself
      ]
    ]

    ;     Face target, move to it.
    if target != nobody [
      face target
      move-to patch-ahead 1
    ]
  ]

  ;  Stop when all turtles are safe and on their own patch
  if not any? turtles with [
    not member? patch-here safe-patches or
    any? other turtles-here
  ] [
    stop
  ]

  tick
end

请注意,这只是一种存在明显问题的方法的简单示例(例如,如果您在一块土地上有太多海龟,即使在满了)。我想说,如果你能以某种方式定义你的两个安全区域然后遇到问题,那么值得发布一个新问题来弄清楚如何解决你遇到的任何新问题。

【讨论】:

  • 这绝对让我入门,非常感谢!!最后一个问题,如果我有 2 个球门补丁而不是 1 个(比如一个在顶部的墙壁,另一个在右侧的墙壁),您是否会对目标点执行所有指令两次(例如一次与目标 -点 1 和另一个目标点 2)或者有没有其他方法可以做某种“for”循环? (例如:首先将目标补丁设置为绿色,然后 {set goal-spot (patches with [pcolor = green])} 然后对目标点中的补丁运行相同的指令?)。
  • @Arduino - 我已经对我的答案做了一些补充 - 看看!
猜你喜欢
  • 2014-04-19
  • 2020-08-09
  • 1970-01-01
  • 2016-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-08
相关资源
最近更新 更多