ULM
ULM

Reputation: 67

Netlogo: How to create a link with every turtle of a list?

I'm trying to link a recently hatched turtle from a breed (a) with the top N turtles of another breed (b). I tried many things but now I'm stuck... My last idea was to create a link from my hatched turtle to every turtle in a list, but it's not working... Here's some of my trial codes:

(I)

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.

(II)

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.

I appreciate any help with this, thanks!

Upvotes: 2

Views: 752

Answers (2)

ULM
ULM

Reputation: 67

I have found a way for code (I) to work:

repeat n [ 
  ask self [ 
    create-share-with (first rank) ] 
  set rank but-first rank 
  ]

Upvotes: 0

Alan
Alan

Reputation: 9610

It sounds like you want the hatched to

create-links-with max-n-of n breed-b [feat]

Upvotes: 2

Related Questions