Search code examples
netlogopatchcellular-automata

bathtub model sprout using decision rules


newbie in netlogo here. I'm simulating a flood model using cellular-automata. It's just a simple one - cell should be filled (change color) or sprout if water > elevation.

For a dummy code, I'm trying to do it this way:

to go
    ask patches with [pcolor != blue] ;remove ocean 
    water_rise
    tick
end

 to water_rise ; saturates cell
  if not any? turtles [
    ask patch x-breach y-breach [     ;;; This will be the breach patch, will start to fill at first tick, a specific location in my map
      set cell-storage elevation * fill-rate
    ]
  ]
  ask patches [
    ;;; This has a patch check if any neighbors have sprouted.
    ;;; If any have, that patch starts to fill.
    if any? neighbors4 with [ any? turtles-here ] [
       set cell-storage elevation * fill-rate
      let minv min [ cell-storage ] of patches
      let maxv max [ cell-storage ] of patches
      set pcolor scale-color green cell-storage 0 5 ;idea is to have a graduated color depending on fill stage
    ]
  ]
  ;;; Once all patches have had a chance this tick to fill,
  ;;; see if any are "full"
  ask patches [
    if cell-storage > elevation [
        ;; If the patch gets "full" and they have not already sprouted,     
    if not any? turtles-here [
      sprout 1 [
        set color yellow
        set size 1
        set shape "square"
      ]
  ]

]

] end Thanks in advance!

BTW, I'm working on a DEM re: elevation values.

I set fill-rate as a slider with 0.3 for now.

-Nands


Solution

  • I played around with this a little and it seems to me like you want your starting patch to fill up, and once it hits its maximum value, to start flooding into other cells that repeat the process. I think the main problem is that in your water-rise, you have are asking all patches with elevation greater than -9999 to first call the starting-point procedure and then also to sprout a turtle if they have any neighbors with elevation is less than cell-storage. It appears that all patches satisfy that condition, so all patches will sprout a turtle.

    It may work better to rework your flow of logic, so that filling up your breach patch is independent of other patches. Something like:

    to water_rise ; saturates cell
      if not any? turtles [
        ask patch 0 0 [     ;;; This would be your breach patch, will start to fill at first tick
          set cell-storage cell-storage + fill-rate
        ]
      ]
      ask patches [
        ;;; This has a patch check if any neighbors have sprouted.
        ;;; If any have, that patch starts to fill.
        if any? neighbors4 with [ any? turtles-here ] [    
          set cell-storage cell-storage + fill-rate        
        ]
      ]
      ;;; Once all patches have had a chance this tick to fill,
      ;;; see if any are "full"
      ask patches [
        if cell-storage > 0 [
          if cell-storage > 5 [              
            set cell-storage 5 
            ;; If the patch gets "full" and they have not already sprouted, sprout 1
            if not any? turtles-here [     
              sprout 1 [
                set color yellow
                set size 0.5
                set shape "circle"
              ]
            ]
          ]
          set pcolor cell-storage + 82
        ]
      ]
    end
    

    Full toy model with variables and setup here.

    Obviously, you would need to modify your starting patch (I used 0 0 for convenience and simplicity). Additionally, I included fill-rate as a way to slow the rate of filling as more and more patches begin getting filled up.