Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Age on Turtles

Tags:

netlogo

I have my turtles own age as one of their variables and I have age set to ticks so that my turtles age whenever they reach a certain number of ticks. However, this causes all turtles to age at the same time (say when ticks = 5), regardless of when they've been created.

Is there any way to get the age to start when the turtle is created? So if the turtle would be created at tick 5, its age starts at zero, but is still equal to the same length as 1 tick?

Yes! Sorry! Here is the code I've been playing with before I put it into my actual model

breed [kids kid]
breed [adults adult]
breed [elderlies elderly]

turtles-own [age
  z]

to setup
  clear-all
  create-kids 10
  [setxy random-xcor random-ycor]
  set-default-shape kids "fish"
  create-adults 10
  [setxy random-xcor random-ycor]
  set-default-shape adults "person"
  set-default-shape elderlies "cow"

  clear-output
  reset-ticks
end

to go
  ask kids [birthday
    move]
  ask adults [birthday
    reproduce-adults
    move]
  tick
end

to birthday
  set age ticks
  if age > 5 [set breed adults]
  if age > 10 [set breed elderlies]
  if age > 15 [die]
end

to reproduce-adults
  set z random 100
  if z > 65
  [ hatch-kids 1]
end

to move
  rt random 360
  fd 1
end
like image 245
Dana Avatar asked May 15 '26 17:05

Dana


2 Answers

In your go procedure, include ask turtles [increment-age], where

to increment-age
  set age (1 + age)
end
like image 50
Alan Avatar answered May 18 '26 07:05

Alan


Alan's solution is good if you want age to be equal to the number of ticks since a turtle was created. You can divide that number by another number if you want a different measure of age. For example, if ticks represent months, you can divide by 12 to get years.

Another method involves adding birth-tick--the tick on which the turtle was "born"--as a turtles-own variable. Suppose that you want to increment the age every 5 ticks. Then you could write increment-age like this:

to increment-age
  let age-in-ticks birth-tick - ticks
  if (age-in-ticks > 0) and (age-in-ticks mod 5 = 0) [
    set age (1 + age)
  ]
end

The expression containing mod tests whether the number of ticks since birth is evenly divisible by 5.

EDIT: I should clarify that you'll need to set birth-tick to the value of ticks at the time that each turtle is created.

like image 36
Mars Avatar answered May 18 '26 07:05

Mars



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!