Colors 将“海龟”上下文更改为“面片上下文”以更改颜色面片
表是在turtle上下文中编写的,其值介于0和1之间,patchID作为键。每个面片应根据表中的值使用比例颜色进行着色。结果应该像图书馆里的热扩散模型。到目前为止,它只给我的海龟们所在的补丁上色。我想我需要从海龟到补丁上下文编写表,但不知道应该如何完成。Netlogo是否为此提供了任何选项?谢谢Colors 将“海龟”上下文更改为“面片上下文”以更改颜色面片,colors,patch,netlogo,Colors,Patch,Netlogo,表是在turtle上下文中编写的,其值介于0和1之间,patchID作为键。每个面片应根据表中的值使用比例颜色进行着色。结果应该像图书馆里的热扩散模型。到目前为止,它只给我的海龟们所在的补丁上色。我想我需要从海龟到补丁上下文编写表,但不知道应该如何完成。Netlogo是否为此提供了任何选项?谢谢 clear-links let alone turtles with [not any? link-neighbors] ask turtles[ let res2 one-
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]]]
这是不对的,因为我真的不明白你是如何获得一只海龟对某个补丁的意见的,但是结构应该是这样的
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
]
问题的解决办法是:
;; 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
你的问题是什么?您声明您认为需要从海龟到补丁上下文编写表,但实际上并没有告诉我们您想要做什么。你说代码给海龟所在的补丁上色。您还想做些什么吗?到目前为止,我为每只海龟都提供了一个表,每个patchID键存储一个特定的意见值。我想做一个世界的彩色表示,以显示平均观点的差异。首先,我想计算每个patchID的所有意见的平均值。其次,我想将这个平均意见作为补丁值。第三,我想做一个颜色表示,从暗的接近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