Netlogo:如何为列表中的每只海龟创建一个 link?
Netlogo: How to create a link with every turtle of a list?
我正在尝试 link 一个品种 (a) 最近孵化的海龟与另一个品种 (b) 的前 N 只海龟。我尝试了很多东西,但现在我被卡住了......我最后的想法是从我孵化的海龟到列表中的每只海龟创建一个 link,但它不起作用......这是我的一些试用代码:
(我)
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]
我找到了代码 (I) 的工作方式:
repeat n [
ask self [
create-share-with (first rank) ]
set rank but-first rank
]
我正在尝试 link 一个品种 (a) 最近孵化的海龟与另一个品种 (b) 的前 N 只海龟。我尝试了很多东西,但现在我被卡住了......我最后的想法是从我孵化的海龟到列表中的每只海龟创建一个 link,但它不起作用......这是我的一些试用代码:
(我)
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]
我找到了代码 (I) 的工作方式:
repeat n [
ask self [
create-share-with (first rank) ]
set rank but-first rank
]