0

I have written a fairly complicated code for my ABM (634 agents having interactions, each having different variables some of which are lists with multiple values that are updated each tick). As I need to save the updated values for all agents, I have defined a global variable using table:make. This table has 634 keys (each key for one agent), and each key has a list of those values (from that agents-own list variable) for the correspondent agent. But when I use the name of this table to be reported as one of my outputs in Behavior Space, the result in csv file is a table with no keys and it has only a number in it: {{table: 1296}}. So, I was wondering how I could change this variable to be able to have all values.

4

1 回答 1

3

如果您乐于在事后使用 R 或其他东西进行一些后处理,那么table:to-list可能就是您所需要的。例如,使用一个简单的设置示例,例如:

extensions [ table ]

globals [ example-table ]

turtles-own [ turtle-list ]

to setup
  ca
  crt 3 [
    set turtle-list ( list random 10 one-of [ "A" "B" "C" ] random 100 )
  ]
  set example-table table:make
  foreach sort turtles [
    t ->
    table:put example-table ( word "turtle_" [who] of t ) [turtle-list] of t
  ]
  reset-ticks
end

ato-report清理每个表项,使第一项是键,所有其他项是列表中的项:

to-report easier-read-table [ table_ ]
  let out []
  foreach table:to-list table_ [ i -> 
    set out lput ( reduce sentence i ) out
  ]
  report out
end

您可以设置您的 BehaviorSpace 实验,以便您的一名记者就是那个记者,例如:

在此处输入图像描述

要获取 .csv 文件,例如:

在此处输入图像描述

报告者列输出列表的列表,您可以根据需要处理这些列表。

但是,我可能不会为此使用基本的 BehaviorSpace 输出,而是在实验中调用手动表输出过程。例如,使用csv扩展来制作这个output-table过程:

to output-table [ filename_ table_ ]
  let out [["key" "col1" "col2" "col3"]]
  foreach table:to-list table_ [ i ->
    set out lput ( reduce sentence i ) out
  ]
  csv:to-file filename_ out
end

如果您不太习惯清理列表列表的输出,据我所知,这是您将从 BehaviorSpace 输出中获得的内容,这将输出一个更易于分析的表。因此,您可以在实验结束时调用它,例如:

在此处输入图像描述

要获得如下表格:

在此处输入图像描述

处理起来更好一些。如果需要,您显然可以修改它以更频繁地报告,例如:

在此处输入图像描述

这将在实验的每个滴答声中输出一个表格(您也可以在代码中执行此操作以使其更容易一些)。

于 2018-12-14T23:27:37.777 回答