Partners Example
Model was written in NetLogo 5.0.4
•
Viewed 344 times
•
Downloaded 48 times
•
Run 2 times
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
turtles-own [ partner ;; the turtle that is our partner, or "nobody" if we don't have one ] ;; This procedure will setup 150 turtles, by randomly placing them around the world. to setup clear-all create-turtles 150 [ ;; turtles get random coordinates, and they are ;; light gray (to show they don't have partners yet). setxy random-xcor random-ycor set color gray + 2 set partner nobody ] reset-ticks end ;; have each turtle move until they find a partner at which point they turn red to find-partners let singles turtles with [partner = nobody] if not any? singles [ stop ] ;; In this example, only turtles that haven't found a partner can move around. ask singles [ ;; Randomly move about the world lt random 40 rt random 40 fd 1 ] ;; Now that all unpartnered turtles have moved, ask the unpartnered turtles to check if they ;; are on a patch with a turtle that also don't have a partner. ask turtles [ if (partner = nobody) and (any? other turtles-here with [partner = nobody]) [ ;; There could be more than one partner to choose from, so we use one-of ;; to randomly choose one of the turtle without a partner set partner one-of other turtles-here with [partner = nobody] ;; We graphically show that we have a partner by turning red. set color red ask partner [ ;; Ask our partner to partner with ourselves. set partner myself ;; Color my partner red too set color red ] ] ] ;; As a check on the correctness of the code, let's make sure that ;; the partner assignments are consistent. if any? turtles with [partner != nobody and [partner] of partner != self] [ ask one-of turtles with [[partner] of partner != self] [ user-message (word "Oops! Partner mismatch: " self " is not partnered to " myself) ] stop ] 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 | |
---|---|---|---|---|
Partners Example.png | preview | Preview for 'Partners Example' | over 11 years ago, by Uri Wilensky | Download |
This model does not have any ancestors.
This model does not have any descendants.