Netlogo:如何将属于邻居的列表传输到矩阵?

时间:2019-05-06 19:53:46

标签: list matrix netlogo

一个名为ownList2的列表由两个参数组成。队友是在给定邻居半径内的所有邻居。我在6.0版中尝试了此代码。但这是行不通的。 基本上,我想将等维列表放入矩阵。我在做错什么吗?还是有人可以改善代码段?

ask turtles[set ownList2 (list who sensed)] 
;sensed is sensor value of a turtle with respect to the patch. 
;ownList2 is like a message of two bytes, 
    ;first byte mentioning the identity of the itself 
    ;second byte mentioning the value of the sensor. 

ask turtles[
    foreach (list flockmates)
    [
       i -> set m45 matrix:to-column-list ( list [ownList2] of i )
    ]
   ]

结果:      对于与邻居1,2,3:3的乌龟0      ownList2〜[1200]                 [2 400]                 [3 900] 乌龟0的M43应该看起来像 [[1 200] [2 400] [3 900]]

1 个答案:

答案 0 :(得分:0)

感谢您添加该信息。这是一个可能满足您需要的玩具示例:

extensions [ matrix ]

turtles-own [ ownlist2 sensed m45 ]

to setup
  ca

  ; Setup example turtles as per question
  foreach [ 100 200 400 900 ] [
    n ->
    crt 1 [
      while [ any? other turtles-here ] [
        move-to one-of neighbors4
      ]
      set sensed n
      set ownlist2 ( list who sensed )
    ]
  ]

  ; Get the turtles to create matrices from the ownlists of
  ; sorted other turtles
  ask turtles [
    set m45 matrix:from-column-list map [ i -> [ ownlist2] of i ] sort other turtles
  ]

  ; Example output:
  ask turtle 0 [
    print "Turtle 0's m45:"
    print matrix:pretty-print-text m45
  ]

  reset-ticks
end

输出示例:

Turtle 0's m45:
[[   1    2    3 ]
 [ 200  400  900 ]]