Alyssa T
Alyssa T

Reputation: 79

Trouble specifying agent's location and sprout command

The objective of my submodel is to simulate how wolf agents avoid patches that have human densities above the wolves' tolerance threshold. When running my model, the sprout command is not generating the number of human agents in the urban patch like I would expect it to. The code for creating humans in the urban patch is:

ask patches [ if self = urban-patches [sprout-humans initial-number-humans]]

Here is the image of my Interface Tab:NetLogo space

The grey is coded as my urban-patches, brown is grass-patches, and green is forest-patches. Why are my human agents not appearing in the grey (urban) patches with the number of agents reflecting the initial-number-humans?

Here is the code for creating the human agents:code

I have specified the xy coordinates of the human agent to be located within the urban (grey) patch, but only one human agent appears when I run the model. How do I correctly code the initial-number-humans to connect with the sprout command?

Upvotes: 0

Views: 93

Answers (1)

JenB
JenB

Reputation: 17678

As I think you have now discovered, the easiest way to distribute a set number of turtles randomly across a group of patches is to use create-turtles rather than sprout. This is because sprout creates the specified number of turtles on each patch that is sprouting them so you need to juggle the total to be created and the number of patches. But that option is useful if you want to achieve even distribution rather than random locations. Here is code that does both.

globals [urban-patches n-humans]

to setup
  clear-all
  set urban-patches n-of 20 patches
  ask urban-patches [set pcolor gray]
  set n-humans 100
  make-humans-sprout
  make-humans-create
end

to make-humans-sprout
  ask urban-patches
  [ sprout n-humans / count urban-patches
    [ set color red
      set xcor xcor - 0.5 + random-float 1
      set ycor ycor - 0.5 + random-float 1
    ]
  ]
end

to make-humans-create
  create-turtles n-humans
  [ set color blue
    move-to one-of urban-patches
      set xcor xcor - 0.5 + random-float 1
      set ycor ycor - 0.5 + random-float 1
  ]
end

Note that the adjustments to xcor and ycor are because sprout and move-to always place the turtle in the centre of the patch and there is no primitive for placing in a random place on a particular patch.

Upvotes: 1

Related Questions