WHO number separately for each BREED

Skip to first unread message

Luka Grgičević

Jan 5, 2024, 2:29:46 PMJan 5
to netlogo-users
Is there any incentive to make this possible in the future? It would be really cool to have this... soon :)

James Steiner

Jan 26, 2024, 12:14:15 AMJan 26
to netlogo-users

It's often said here that if you're depending on who numbers, don't.

That said, if you want each breed to have its own unique sequence, you can easily implement that yourself.

a. Add a global variable for each breed, like "actors-who"
b. give the turtles or the breed a breeds-own variable, like "breed-who"
c. create a setup reporter for each breed, that either fully sets up the agent, or creates and returns a reference go the new agent.
d. in that procedure, increment the global breed counter and apply the  value to the breed-who variable of the new agent
e. as a bonus, make the setup procedure context-agnostic by asking a patch to sprout the turtle. Then any other agent or the observer can use that procedure to create an agent.
f. only ever use that procedure to create any agent of that breed.

tah dah.

On Fri, Jan 5, 2024 at 2:29 PM Luka Grgičević <lgrg...@gmail.com> wrote:
Is there any incentive to make this possible in the future? It would be really cool to have this... soon :)

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/1f04e30c-3d5e-4640-a0e3-f911274f5182n%40googlegroups.com.

Paolo Gaudiano

Jan 26, 2024, 7:52:27 AMJan 26
to netlogo-users
I just had to do something similar mostly for convenience: I have a simulation with several breeds (company, employee, customer, etc.). Sometimes especially when testing or debugging I want to type a command in the command center such as “show [ var ] of employee 0”, but if employees are created after companies that makes it a pain in the butt to figure out the who.

Without the need for a global tracker, I added an employees-own variable “my-breed-counter”, and when I create the employee I add the following command:
    set my-breed-counter who - ( [ who ] of min-one-of breed [ who ] )
This will work for any breed (note I added the parentheses for clarity but they are not needed)

Note that if a turtle dies somewhere along the way, and you create more of the same breed, this could have unexpected results. However, you can create a function of this type to reset all the counters:

  ask employees [ set my-breed-counter 0 ] ; Reset all counters to zero
ask employees [ set my-breed-counter who - [ who ] of min-one-of breed [ who ] ]
I am attaching a simple program that plays around with this and displays it so you can check things out.


Aleria   |  ARC  |  NYU    Forbes   |  TEDx   |  @icopaolo   |  LinkedIn   |    Pronouns:  He/Him/His  |  Name pronunciation
Reply all
Reply to author
0 new messages