最近我一直在编写Netlogo v6代码:
现在,我一直在学习很多关于报告的内容,并且我发现它对构建我的代码有很大帮助,所以我使用它非常多。
但是,我似乎不断收到以下类型的错误:
此代码不能由乌龟运行,只能链接 链接14 9运行CALCULATE_CURRENT_REPUTATION时出错 由程序CALCULATE_REPUTATION调用 由程序HORIZONTAL_INTERACT调用 由程序GO_TO_MEETING调用 由程序GO调用 按钮'go'调用
我想知道是否有人能看出什么是错的?
我一直在试图查看问题是否与报告有关,但这似乎不是问题。因为,当我将所有报告组合成一个单一的函数时,我会得到一个类似的链接/乌龟问题。
我的预感是问题在于我以某种方式没有正确地提出要求,但我该如何改变呢?
报告版本的代码:
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的无关代码?和会议组织?被省略]
;;;;;;;;;;;;;;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
答案 0 :(得分:1)
我自己也遇到了这个问题,所以这里有解决方案,并为那些有类似问题的人解释了问题:
这是函数calculate_coop_b中的语法问题。问题是我问变量[股票购买]我的外链接,但我实际上是想问[股票买了]外链接邻居。
此功能的正确代码:
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函数,即使这最终并没有导致我的问题。
感谢阅读,再见!