1

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

  • Nandoarz- what errors are you running into, or what are you not seeing that you expect to see? – Luke C Mar 28 '17 at 18:17
  • hi luke. it seems i was not able to set my starting point correct as there is sprouting everywhere. – nandonation Mar 28 '17 at 18:20
  • Got it. In that case, can you include more detail? As is, we can't see where you have defined "x-breach" and "y-breach". It might help to include your setup procedure. – Luke C Mar 28 '17 at 18:26
  • it's just a random coordinate of my pre-loaded map 308 and -36 respectively. cell-storage is also a dummy value just to test this code. thanks! – nandonation Mar 28 '17 at 18:30
  • Nands- I'm still not quite sure what you actually want to do. Are you trying to have cells fill up and then "spill over" into neighboring cells? As far as why every cell is sprouting, it's because in your `water_rise` procedure, you are querying *all* patches with your `if any? neighbors4 ...` line. – Luke C Mar 28 '17 at 19:08

1 Answers1

1

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.

Luke C
  • 10,081
  • 1
  • 14
  • 21
  • thanks luke! this helps a lot especially the fill-rate variable. I'm still confused why it's not starting at my desired breach point. if you mind, i can give you the whole script. thanks! – nandonation Mar 29 '17 at 05:52
  • I'd be happy to take a look. Is your code very long, or could you just edit your question above and in what is necessary? – Luke C Mar 29 '17 at 06:03
  • Nands can you include setup to show your variable definition? It would help know why it isn't starting at your breach point- in the model I linked to above, you can just edit the `patch 0 0` to your breach point coordinates and it will start there- does that not accomplish what you need? Also, there are some errors in your code- for example, I can't run it as is. Eg. `ask patches with [pcolor != blue]` (what are you asking them to do?). – Luke C Mar 29 '17 at 07:32
  • Hi Luke. Sorry for the late reply. Your suggestion actually helped and I successfully run my model. Thanks a lot again! – nandonation Apr 07 '17 at 14:35