【发布时间】:2016-05-03 19:54:44
【问题描述】:
我很难理解to-report 和report 在NetLogo 中的作用,即使它看起来很有用,我也找不到用“人类风格”语言编写的帮助。
在 NetLogo 字典 http://ccl.northwestern.edu/netlogo/docs/dictionary.html#report 我可以找到 to-report 的定义:
to-report procedure-name
to-report procedure-name [input1 ...]
Used to begin a reporter procedure.
The body of the procedure should use report to report a value for the procedure. See report.
对于report:
report value
Immediately exits from the current to-report procedure and reports value as the result of that procedure. report and to-report are always used in conjunction with each other. See to-report for a discussion of how to use them.
所以,to-report 和 report 似乎计算了一些值并报告了它。
因此,当我尝试添加时
to-report average [a b c]
report (a + b + c) / 2
end
到我的代码,然后在我的代码 p.e. 的某处使用 average 变量:
to go
...
print average
tick
end
我有一个错误:AVERAGE expected 3 inputs。当我尝试在 globals [a b c] 中创建我的变量 [a b c] 时,我遇到了一个错误 There is already a global variable called A。
如果我在to-report 过程中定义我的变量[a b c]:
to-report average [a b c]
set a 1
set b 2
set c 3
report (a + b + c) / 2
end
我的错误又是AVERAGE expected 3 inputs。
因此,我怎样才能简单地测试报告程序的有用性?以及在我的代码中正确放置它的位置以查看它的实际作用?来自 Urban Suite - Economic Disparity (http://ccl.northwestern.edu/netlogo/models/UrbanSuite-EconomicDisparity) 我看到 to-report 用于计算与每个补丁相关的值: p>
to-report patch-utility-for-poor
report ( ( 1 / (sddist / 100 + 0.1) ) ^ ( 1 - poor-price-priority ) ) * ( ( 1 / price ) ^ ( 1 + poor-price-priority ) )
end
但是这个报告的值没有直接定义为补丁变量,这增加了我的困惑......
谢谢!
【问题讨论】: