基于视角的排名?
Perspective based ranking?
我有一个程序,其中每个节点都有自己的其他节点排名系统,NetLogo 实现这个的最佳方法是什么?
通常,我会用二维列表来解决这个问题:
[[turtle 1, score], [turtle 2, score], ...]
但这在 NetLogo 中似乎很麻烦。这是我创建和修改二维列表的代码:
to test
clear-all
crt 10
;Create a list of turtles
let agents-list [self] of turtles
;Create empty list, which will be the top level of the TwoD list
let TwoD-list []
;Populate the TwoD-list: [[turtle 0, 0], [turtle 1, 0], ...]
foreach agents-list [
set TwoD-list (lput (list ? 0) TwoD-list)
]
show TwoD-list
repeat 5 [
;Change a value in the TwoD-list
let rand-index random (length TwoD-list) ;select a random index
;The next line is what makes it a huge headache, basically you have to select a list at the top level to replace, and then select the list at the lower level to replace it.
;This entire line of code is just adding one to an element
set TwoD-list (replace-item rand-index TwoD-list (replace-item 1 (item rand-index TwoD-list) (item 1 (item rand-index TwoD-list) + 1)))
show TwoD-list
]
end
我还能做什么?或者有没有更好的方法来实现这个方法?
如果你想模拟代理之间的关系,NetLogo 有完美的选择:links!
让每只海龟给所有其他海龟打分可以很自然地表示为:
directed-link-breed [ rankings ranking ]
rankings-own [ score ]
to setup
clear-all
create-turtles 10
ask turtles [ create-rankings-to other turtles ]
; increment 5 random rankings by one:
ask n-of 5 rankings [ set score score + 1 ]
; display the rankings of each turtle:
ask turtles [ show [ (word end2 " " score) ] of my-out-rankings ]
end
如果您不想让链接显示在视图中,您可以使用以下方法隐藏它们:
ask links [ set hidden? true ]
我有一个程序,其中每个节点都有自己的其他节点排名系统,NetLogo 实现这个的最佳方法是什么?
通常,我会用二维列表来解决这个问题:
[[turtle 1, score], [turtle 2, score], ...]
但这在 NetLogo 中似乎很麻烦。这是我创建和修改二维列表的代码:
to test
clear-all
crt 10
;Create a list of turtles
let agents-list [self] of turtles
;Create empty list, which will be the top level of the TwoD list
let TwoD-list []
;Populate the TwoD-list: [[turtle 0, 0], [turtle 1, 0], ...]
foreach agents-list [
set TwoD-list (lput (list ? 0) TwoD-list)
]
show TwoD-list
repeat 5 [
;Change a value in the TwoD-list
let rand-index random (length TwoD-list) ;select a random index
;The next line is what makes it a huge headache, basically you have to select a list at the top level to replace, and then select the list at the lower level to replace it.
;This entire line of code is just adding one to an element
set TwoD-list (replace-item rand-index TwoD-list (replace-item 1 (item rand-index TwoD-list) (item 1 (item rand-index TwoD-list) + 1)))
show TwoD-list
]
end
我还能做什么?或者有没有更好的方法来实现这个方法?
如果你想模拟代理之间的关系,NetLogo 有完美的选择:links!
让每只海龟给所有其他海龟打分可以很自然地表示为:
directed-link-breed [ rankings ranking ]
rankings-own [ score ]
to setup
clear-all
create-turtles 10
ask turtles [ create-rankings-to other turtles ]
; increment 5 random rankings by one:
ask n-of 5 rankings [ set score score + 1 ]
; display the rankings of each turtle:
ask turtles [ show [ (word end2 " " score) ] of my-out-rankings ]
end
如果您不想让链接显示在视图中,您可以使用以下方法隐藏它们:
ask links [ set hidden? true ]