表格用乌龟上下文编写,值介于0和1之间,patchID作为键。每个补丁应根据表中的值使用比例颜色进行着色。结果应该看起来......就像图书馆里的热扩散模型一样。到目前为止,它只会为我的乌龟所在的斑块着色。我想我需要把表从乌龟写到补丁上下文,但不知道应该怎么做。 Netlogo是否提供任何选项?谢谢!
clear-links
let alone turtles with [not any? link-neighbors]
ask turtles[
let res2 one-of other alone
;;go over each patch
foreach table:keys dict_Opinion[
;;get current opinion for both agents and store it op_a1 and op_a2
let op_a1 table:get dict_Opinion ?
let op_a2 [table:get dict_Opinion ?] of res2
let soc-dist 0
let new_op_a1 0
let new_op_a2 0
;;calculate social distance
set soc-dist abs(op_a1 - op_a2)
;;check if social distance is less than threshold D
ifelse soc-dist < updated_D [
;;if lower than D calculate new opinions for both agents
set new_op_a1 (op_a1 + (mu * ( op_a1 - op_a2)))
if new_op_a1 > 1 [set new_op_a1 1]
if new_op_a1 < 0 [set new_op_a1 0]
set new_op_a2 (op_a2 + (mu * ( op_a2 - op_a1)))
if new_op_a2 > 1 [set new_op_a2 1]
if new_op_a2 < 0 [set new_op_a2 0] ]
;;else: if the soc distance is too large opinions remain unchanged
[set new_op_a1 op_a1
set new_op_a2 op_a2]
;;newly calculated opinions are put in the opinion lists of the agents
table:put dict_Opinion ? precision new_op_a1 4
ask res2 [table:put dict_Opinion ? precision new_op_a2 4]]]
直到这里,一切正常......我试图将new_op_a1和new_op_a2写入补丁自己的new_op,但这只会改变补丁的颜色,海龟位于。
set new_op ((new_op_a1 + new_op_a2) / 2)
set pcolor scale-color white new_op 0 1
答案 0 :(得分:0)
这是不对的,因为我并不真正了解你如何访问特定海龟对特定补丁的看法,但结构应该是这样的
patches-own
[ ...
what-turtles-think
...
]
ask patches
[ set what-turtles-think mean [opinion about myself] of turtles
set pcolor scale-color red what-turtles-think 0 1
]
答案 1 :(得分:0)
解决问题的方法:
;; add two new variable to patches-own
patches-own [... a b ...]
to patch_avg_op
;;calculate the sum of the opinion of all turtles
ask turtles [
foreach table:keys dict_Opinion [
let c table:get dict_Opinion ?
let d patches with [plabel = ?]
ask c [
set a a + c
]
]
]
;; calculate the average and put it in patch variable b
let nr_of_turtles count turtles
ask patches [
set b (a / nr_of_turtles)
set a 0
]
end
to color-patches
ask patches [ set pcolor scale-color black b 0 1]
end