One Turtle Per Patch Example
Model was written in NetLogo 5.0.4
•
Viewed 9789 times
•
Downloaded 416 times
•
Run 1 time
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
;; SET UP THE WORLD to setup clear-all ;; Color the patches so they're easier to see ask patches [ set pcolor random-float 2 ] ;; The easiest way to ensure that we start with only one ;; turtle per patch is to use "sprout" to have the patches ;; create the turtles ask n-of num-turtles patches [ sprout 1 ] reset-ticks end ;;; ABOUT THE STRATEGIES ;; Which of the following techniques is appropriate for your model ;; depends on what you're modeling. The different techniques have ;; different pros and cons. For example, how far the turtles move ;; each time varies with the different strategy: ;; ;; Strategy #1: A turtle sometimes moves 1, sometimes doesn't move ;; at all. Even if it moves, it sometimes still remains on the same ;; patch. ;; ;; Strategy #2: A turtles always moves at least 1, but it may move ;; an indefinitely large distance if it takes it a long time to find ;; an empty patch. ;; ;; Strategy #3: If there is an adjacent empty patch, the turtle will ;; always move to it, otherwise it will stay put. Turtles always ;; occupy the center of patches. ;; ;; These aren't the only possible strategies -- there are lots of ;; possible ways you could modify or combine these strategies. ;;; ;; TURTLE STRATEGY #1: ;; If the patch ahead has no other turtles on it, then move onto ;; it, otherwise turn a random direction and wait until next time ;; before trying to move again. A subtle point here is that "fd 1" ;; doesn't always take you to a new patch, because along the ;; diagonal, a patch is 1.414... units big. to go-if-empty-ahead ask turtles [ ifelse not any? other turtles-on patch-ahead 1 [ fd 1 ] [ rt random 360 ] ] tick end ;; TURTLE STRATEGY #2: ;; Check neighboring patches to see if any are empty. If any are ;; empty, pick a random empty one and move onto its center. ;; Note that we can't just do "fd 1", since the patch's center ;; might be more than 1 unit away from our current position. to go-if-empty-nearby ask turtles [ let empty-patches neighbors with [not any? turtles-here] if any? empty-patches [ let target one-of empty-patches face target move-to target ] ] tick end ;; TURTLE STRATEGY #3: ;; Keep moving forward until standing on an empty patch. (The ;; Segregation model in the Models Library uses a variant of ;; this strategy.) Note that theoretically this could end up ;; stuck in an infinite loop if all the patches the turtle ;; crosses are always occupied, but this is very unlikely ;; to happen in practice. to go-until-empty-here ;; turtle procedure ask turtles [ fd 1 while [any? other turtles-here] [ fd 1 ] ] tick end ; Public Domain: ; To the extent possible under law, Uri Wilensky has waived all ; copyright and related or neighboring rights to this model.
There are 10 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
One Turtle Per Patch Example.png | preview | Preview | over 11 years ago, by Reuven M. Lerner | Download |
This model does not have any ancestors.
This model does not have any descendants.