0

I am trying to build a model where turtle move one patch per tick with random movement. I am looking for a solution to increase the number of turtle per tick based on the percentage. For ex. In the beginning there are 7 turtles, by each tick they should increase by following percentage:

10.72% 10.83% 10.93% 11.03% 11.11% 11.19% 11.27% 11.33% 11.39% 11.45%

Not sure if this is possible? If needed this can be round up to whole number.

If this is not possible, how can I increase the turtle number by 11% each tick for 10 ticks then after 12% each tick for another 10 ticks and so on?

Below is the code that I am using.


to setup
  clear-all
  setup-turtles
  setup-patches
  reset-ticks
end
to setup-patches
  ask patches [ set pcolor green ]
end
to setup-turtles
  create-turtles tourists [setxy random-xcor random-ycor ]
  ask turtles [ set shape "person" set size 2 ]
end
to go
  if ticks >= 130 [ stop ]
  move-turtles
  eat
  tick
end
to move-turtles
  ask turtles [ right random 360 forward 1]
end
to eat
  ask turtles [ if pcolor = green [ set pcolor black ] ]
end

Thank you for your support. Avi

Alex P.
  • 3,073
  • 3
  • 22
  • 33
Avi
  • 1
  • What is the thing that needs to increase? For example, is it a variable (attribute) that the turtle owns? Or is the increase something to do with the movement? – JenB Nov 27 '17 at 13:30
  • Thanks for the response JenB. Increase is related to the movement. With each tick each turtle must move one step on a green patch and consume the green space and turn it into black. (probably even that part is not correct in my model because the move is random, which means turtles might be moving on the black patches as well, I would greatly appreciate if you could also help me with that) and the number of turtles needs to be increased if possible by percentage if not by numbers. I have limited understanding of the programming, so any help would be highly appreciated. Thank you. – Avi Nov 27 '17 at 22:40
  • so you want to create additional turtles to make the total number of them increase? if you start with 7 turtles, then a 10.72% increase gets you to 7.75 turtles, so this doesn't really make sense. Really, it is also best to get one thing working at a time. I would start with moving, then eating and then worry about increasing turtles. – JenB Nov 27 '17 at 23:29
  • Got it thanks. In that case how can I make it for all 7 turtles to move on only green patches each time and increase turtle numbers, let's say one more turtle on each tick? So it starts with 7 turtles and next tick it increase to 8 turtles and so on? Is this possible? Thanks a lot for your help with this. – Avi Nov 28 '17 at 09:14

1 Answers1

0

I think your model is very similar to 'Rabbits Grass Weeds' in the Models Library so you might want to have a look at that to get some ideas. Focusing just on the revised question of moving to a green patch, you need with, which will restrict choices. Note that the code below will break if there are no neighbouring patches that are green.

to setup
  clear-all
  setup-turtles
  setup-patches
  reset-ticks
end

to setup-patches
  ask patches [ set pcolor green ]
end

to setup-turtles
  create-turtles 7 [setxy random-xcor random-ycor ]
  ask turtles [ set shape "person" set size 2 ]
end

to go
  if ticks >= 130 [ stop ]
  move-turtles
  increase-turtles
  tick
end

to move-turtles
  ask turtles [ move-to one-of neighbors with [pcolor = green] ]
end

to increase-turtles
  ask one-of turtles [ hatch 1 ]
end

I used hatch in this code, which gets one turtle to create another turtle at the same place with the same colour etc. If you want to just create a new turtle in exactly the same way as your original turtles, then you want something more like this.

to setup
  clear-all
  make-turtles 7
  setup-patches
  reset-ticks
end

to setup-patches
  ask patches [ set pcolor green ]
end

to make-turtles [ num ]
  create-turtles num
  [ setxy random-xcor random-ycor
    set shape "person"
    set size 2
  ]
end

to go
  if ticks >= 130 [ stop ]
  move-turtles
  increase-turtles
  tick
end

to move-turtles
  ask turtles [ move-to one-of neighbors with [pcolor = green] ]
end

to increase-turtles
  make-turtles 1
end

In this case, I have made a new procedure (called make-turtles) that creates as many turtles as you specify, randomly locates them etc. In setup, I call it to make 7 turtles, and then later on just make 1 each time.

JenB
  • 17,620
  • 2
  • 17
  • 45
  • This is very helpful. Second option best suits my need. For now I have only one issue, as you mentioned, the code breaks when there are no green neighboring patches. To solve this, Is it possible to start all the turtles from the left end of patches. For example in the beginning they are all created in a column format on the left end of patches, this way if their movement is only forward then they will always go on the green. Finally, is it possible to make increase turtle code so that it only makes new turtles in the remaining green patches? thank you for suggesting 'Rabbits Grass Weeds'.Thx – Avi Nov 28 '17 at 17:09