Hill Climbing Example 3D
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
This example shows make a terrain in 3D and move turtles across the terrain. This is much like the Hill Climbing Example in 2D. However, the elevation variation in the terrain is visible in the 3D space.
THINGS TO NOTICE
The hill climbing code is very similar to UPHILL in 2D. However, we want the turtles to look at the link neighbors of the stayer here rather than the patch neighbors.
NETLOGO FEATURES
Note that terrain models are not full 3D models. Each spot on the landscape only has eight neighbors; we use links to indicate the neighbors of each location since it cannot be determined spatially. We do, however, use the 3D space to display the height of each location.
Comments and Questions
breed[ stayers stayer ] ;; the actual points of the landscape breed[ walkers walker ] ;; turtles that move around the landscape walkers-own [ peak? ;; indicates whether a turtle has reached a "peak", ;; that is, it can no longer go "uphill" from where it stands ] patches-own [elevation] to setup clear-all ask patches [ set elevation 0 ] ;; make a landscape with hills and valleys ask n-of 10 patches with [pzcor = 0 ] [ set elevation 120 ] ;; slightly smooth out the landscape repeat 10 [ diffuse elevation 1 ;; the terrain does not require use of the 3D patch grid just the 3D ;; space to display the terrain so when we diffuse add anything ;; diffusing up and down back to the first layer of patches. ask patches with [pzcor = 0 ] [ set elevation elevation + [elevation] of patch-at 0 0 1 + [elevation] of patch-at 0 0 -1 ask patch-at 0 0 1 [ set elevation 0 ] ask patch-at 0 0 -1 [ set elevation 0 ] ] ] let max-elevation max [elevation] of patches ;; use turtles and links to display the landscape ;; each patch has one stayer which is linked to ;; the neighboring stayers ask patches with [pzcor = 0] [ sprout-stayers 1 [ create-links-with turtles-on neighbors ht ] ] ;; each stayer is set at a height proportional ;; to the elevation of the patch ask stayers [ set zcor (elevation / max-elevation) * max-pzcor ] ;; put some turtles on patch centers in the landscape ask n-of 80 stayers [ hatch-walkers 1 [ st set peak? false set color red pd set pen-size 3 ] ] end to go ;; stop when all turtles are on peak if all? walkers [peak?] [ stop ] ask walkers [ let here one-of stayers-here ;; this is essentially uphill except that we use link-neighbors ;; rather than patch neighbors let there max-one-of [link-neighbors] of here [zcor] ;; when there are no more higher neighbors we're on a peak ;; and it's time to stop ifelse [zcor] of there > [zcor] of here [ face there move-to there ] [ set peak? true ] ] tick end ; Copyright 2007 Uri Wilensky. This code may be freely copied, distributed, ; altered, or otherwise used by anyone for any legal purpose.
There are 3 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Hill Climbing Example 3D.png | preview | Preview for 'Hill Climbing Example 3D' | over 11 years ago, by Uri Wilensky | Download |
This model does not have any ancestors.
This model does not have any descendants.