Netlogo 指定特定方向上的邻居

Netlogo 指定特定方向上的邻居,netlogo,patch,direction,rate,Netlogo,Patch,Direction,Rate,我正在尝试为海龟创建一个移动到邻近区域的速率模型。最终,我希望海龟,在一定条件下,孵化出8只潜在的其他海龟,每只海龟都能根据自己的方向,专门前往它们的一个邻居。基本上,我想将相邻面片指定为北邻、南邻、东邻、西邻、西北邻,等等。从那时起,我想让每只海龟都移动到一个特定的补丁。每个斑块变量有8个移动速率:向北移动速率、向南移动速率,依此类推。所以我想让这8只海龟以他们邻居的速度移动到他们的特定区域。在它到达其北邻居的中心后,我希望北邻居变量重置,以便新的北邻居是旧的北邻居的北邻居。下面是一个只指定N

我正在尝试为海龟创建一个移动到邻近区域的速率模型。最终,我希望海龟,在一定条件下,孵化出8只潜在的其他海龟,每只海龟都能根据自己的方向,专门前往它们的一个邻居。基本上,我想将相邻面片指定为北邻、南邻、东邻、西邻、西北邻,等等。从那时起,我想让每只海龟都移动到一个特定的补丁。每个斑块变量有8个移动速率:向北移动速率、向南移动速率,依此类推。所以我想让这8只海龟以他们邻居的速度移动到他们的特定区域。在它到达其北邻居的中心后,我希望北邻居变量重置,以便新的北邻居是旧的北邻居的北邻居。下面是一个只指定North neighbor的代码示例(我计划对North neighbor、South neighbor等使用单独的过程)

patches-own[I-b-N heat-sink-N ROM-N ROM-S]  

to setup[
 ca
 reset-ticks
 crt 1 [
  set shape "triangle"
  set color red
  ]
 ask patches[
  set pcolor green
  set ROM-N 5
  set ROM-S 6 ;here there would be ROS-N ROS-S ROS-E ... for each patch
  set I-b-N 8
  set heat-sink-N 2
  ]
]  

to go
 spread-north
 ;spread-south
 tick
end

to spread-north ;duplicate and modify the same procedure for south, east, west,...
      ask turtles [
        if xcor = [pxcor] of patch-here and ycor = [pycor] of patch-here[
          set N-neighbor [patch-at-heading-and-distance 0 1] of self]
      ]
      ask turtles[ ;I use two ask turtles to make sure N-neighbor is created at the beginning of the procedure
        let goal N-neighbor ;here to store N-neighbor
        let parent patch-here
         if [I-b-N] of parent > [heat-sink-N] of goal[ ;If my patch's North-facing I-b > North heat-sink of North neighbor
          hatch 1 [ 
             face goal ;make sure it is facing towards North neighbor
                while [xcor != [pxcor] of goal and ycor != [pycor] of goal][
                  fd 1 /  ((ROM-N + [ROM-N] of goal) / 2) ;moves forward a fraction of the distance between patch-here and North neighbor until it has reached the center coordinates of North neighbor
                ]
            set pcolor black
           ]    
end

我从复制/粘贴和更新你的StackOverflow问题中推测,你的代码中有一些拼写错误。我尽可能地修复这些错误

我花了几次时间通读了您的描述和代码,但我认为这是您想要实现的算法:

  • 一只乌龟在一块地的中心选择它的北面邻居作为它的新目标
  • 如果当前补丁的
    I-B-N
    小于
    heat-sink-N
    ,我们孵化出一只新海龟朝着这个目标前进
  • 孵出的幼仔以该目标的
    ROM-N
    确定的速率前进到目标
我在代码中看到的最大问题是你使用
while
来控制海龟的移动。在NetLogo中,时间的概念是基于滴答声,如果你想让海龟一次一点地慢慢地朝着目标移动,你想让它在每个滴答声中移动一点,而不是在for循环中一次移动一点

第二点是,我认为您对目标的处理有点混乱,所以我想让它更清楚、更明确。因此,我添加了一个
turtles own
变量
goal
来保持目标,以便我们可以在两个刻度之间使用它。我还随机分配了
ROM-N
I-b-N
head-sink-N
值对于补丁,我们可以在每次运行测试时得到不同的结果

另一个问题是,你的移动功能可能会让海龟超过他们想要的目标,所以我添加了一个检查

这是代码。如果你运行它,你会看到至少一个孵化卵,并移动到北面的下一个补丁,然后可能会根据我生成的随机数据重复这个过程,以填充测试世界。我希望这是有意义的,是有帮助的

turtles-own [ goal ]
patches-own [ I-b-N heat-sink-N ROM-N ]

to setup
  clear-all
  reset-ticks
  create-turtles 1 [
    ; easier for me to see the direction of the default arrow shape
    ; set shape "triangle"
    set color red
    setxy 0 0
    set heading 0
    set goal patch 0 0 ; the first turtle needs its goal set so it'll spawn immediately
  ]
  ask patches [
    set pcolor green
    set ROM-N random 10
    set I-b-N random 10
    set heat-sink-N random 10
  ]

  ; this is required to make sure we always see at least one move
  ask patch 0 0 [ set I-b-N 10 ]
  ask patch 1 0 [ set heat-sink-N 0 ]
end

to go
  ; since `spread-north` asks the same group of turtles that we move below we could probably merge
  ; this with that and make it a turtle procedure, but I'll leave it as is for now
  spread-north

  ask turtles with [goal != nobody] [
    ; moves forward a fraction of the distance between patch-here and North neighbor until it has reached the center coordinates of North neighbor
    let max-move 1 / ((ROM-N + [ROM-N] of goal) / 2)
    fd min list max-move (distance goal)
  ]
  tick
end

to spread-north

  ; you didn't say what to do with turtles that were finished, so I'll just skip them
  ask turtles with [goal != nobody] [

    ; make sure to check against the final destination, and not the patch here
    ; (we might not be on the goal patch yet)
    if xcor = [pxcor] of goal and ycor = [pycor] of goal [

      ; instead of setting our goal for our hatchlings, let's just clear our goal
      ; and then handle our hatching
      set goal nobody
      set pcolor black

      let maybe-goal patch-at 0 1

      ; If my patch's North-facing I-b > North heat-sink of North neighbor
      if [I-b-N] of patch-here > [heat-sink-N] of maybe-goal [
        hatch 1 [

          ; all we do for the hatchlings is point them at a goal
          set goal maybe-goal

          ; make sure it is facing towards the goal and ready to move on the next tick
          face goal

        ]

      ]

    ]

  ]
end
你还提到了复制/粘贴其他方向的逻辑。我认为你可以概括这一点来处理任何方向的目标,而不会有太多麻烦。我不清楚你是否真的需要每个补丁在每个方向上都有不同的
I-b
散热片
,这对我来说似乎很奇怪。但是如果你有如果你能把这件事做完,那就作为第二个问题来回答吧