Background
我用这个答案根据的受欢迎程度或健康状况确定的概率分布来选择一只。
问题
我正在尝试传递一个参数,该参数确定概率分布由哪个的属性决定。
问题
如何在 netlogo 中执行等效的参数"python 解包"?
示例代码
turtles-own
[
fitness
strength
degree ;;Node's Connectness
popularity
wealth
]
to-report pick-turtle-biased-by-property [turtle-list property-to-unpack]
let prob-list []
let turtle-list []
ask turtles [
set prob-list lput [[property-to-unpack] of self ] prob-list
set turtle-list lput self turtle-list
]
report first rnd:weighted-one-of-list (map list turtle_list prob-list) last
end
您要执行的操作的关键是使用"匿名报告者"来传递"要解压缩的属性"。请参阅编程指南的匿名过程部分。
下面是一个完整的示例:
extensions [ rnd ]
turtles-own [
strength
wealth
]
to setup
clear-all
create-turtles 10 [
set strength random 100
set wealth random 100
]
end
to go
print pick-turtle-biased-by-property [ -> strength ]
print pick-turtle-biased-by-property [ -> wealth ]
end
to-report pick-turtle-biased-by-property [ property-to-unpack ]
let pairs [ (list self runresult property-to-unpack) ] of turtles
report first rnd:weighted-one-of-list pairs last
end