Help in choosing values ​​from a list

6 views
Skip to first unread message

Karina Santos

unread,
Oct 8, 2021, 8:48:38 AM10/8/21
to netlogo-users
Hello,

I'm trying to find a command to execute the following:

I have 10 turtles that are "born" in each patch of the world (I use the command "sprout"). I would like to implement the following: a memory for the next turtles, ie.: the new fate of a turtle is chosen based on the amount of resources from locations that were previously visited by other turtles. The idea is that 10 turtles from each patch come out to see the 3 places that have the highest resource value (resource is a patch variable). These 3 values of greatest resource I would multiply by a global variable of 30 (simulating that they left after 3 more times each exit with 10 turtles) and then I would simulate that the next turtles were in the places that had the greatest resource that were previously visited by previous turtles.

I think I should create a list, but I don't know how I go about picking the biggest resource values from that list. Is it possible to do that? Could someone help me unlock this part of my code?

Thank you

Wade Schuette

unread,
Oct 8, 2021, 10:07:30 AM10/8/21
to Karina Santos, netlogo-users
I don't understand your total problem but I think the "sort-on" command
will help.   This sorts an agent-set on some property of the agent set and
produces a sorted list. Then you can pull off the last item of the list as
the maximum item.

Here's code:
;;==========================================
patches-own [ x ]
to setup
  clear-all
  let maxval -100;
  let maxpatch "";
 
  ;;========== set up a problem and peek at the answer  ====
  ask patches [
    set x random 100;  
    if ( x > maxval) [
        set maxval x
        set maxpatch self]
  ]
  print ( word "maxval should be " maxval " for patch " maxpatch)
  ;;================= end problem setup
  ;; now solve it using "sort-on"
 
  let mylist sort-on [x] patches
  set maxpatch last mylist
  ask maxpatch [ print (word self " has x value " x ) ]
 
  reset-ticks
end

--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/CABCtG4FKJGghS3mjrXOtjUcRCbHowaskTVQJrjaOxCeifpYtKA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages