list - Netlogo:如何为列表中的每只海龟创建链接?

标签 list netlogo nested-lists

我正在尝试将一个品种 (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/

相关文章:

python - 如何使用 txt 文件交叉检查列表

NetLogo:包含相似元素的配对列表

c# - .net 3.5 中是否有元组之类的东西

Python,同时将类创建 append 到列表a

primes - 如何实现像 Netlogo 中的 Ulam 螺旋那样的方形螺旋?

simulation - Netlogo:Ask 预期此输入是一个命令 block ,但得到的是一个数字

python - 删除列表中包含的子列表

C# list of lists - 如何使列表中的列表具有唯一性和抗版本性?

python - 嵌套列表的 'in' 运算符的替代方案

java - 为什么操作 LinkedList 节点别名可以让这个方法起作用?