【发布时间】:2018-05-23 01:48:51
【问题描述】:
我正在 Netlogo 中编写一个基本上应该执行以下操作的代码:
- 在定向链接之间进行交互并找出它们的合作行为 (coop_b)。
- 将 coop_b 与交互时间 (reputation_now) 一起存储在列表变量中
- 每次互动,将reputation_now 添加到更大的列表reportation_h(声誉历史)
- 现在,为声誉添加时间权重,以便最近进行的交互在总声誉中的权重更大。我通过将交互的遭遇时间除以当前时间滴答来做到这一点,然后将其与 coop_b 相乘以检索每个交互的加权声誉。这存储在列表reputation_h_w(历史声誉加权)中。问题是,每次成员交互时都应该更新此列表,以便之前添加到列表中的内容现在更新为新的时间刻度。我的预感是我的代码在这方面陷入了迷雾(问题描述在代码部分下方)。
我的代码:
to horizontal_interact
ask members [
;set random example variable for coop_b
set coop_b random-float 5 ; coop-b stands for cooperation behavior
if ticks > 0 [
ask my-out-links [ ;there are directed links between all members
set reputation_now (list [coop_b] of end2 ticks) ;list of coop_b and encounter time
set reputation_h lput reputation_now reputation_h ; history of reputations, a list of all reputation_now recorded
foreach reputation_h [ x ->
let cooperative_behavior item 0 x
let encounter_time item 1 x
let reputation_now_w (list cooperative_behavior encounter_time (encounter_time / ticks ))
]
]
]
]
end
如果我用 2 位成员测试reputation_h 和reputation_h_w 的内容,我得到:
reputation_h 是成员的 coop_b 变量和遭遇的滴答声
links> show reputation_h
(link 1 0):
[[4.0900840358972825 1]
[0.8885953841506328 2]
[0.47017368072392984 3]]
(link 0 1): [[3.6805257472366164 1]
[3.6805257472366164 2]
[3.4201458793705326 3]]
reputation_h_w(包含成员的coop_b变量,遭遇时间和遭遇时间除以滴答声):
links> show reputation_h_w
(link 0 1): [[3.6805257472366164 1 1]
[3.6805257472366164 1 0.5]
[3.6805257472366164 2 1]
[3.6805257472366164 1 0.3333333333333333]
[3.6805257472366164 2 0.6666666666666666]
[3.4201458793705326 3 1]]
(link 1 0): [[4.0900840358972825 1 1]
[4.0900840358972825 1 0.5]
[0.8885953841506328 2 1]
[4.0900840358972825 1 0.3333333333333333]
[0.8885953841506328 2 0.6666666666666666]
[0.47017368072392984 3 1]]
问题在于,reputation_h_w 对我来说没有意义 - 首先有六个输入而不是三个,其次,遭遇时间(第 1 项)和遭遇时间/滴答声(第 2 项)是关闭的。
我在这里做错了什么?
【问题讨论】: