Search code examples
variablesnetlogopatchnearest-neighborflood-fill

Netlogo: Set patch variable value to neighboring patch variable value


I am new to NetLogo and trying to simulate flooding after repeated rainstorms. The model generates flood turtles on random patches every 20 ticks and has a randomly generated topography. Patch variables include [water-level] [elevation] [capacity].

Elevation is randomly generated, and [water-level] = [elevation] + [flood_no], or elevation plus the the number of flood turtles on top of each patch. So far, I have been able to make the flood turtles travel downhill. My issue is that I want them to pool and then spill over to the appropriate neighboring patch once the [capacity] of each patch is reached.

I am trying to make each patch determine its capacity by equating it to the lowest water-level value found among its neighbors. However, when I run the model, NetLogo gives me the patch coordinates for the neighboring patch with the lowest water-level value instead of the actual water-level value itself:

patches-own [elevation water-level capacity]
breed [floods flood]
floods-own [flood_no]

ask patches [set capacity min-one-of neighbors [water-level]] ;this gives me the patch coordinates with the lowest water-level out of each patches' neighbors 

Is there any way I can change this to make it give me the patch variable value instead of just the patch location?


Solution

  • min-one-of is about identifying the patch, so you could do it in two steps:

    ask patches
    [ let low-patch set min-one-of neighbors [water-level]
      set capacity [water-level] of low-patch
    ]
    

    But more directly, you can find the minimum value of the variable using min:

    ask patches [set capacity min [water-level] of neighbors ]
    

    Internally, NetLogo creates a list of the water-level values for the neighbouring patches with the of primitive, and then min just takes the minimum of that list. So in two steps, it would look like:

    ask patches
    [ let nbr-levels [water-level] of neighbors
      set capacity min nbr-levels
    ]