【问题标题】:Netlogo how to ask turtles wait until others turtles more than a specific distanceNetlogo如何问乌龟等到其他乌龟超过特定距离
【发布时间】:2020-05-14 22:20:48
【问题描述】:

我正在尝试在 Netlogo 中编写代码,让海龟等待一定时间(例如:2 秒),如果他的邻居小于一定距离。当他和他的邻居之间的距离超过那个距离后,这只乌龟就可以开始移动了。这是我的代码:

我对海龟的初始设置:

;;send people back to where they come from
  ask turtles [
    move-to one-of road with [not any? other turtles in-radius 4]
  ]

让海龟移动:

  to move
           face best-way-to goal
           ifelse patch-here != goal
            [ 
              ifelse how-close < 2
              [wait 2 fd 1]
              [fd 1]
            ]
            [stop]
    end

to-report keep-distance
   set close-turtles other turtles-on (patch-set patch-here neighbors4)
   ifelse any? close-turtles
       [set how-close distance min-one-of close-turtles [distance myself]]
       [set how-close 100] ;this means cannot find neighbours around this people
   report how-close
end

但这并没有给我想要的东西。有人知道如何在 Netlogo 中实现这一点吗?任何帮助真的很感激。谢谢!

【问题讨论】:

    标签: netlogo agent-based-modeling


    【解决方案1】:

    使用wait的问题是模型会暂停,所以其他的海龟也不动,也走不开。如果你想让乌龟只有在没有人靠近时才移动,请尝试替换:

    to move
      face best-way-to goal
      ifelse patch-here != goal
      [ 
        ifelse how-close < 2
        [wait 2 fd 1]
        [fd 1]
      ]
      [stop]
    end
    

    to move
      face best-way-to goal
      if patch-here != goal and how-close >= 2
      [ forward 1
      ]
    end
    

    也就是说,您不需要ifelse 构造,您可以使用if 并且仅在条件适合移动时才移动。

    【讨论】:

    • 非常感谢您的回复。但是当我将您的代码粘贴到 Netlogo 中时,海龟就不再前进了。我想这是因为他们之间的距离最初小于2所以他们不会走路?你对此有什么想法吗?谢谢!
    • 如果 how-close 以
    • 谢谢!我已经修改了我的问题并在我的代码中添加了海龟设置。所以理论上海龟应该在半径4内没有人发芽?但我运行代码仍然没有移动。这有助于解释我的问题吗?
    • (1) 请将此问题设为新问题。 (2) 当你这样做时,包括调用保持距离过程的代码,以及如何接近是乌龟还是全局变量
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多