List 嵌套的Foreach列表NetLogo
嗨 在Netlogo v.6中,我试图计算对等方合作行为的时间加权度量。关键是,我不知道如何在NetLogo中实现嵌套的foreach 我目前的做法是:List 嵌套的Foreach列表NetLogo,list,foreach,nested,netlogo,List,Foreach,Nested,Netlogo,嗨 在Netlogo v.6中,我试图计算对等方合作行为的时间加权度量。关键是,我不知道如何在NetLogo中实现嵌套的foreach 我目前的做法是: 设置一个列表:信誉\u同行 设置一个列表:声誉\u同行\u列表,变量1(行为)和变量2(时间刻度) 每次遭遇时,将声誉\u列表添加到声誉\u对等点,使声誉\u对等点成为列表列表 计算加权声誉: 在reputation_peer中获取每个列表的第2项,这是该遭遇的时间刻度 然后除以当前时间刻度 这给出了一个分数:该遭遇的滴答声/总时间滴答声 设
- 在reputation_peer中获取每个列表的第2项,这是该遭遇的时间刻度
- 然后除以当前时间刻度李>
- 这给出了一个分数:该遭遇的滴答声/总时间滴答声
- 设置一个列表,并对其进行加权
- 为了衡量声誉,将时间分数乘以声誉的第一项,即行为变量
如果你们有一些建议,我会帮上大忙。我不能100%确定你们对最终输出的期望,但也许这就是你们需要的
to calc-rep-2
set reputation_peer [[8 4][9 2][10 3][11 2][14 1]]
let weighted_rep_list []
if ticks > 0 [
foreach reputation_peer [ x ->
; Pull out the values from reputation_peer for ease of use
let encounter_behavior item 0 x
let encounter_time item 1 x
; Calculate the time fraction for the current item
let time_fraction encounter_time / ticks
; Calculate the weighted reputations
let weighted_rep encounter_behavior * time_fraction
; Add the weighted rep to the list of weighted reps
set weighted_rep_list lput weighted_rep weighted_rep_list
]
; Now, weighted_rep_list is a list of weighted reputations
print weighted_rep_list
; Get the sum of the list
print sum weighted_rep_list
]
tick
end
我不能100%确定您期望的最终输出是什么,但也许这就是您需要的
to calc-rep-2
set reputation_peer [[8 4][9 2][10 3][11 2][14 1]]
let weighted_rep_list []
if ticks > 0 [
foreach reputation_peer [ x ->
; Pull out the values from reputation_peer for ease of use
let encounter_behavior item 0 x
let encounter_time item 1 x
; Calculate the time fraction for the current item
let time_fraction encounter_time / ticks
; Calculate the weighted reputations
let weighted_rep encounter_behavior * time_fraction
; Add the weighted rep to the list of weighted reps
set weighted_rep_list lput weighted_rep weighted_rep_list
]
; Now, weighted_rep_list is a list of weighted reputations
print weighted_rep_list
; Get the sum of the list
print sum weighted_rep_list
]
tick
end
嗨,卢克,非常感谢你的帮助!你的密码让我更进一步。只是现在有一个不同的问题,我似乎无法解决。如果你有时间,也许你可以看一下。这是编辑部分最上面的主要问题。@maria118code嗨,玛丽亚,很高兴这有帮助!这可能值得为你的编辑开始一个新问题,因为这是一个单独的问题。实际上,为了帮助其他可能与您有类似问题的人,最好不要在原始代码得到有效答案后完全删除它。我个人建议您“回滚”您的编辑,以便显示您的原始问题(您的编辑在您的帖子下的“编辑的x小时前”链接下进行跟踪)并开始一个新问题。是的,听起来很合理!对于任何感兴趣的人,另一个问题现在发布在Hi Luke下,非常感谢您的帮助!你的密码让我更进一步。只是现在有一个不同的问题,我似乎无法解决。如果你有时间,也许你可以看一下。这是编辑部分最上面的主要问题。@maria118code嗨,玛丽亚,很高兴这有帮助!这可能值得为你的编辑开始一个新问题,因为这是一个单独的问题。实际上,为了帮助其他可能与您有类似问题的人,最好不要在原始代码得到有效答案后完全删除它。我个人建议您“回滚”您的编辑,以便显示您的原始问题(您的编辑在您的帖子下的“编辑的x小时前”链接下进行跟踪)并开始一个新问题。是的,听起来很合理!对于任何感兴趣的人,另一个问题现在发布在