是否有等效于 python 解包或 bash 使用 Netlogo 的间接参数扩展?
Is there an equivlent of python unpacking or bash's indirect parameter expansion with Netlogo?
背景
我使用 select 乌龟基于概率分布,该概率分布由乌龟的受欢迎程度或适应性决定。
问题
我正在尝试传递一个参数来确定乌龟的 属性 概率分布由哪个决定。
问题
如何在 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
您要执行的操作的关键是使用 "anonymous reporters" 传递 "property to unpack"。请参阅编程指南的 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
背景
我使用
问题
我正在尝试传递一个参数来确定乌龟的 属性 概率分布由哪个决定。
问题
如何在 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
您要执行的操作的关键是使用 "anonymous reporters" 传递 "property to unpack"。请参阅编程指南的 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