我正在尝试将一个品种 (a) 中最近孵化的一只海龟与另一个品种 (b) 的前 N 只海龟联系起来。我尝试了很多方法,但现在我陷入了困境......我最后的想法是创建一个从我孵化的海龟到列表中的每只海龟的链接,但它不起作用......这是我的一些试用代码:
(一)
set rank (sort-by [[feat] of ?1 > [feat] of ?2] breed-b)
;;; creates a concatenated list of turtles from breed-b on
;;; descending order of [feat] like: [[(turtle 6) (turtle 2) (turtle 0)]]
hatch-breed-a 1 [
let n 3
;;; I want to create-link-with the top n turtles of rank
repeat n [
ask self [ create-link-with item 0 (item 0 rank) ]
set rank remove-item 1 rank
] ]
;;; my idea was to create a link with the first turtle of the list,
;;; then remove that turtle form the list before the next iteration
;;; so that the next link would be created with the turtle
;;; that was originally the second, but I receive an error message:
;;; ITEM expected input to be a string or list
;;; but got the turtle (turtle 6) instead.
(二)
set rank (sort-by [[feat] of ?1 > [feat] of ?2] breed-b)
;;; creates a concatenated list of turtles from breed-b
;;; on descending order of [feat] like: [[(turtle 6) (turtle 2) (turtle 0)]]
hatch-breed-a 1 [
let n 3
;;; I want to create-link-with the top n turtles of rank
let i 0
while [i < n] [
ask self [ create-link-with item i rank ]
set i i + 1
] ]
;;; my idea here was to create an index (i) so that the while
;;; would only take the first n items of rank, but apparently
;;; item don't accept a variable (i) only numbers.
非常感谢任何帮助,谢谢!
最佳答案
听起来你想要孵化
create-links-with max-n-of n breed-b [feat]
关于list - Netlogo:如何为列表中的每只海龟创建链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29354555/