Netlogo 内存:在表中存储多个修补程序的修补程序变量

Netlogo 内存:在表中存储多个修补程序的修补程序变量,netlogo,Netlogo,我正在创建特定于海龟的表,其中存储补丁坐标、模拟年份(全局变量设置为1、2或3,具体取决于滴答数)以及表示可用资源的补丁变量 我已经为创建一个表编写了代码,其中包含了当前补丁的这些值,但我一直在尝试扩展这个表,以便在每个时间步,海龟为其所有相邻补丁存储这三个值 似乎对当前修补程序有效的代码是: extensions [table] globals [year] turtles-own [memory-map] patches-own [food] to setup ca set year

我正在创建特定于海龟的表,其中存储补丁坐标、模拟年份(全局变量设置为1、2或3,具体取决于滴答数)以及表示可用资源的补丁变量

我已经为创建一个表编写了代码,其中包含了当前补丁的这些值,但我一直在尝试扩展这个表,以便在每个时间步,海龟为其所有相邻补丁存储这三个值

似乎对当前修补程序有效的代码是:

extensions [table]
globals [year]
turtles-own [memory-map]
patches-own [food]

to setup
 ca
 set year 1
 ask patches [set food random 10]
 crt 2 [set memory-map table:make]
 reset-ticks
end

to go
 if ticks = 100 [set year 2]
 if ticks = 200 [set year 3]
 ask turtles [fd 1 set-memory]
end

to set-memory
  let thispatch (list pxcor pycor year); key for table
  table:put memory-map thispatch food
end
现在,我尝试使用foreach修改此代码,以循环遍历邻居,并使设置内存过程适用于每个修补程序:

to set-memory
  foreach sort neighbors [ x ->
    ask x [
    let thispatch (list pxcor pycor year)
    table:put memory-map thispatch food 
  ]]
end
最后一位给了我一个错误,提示table:put只能在海龟上下文中使用

我还尝试先为所有邻居创建坐标/年列表:

let thispatch [(list pxcor pycor year) ] of neighbors
这是可行的,但我不知道如何使用每组列表输入作为表的键


最后,我需要一个表,表中的键包含每个相邻补丁的(pxcor pycor year),食物值作为每个键的值。非常感谢您的帮助。

我想我得到了。我创建了一个独立的模型,用于更新表中邻近补丁以及海龟所在补丁的值:

extensions
[
  table
]

patches-own
[
  id
  food
]

turtles-own
[
  memory-map
]

to setup
  ; Assign a specific ID to each patch to act as the key for the table 
  ;(that way you only deal with one value instead of a set of coordinates)
  (foreach (sort patches) (n-values (count patches) [i -> i + 1]) [[i _id] -> ask i [set id _id]]) 
  ask patches [set food 100]
  crt 1
  [
    set pcolor yellow ;for visualization purposes
    set plabel id ;for visualization purposes
    set memory-map table:make ; Create empty table
    table:put memory-map ([id] of patch-here) food ;Add key (id) and value (food) of current patch to the table
                                                   ; Loop asking each of the neighbors to update the table
    let patch-memmap memory-map ;so that patches can access the table, otherwise it's only accessible to turtles and it gives an error
    foreach sort neighbors [ x ->
      ask x [
        table:put patch-memmap id food
        set pcolor green ;for visualization purposes
        set plabel id ;for visualization purposes
    ]]
    set memory-map patch-memmap ;return the new table to the turtle 
    show memory-map ;check what table looks like
  ]
end

to go
  ask patches [set food 200]
  ask turtles 
  [ 
    move-to one-of neighbors 
    set food (food * 0.5) ;representing consumption in the current patch
    update-memory
  ]

end

to update-memory
  set pcolor red ;for visualization purposes
  set plabel id ;for visualization purposes
  table:put memory-map ([id] of patch-here) food
  let patch-memmap memory-map 
  foreach sort neighbors [ x ->
    ask x [
      table:put patch-memmap id food
      set pcolor pink 
      set plabel id 
  ]]
  set memory-map patch-memmap
  show memory-map
end