我用this answer根据由乌龟的流行程度或适合度决定的概率分布选择了一只乌龟。
我正在尝试传递一个参数,该参数确定概率分布所依据的是乌龟的哪个属性。
如何在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
答案 0 :(得分:3)
您要执行的操作的关键是使用“匿名报告者”传递“解包属性”。请参阅编程指南的Anonymous procedures部分。
这是一个完整的例子:
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