demo downhill-in-bounds

demo downhill-in-bounds preview image

1 collaborator

Hobbes286x286 Rik Blok (Author)

Tags

agent-based model 

Tagged by Rik Blok over 10 years ago

bounded 

Tagged by Rik Blok over 10 years ago

diffuse-in-bounds.nls 

Tagged by Rik Blok over 10 years ago

diffusion 

Tagged by Rik Blok over 10 years ago

output-wrap.nls 

Tagged by Rik Blok over 10 years ago

random-walk.nls 

Tagged by Rik Blok over 10 years ago

sigfigs.nls 

Tagged by Rik Blok over 10 years ago

spatial 

Tagged by Rik Blok over 10 years ago

updownhill-in-bounds.nls 

Tagged by Rik Blok over 10 years ago

Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0.4 • Viewed 527 times • Downloaded 34 times • Run 0 times
Download the 'demo downhill-in-bounds' modelDownload this modelEmbed this model

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

__includes [
  "diffuse-in-bounds.nls"      ; Same as diffuse but only for patches in bounds.
  "output-wrap.nls"            ; Same as output-print but wraps printed output.
  "sigfigs.nls"                ; Like precision but specifies number of significant figures.
  "random-walk.nls"            ; Random walk.
  "updownhill-in-bounds.nls"   ; Like uphill/downhill but only for patches in bounds.
]


patches-own
[ wall?
  source?
  sink?
  redness
]


turtles-own
[
  age
]

globals
[  ; Variable 'dt' not needed here if using System Dynamics Modeler.
  dt  ; Time step.  Automatically set in 'go' by 'per-capita-tau-leap'.
]

to startup
  setup  ; Might as well setup when model loaded.
end 

to setup
  clear-all
  reset-ticks
  output-wrap 27 ; Set output box to wrap at column 27.
  output-wrap 
  ( word "Demonstrates hill climbing with bounds.  Blue patches are walls that block "
    "movement.  The red property diffuses within bounds and the turtles attempt to "
    "follow the gradient downhill (from white to black).\n\n"
    "Choose the wall-density and number of sources-and-sinks, then press 'setup'. "
    "Note that the edges also act as walls.\n"
  )
  output-wrap
  ( word "Press 'go' to start diffusing and movement.  The rate of diffusion is determined by "
    "the log-diffusion and err-tolerance sliders.\n"
  )
  ask patches
  [ set source? false
    set sink?   false
    set wall? random-float 1 < wall-density
    if-else wall? 
    [ set pcolor blue 
    ]
    [ set redness 5
    ]    
  ]
  ask n-of sources-and-sinks patches with [not wall?]
  [ set source? true set redness 10 ]
  ask n-of sources-and-sinks patches with [not wall? and not source?]
  [ set sink? true set redness 0 ]
  color-patches
  ask patches with [not wall? and not source? and not sink?]
  [ sprout 1
    [ set size 1
      set color green
      set age random world-width
    ]
  ]
end 

to go
  if ticks = 0
  [ output-wrap
    ( word "Green turtles move downhill (from white to black), avoiding blue walls "
      "until they get too old or reach a black sink.  Then they respawn at a random "
      "new location and continue downhill.  Some turtles get stuck trying to push "
      "through walls.  Meanwhile, the red property diffuses from "
      "the white sources to the black sinks.\n"
    )
  ]
  ; assume err = fraction = diffusion-const * dt
  set dt inaccuracy / diffusion-const
  ask patches with [source?] 
  [ set redness 10 
  ]
  ask patches with [sink?]
  [ set redness 0
  ]
  if-else (neighborhood = "4 neighbors") 
  [ diffuse4-in-bounds "redness" inaccuracy task [not wall?]
  ]
  [ diffuse-in-bounds "redness" inaccuracy task [not wall?]
  ]
  color-patches
  ask turtles 
  [ if-else (neighborhood = "4 neighbors") 
    [ set heading towards-downhill4-in-bounds task [ redness ] task [ not wall?]
    ]
    [ set heading towards-downhill-in-bounds task [ redness ] task [ not wall?]
    ]
    set age age + dt
    if sink? or age > world-width ; don't let get older than it takes to cross fraction of world
    [ move-to one-of patches with [not wall?]
      set age 0
    ]
  ]
  random-walk-in-cone-bounds turtles dt 180 * sqrt dt task [not wall?]
  tick-advance dt
end 

to-report diffusion-const
; Used by 'go' in call to 'diffuse-individual'.
  report 10 ^ log-diffusion
end 

to-report inaccuracy
; Complement of accuracy, depends on err-tolerance.
; Used by 'go' in call to 'per-capita-tau-leap'.
  report 10 ^ ( err-tolerance )
end 

to color-patches
  ask patches with [ wall? = false ]
  [ set pcolor scale-color red redness 0 10 
  ]
end 

There is only one version of this model, created over 10 years ago by Rik Blok.

Attached files

File Type Description Last updated
demo downhill-in-bounds.png preview Preview for 'demo downhill-in-bounds' over 10 years ago, by Rik Blok Download
diffuse-in-bounds.nls extension Same as diffuse but only for patches in bounds. over 10 years ago, by Rik Blok Download
output-wrap.nls extension Same as output-print but wraps printed output. over 10 years ago, by Rik Blok Download
random-walk.nls extension Random walk. over 10 years ago, by Rik Blok Download
sigfigs.nls extension Like precision but specifies number of significant figures. over 10 years ago, by Rik Blok Download
updownhill-in-bounds.nls extension Like uphill/downhill but only for patches in bounds. over 10 years ago, by Rik Blok Download

This model does not have any ancestors.

This model does not have any descendants.