netlogo - 为什么使用领带的 Netlogo 链接不起作用?

标签 netlogo tie

以下代码创建 2 辆汽车,然后在它们后面添加购物车(称为“追随者”)。该代码的目的是将追随者均匀地分布在汽车后面,一个接一个,然后将它们连接并绑在一起。然后,当汽车移动时,他们应该拉动跟随者。但似乎只有第一个联系(汽车和最近的追随者)有效。

globals [small  len_small ]
breed [cars car]
breed [followers follower]

cars-own [reg no_foll  len]
followers-own [reg]

to setup
  clear-all
   set small 2
   set len_small 7
 
  ask patches with [pycor >= 5 or pycor <=  1][set pcolor red]
  ask patches with [pycor = 4 ][set pcolor blue]
   ask patches with [ pycor = 2][set pcolor blue + 1]
  ask patches with [pycor = 3][set pcolor white]
  make_small
  reset-ticks

end

to go
  ask cars [forward 2]
  
end

to make_small
 create-cars  small  [move-to one-of patches with [pcolor = white  ]
    set shape "circle" set color red  set reg who set no_foll 0  set len len_small
    set heading one-of  [90 270]]
  
   create-followers (len_small - 1) * small [ set shape "car" set color red move-to one-of cars with [color = red and no_foll < (len_small - 1)]
    set heading [heading] of one-of cars-here + 180 set reg [reg] of one-of cars-here ask one-of cars-here [set no_foll no_foll + 1]]
  form_small_car
end

to form_small_car
  ask followers with [color = red ] [while [any? other turtles-here with [reg = [reg] of myself]][forward 1]]
  ask cars with [color = red] [let foll_behind_list followers-on patch-ahead -1 let foll_behind one-of foll_behind_list with [reg = [reg] of myself] create-link-to foll_behind [tie]]
  ask followers with [color = red and any? followers-on patch-ahead -1] [let foll_behind_list followers-on patch-ahead -1 let foll_behind one-of foll_behind_list with [reg = [reg] of myself ] 
  create-link-to foll_behind [tie]]
 end

我哪里出错了? [顺便说一句,在这个示例代码中,追随者的选择有些过度,但在更大的模型中,需要到位,以便只有追随者附加到同一汽车链接]

谢谢

凯文

最佳答案

我想我明白了 - 本质上需要确保只选择正确的汽车,并且提前修补 1 而不是 -1。

globals [small  len_small ]
breed [cars car]
breed [followers follower]

cars-own [reg no_foll  len]
followers-own [reg]

;;white is the road and blue are parking ranks (red is the border)
to setup
  clear-all
   set small 2
   set len_small 7

  ask patches with [pycor >= 5 or pycor <=  1][set pcolor red]
  ask patches with [pycor = 4 ][set pcolor blue]
   ask patches with [ pycor = 2][set pcolor blue + 1]
  ask patches with [pycor = 3][set pcolor white]
  make_small
  reset-ticks

end

to go
  ask cars [forward 2]

end

to make_small
 create-cars  small  [move-to one-of patches with [pcolor = white  ]
    set shape "circle" set color red  set reg who set no_foll 0  set len len_small
    set heading one-of  [90 270]]

   create-followers (len_small - 1) * small [ set shape "car" set color red move-to one-of cars with [color = red and no_foll < (len_small - 1)]
    set heading [heading] of one-of cars-here + 180 set reg [reg] of one-of cars-here ask one-of cars-here [set no_foll no_foll + 1]]
 form_small_car
end

to form_small_car
  ask followers with [color = red ] [while [any? other turtles-here with [reg = [reg] of myself]][forward 1]]
  ask cars with [color = red] [let foll_behind_list followers-on patch-ahead -1 let foll_behind one-of foll_behind_list with [reg = [reg] of myself] create-link-to foll_behind [tie]]
  ask followers with [color = red and any? followers-on patch-ahead 1] [let foll_behind_list followers-on patch-ahead 1 if any? foll_behind_list with [reg = [reg] of myself]
    [let foll_behind one-of foll_behind_list with [reg = [reg] of myself] print who print [who] of foll_behind create-link-to foll_behind [tie]]
     ]
 end

关于netlogo - 为什么使用领带的 Netlogo 链接不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75745711/

相关文章:

random - 让随机数量的海龟做某事?

syntax-error - NetLogo-沙堆-错误

netlogo - 模拟环岛交通

perl - 我怎样才能 Hook 到 Perl 的打印?

r - 在 R 中找到最小值时的领带

random - 如何给全局一个不包括0的随机数

NETLOGO:如果一 block 土地上有两只乌龟,我该如何让一只乌龟死亡?

perl - Tie::File 是否延迟加载文件?

perl - 如何绑定(bind) perl 脚本中的每个变量?