Netlogo:嵌套 to-report、ask 和 argument
Netlogo: Nested to-report, ask, and argument
最近我一直在写一个 Netlogo v6 代码:
- 根据同伴的影响力总和改变代理人在特定行为中的影响力,该影响力由同伴的声誉加权
- 同行的声誉基于他们的合作行为和他们在会议中的知名度
现在,我学习了很多关于 to-report 的知识,我发现它对我构建代码有很大帮助,所以我经常使用它。
但是,我似乎不断收到以下类型的错误:
this code can't be run by a turtle, only a link
error while link 14 9 running CALCULATE_CURRENT_REPUTATION
called by procedure CALCULATE_REPUTATION
called by procedure HORIZONTAL_INTERACT
called by procedure GO_TO_MEETING
called by procedure GO
called by Button 'go'
我想知道是否有人能看出问题所在?
我一直在尝试查看问题是否出在 to-report 上,但这似乎不是问题所在。因为,当我将所有 to-report 组合成一个单一函数时,我得到了一个类似的 link/turtle 问问题。
我的直觉是问题在于我不知何故没有正确询问,但我应该如何更改它?
to-report版本代码:
to go_to_meeting
ask members [
; if go_to_meeting and meeting_organised both report true, the member goes to the meeting (which is on the belowmentioned patch-set)
if go_to_meeting? and meeting_organised? [
move-to one-of (patch-set patch 0 0 ([neighbors] of patch 0 0 ))
set meetings_attended meetings_attended + 1]
; the members at the meeting check whether their links are also there, if so, they interact with them
ask members-on one-of (patch-set patch 0 0 ([neighbors] of patch 0 0 )) [
if link_at_meeting? [horizontal_interact]
]
]
end
[ link_at_meeting 的无关代码?和 meeting_organised?被省略]
;;;;;;;;;;;;;;AT THE MEETING;;;;;;;;;;;;;;
to horizontal_interact
set subjective_norm_list []
set links_at_meeting my-out-links with [[patch-here] of other-end = (one-of (patch-set patch 0 0 ([neighbors] of patch 0 0 )))]
if any? links_at_meeting [
repeat number_of_interactions_per_meeting [
ask one-of links_at_meeting [
set influence_given ( calculate_reputation end2 end1 ) * [attitude] of end2 * [intrinsic_trust] of end1
set number_of_encounters number_of_encounters + 1
ask myself [set subjective_norm_list lput [influence_given] of myself subjective_norm_list]
]
]
set subjective_norm sum subjective_norm_list
print subjective_norm_list
print subjective_norm
]
end
; a = end 2
; b = end 1
to-report calculate_reputation[a b]
set reputation_now calculate_current_reputation
;reputation history is the cooperative behavior and visibility history of the link
set reputation_h lput reputation_now reputation_h
ifelse length reputation_h < ([memory] of b)
;if the links have encountered less than a member's memory, that is, the member recounts every memory, take the link's reputation to be the mean of every coop_b in the reputation history
[let reputations sum reputation_h
set reputation_total (reputations / (length reputation_h))]
;else, go so far as memory stretches and take the mean cooperative behavior in the reputation history as the link's reputation
[let reputations sum sublist reputation_h (length reputation_h - ([memory] of b)) (length reputation_h)
set reputation_total (reputations / ([memory] of b))]
report reputation_total
end
to-report calculate_current_reputation
report ((100 - behavioral_transparency) / 100 * calculate_visibility + behavioral_transparency * calculate_coop_b)
end
to-report calculate_visibility
report number_of_encounters / ([meetings_attended] of end1)
end
to-report calculate_coop_b
ask end1 [
set shares_bought_total sum [shares_bought] of my-out-links
set energy_gap_total ( sum [energy_consumed] of my-out-links - sum [energy_generated] of my-out-links)
]
report ([shares_bought] of end2 / [shares_bought_total] of end1 + [energy_gap] of end2 / [energy_gap_total] of end1 )
end
我自己遇到了这个问题,所以这里是为那些有类似问题的人解释的解决方案和问题:
这是函数 calculate_coop_b 中的语法问题。问题是我问了我的-link 的变量 [购买的股份],但我实际上是想问 link- 的邻居的 [购买的股份]。
此函数的正确代码:
to-report calculate_coop_b
ask end1 [
set shares_bought_total sum [shares_bought] of out-link-neighbors
set energy_gap_total ( sum [energy_consumed] of out-link-neighbors - sum [energy_generated] of out-link-neighbors)
]
report ([shares_bought] of end2 / [shares_bought_total] of end1 + [energy_gap] of end2 / [energy_gap_total] of end1 )
end
我希望此页面仍向其他人说明如何使用嵌套的 to-report 函数,即使这最终并没有成为我的问题所在。
感谢阅读,再见!
最近我一直在写一个 Netlogo v6 代码:
- 根据同伴的影响力总和改变代理人在特定行为中的影响力,该影响力由同伴的声誉加权
- 同行的声誉基于他们的合作行为和他们在会议中的知名度
现在,我学习了很多关于 to-report 的知识,我发现它对我构建代码有很大帮助,所以我经常使用它。
但是,我似乎不断收到以下类型的错误:
this code can't be run by a turtle, only a link error while link 14 9 running CALCULATE_CURRENT_REPUTATION called by procedure CALCULATE_REPUTATION called by procedure HORIZONTAL_INTERACT called by procedure GO_TO_MEETING called by procedure GO called by Button 'go'
我想知道是否有人能看出问题所在?
我一直在尝试查看问题是否出在 to-report 上,但这似乎不是问题所在。因为,当我将所有 to-report 组合成一个单一函数时,我得到了一个类似的 link/turtle 问问题。
我的直觉是问题在于我不知何故没有正确询问,但我应该如何更改它?
to-report版本代码:
to go_to_meeting
ask members [
; if go_to_meeting and meeting_organised both report true, the member goes to the meeting (which is on the belowmentioned patch-set)
if go_to_meeting? and meeting_organised? [
move-to one-of (patch-set patch 0 0 ([neighbors] of patch 0 0 ))
set meetings_attended meetings_attended + 1]
; the members at the meeting check whether their links are also there, if so, they interact with them
ask members-on one-of (patch-set patch 0 0 ([neighbors] of patch 0 0 )) [
if link_at_meeting? [horizontal_interact]
]
]
end
[ link_at_meeting 的无关代码?和 meeting_organised?被省略]
;;;;;;;;;;;;;;AT THE MEETING;;;;;;;;;;;;;;
to horizontal_interact
set subjective_norm_list []
set links_at_meeting my-out-links with [[patch-here] of other-end = (one-of (patch-set patch 0 0 ([neighbors] of patch 0 0 )))]
if any? links_at_meeting [
repeat number_of_interactions_per_meeting [
ask one-of links_at_meeting [
set influence_given ( calculate_reputation end2 end1 ) * [attitude] of end2 * [intrinsic_trust] of end1
set number_of_encounters number_of_encounters + 1
ask myself [set subjective_norm_list lput [influence_given] of myself subjective_norm_list]
]
]
set subjective_norm sum subjective_norm_list
print subjective_norm_list
print subjective_norm
]
end
; a = end 2
; b = end 1
to-report calculate_reputation[a b]
set reputation_now calculate_current_reputation
;reputation history is the cooperative behavior and visibility history of the link
set reputation_h lput reputation_now reputation_h
ifelse length reputation_h < ([memory] of b)
;if the links have encountered less than a member's memory, that is, the member recounts every memory, take the link's reputation to be the mean of every coop_b in the reputation history
[let reputations sum reputation_h
set reputation_total (reputations / (length reputation_h))]
;else, go so far as memory stretches and take the mean cooperative behavior in the reputation history as the link's reputation
[let reputations sum sublist reputation_h (length reputation_h - ([memory] of b)) (length reputation_h)
set reputation_total (reputations / ([memory] of b))]
report reputation_total
end
to-report calculate_current_reputation
report ((100 - behavioral_transparency) / 100 * calculate_visibility + behavioral_transparency * calculate_coop_b)
end
to-report calculate_visibility
report number_of_encounters / ([meetings_attended] of end1)
end
to-report calculate_coop_b
ask end1 [
set shares_bought_total sum [shares_bought] of my-out-links
set energy_gap_total ( sum [energy_consumed] of my-out-links - sum [energy_generated] of my-out-links)
]
report ([shares_bought] of end2 / [shares_bought_total] of end1 + [energy_gap] of end2 / [energy_gap_total] of end1 )
end
我自己遇到了这个问题,所以这里是为那些有类似问题的人解释的解决方案和问题:
这是函数 calculate_coop_b 中的语法问题。问题是我问了我的-link 的变量 [购买的股份],但我实际上是想问 link- 的邻居的 [购买的股份]。
此函数的正确代码:
to-report calculate_coop_b
ask end1 [
set shares_bought_total sum [shares_bought] of out-link-neighbors
set energy_gap_total ( sum [energy_consumed] of out-link-neighbors - sum [energy_generated] of out-link-neighbors)
]
report ([shares_bought] of end2 / [shares_bought_total] of end1 + [energy_gap] of end2 / [energy_gap_total] of end1 )
end
我希望此页面仍向其他人说明如何使用嵌套的 to-report 函数,即使这最终并没有成为我的问题所在。
感谢阅读,再见!