基于其他海龟变量的选择



我被ABM卡住了。情况很简单:有一些海龟,生产者,还有一些选择者。生产者生产出具有一定质量的产品,选择者根据感知质量进行选择。

感知质量是一个函数";生产者的产品质量-chooser的贝塔";,其中贝塔是个体自适应变量。所有这些变量都是海龟自己的,它们都拥有它们(每轮角色都会切换(。

我希望发生以下情况:产品质量是生产者的变量,测试版是选择者的变量。如何对操作进行编码?

我尝试过以下方法:

ask turtles with [group = "producers"] [
set perceived-product-quality ((product-quality - beta))
]

然而,就像测试版是生产者的(不正确,应该是选择者(。

然后我尝试了这个:

ask turtles with [group = "choosers"] [
let quality [product-quality] of turtles with [ group = "producers" ]
set perceived-product-quality quality - beta
]

然而,它不起作用,运行时错误:"预期输入是一个数字,但得到了列表">

我该怎么做?

如果你试图从所有生产商和选择者那里查询平均产品质量/测试版,我不确定你的确切用例是什么,但我认为的一般答案是,你需要明确你实际上试图从哪些海龟那里获取值。当您使用ask时,您要ask执行某些操作的代理将默认使用其自己的变量(如果它拥有这些变量(。因此,如果你需要坚持使用turtles-own变量,而不是制定品种和品种特定的变量,你需要明确说明你试图引用哪只海龟。以下是一个玩具示例,它让选择者选择配方中最接近的生产商的产品质量:

turtles-own [ group product-quality beta perceived-product-quality]
to setup
ca
ask n-of 10 patches [
sprout 1 [
set group one-of [ "producers" "choosers" ]
]
]
ask turtles [
ifelse group = "producers" [
set product-quality random 500 + 500
set beta random 200 + 100
set color red
] [
set product-quality random 50 + 50
set beta random 20 + 10
set color blue
] 
]
reset-ticks
end
to set-perceived
let current-producers turtles with [ group = "producers" ]
let current-choosers turtles with [ group = "choosers" ]
ask current-choosers [
; Pick the closest producer
let closest-producer min-one-of current-producers [ distance myself ] 

; Pull the product quality of that closest producer
let closest-product-quality [ product-quality ] of closest-producer

; Set MY perceived product quality to be closest-product-quality - MY beta
set perceived-product-quality closest-product-quality - beta
show ( 
word "I used the turtle " closest-producer 
" to determine my perceived product quality of: " perceived-product-quality 
)
]
end

编辑:

评论更新:

我希望发生以下情况:选择器为Moore邻居中的所有乌龟执行"感知产品质量-测试版"操作。完成此操作后,他们将选择感知产品质量值最高的产品。

在此版本中,有一个to-report程序,从from-who的角度报告感知的产品质量。然后,这可以与max-one-of一起使用,以返回具有最高感知值的乌龟。

turtles-own [ group product-quality beta perceived-product-quality]
to setup
ca
resize-world 0 5 0 5
set-patch-size 40
ask patches [
sprout 1 [
set group one-of [ "producers" "choosers" ]
]
]
ask turtles [
ifelse group = "producers" [
set product-quality random 500 + 500
set beta random 200 + 100
set color red
] [
set product-quality random 50 + 50
set beta random 20 + 10
set color blue
]
]
reset-ticks
end
to choose-best-moore
let current-choosers turtles with [ group = "choosers" ]
ask current-choosers [
let current-producers ( turtles-on neighbors ) with [ group = "producers" ]
ifelse any? current-producers [
let turtle-with-highest-perceived max-one-of current-producers [ perceived-target-value myself ]
let real-product-quality [product-quality] of turtle-with-highest-perceived
let false-product-quality [ perceived-target-value myself ] of turtle-with-highest-perceived 
show ( word "I surveyed " count current-producers " and found that " turtle-with-highest-perceived 
" had the best product quality (real: " real-product-quality ", perceived: " false-product-quality ")" )
] [
show "I found no producers in my neighboring cells"
]
]
end
to-report perceived-target-value [ from-who ] 
let target-product-quality product-quality
let target-perceived-quality ( target-product-quality - [beta] of from-who )
report target-perceived-quality
end

最新更新