NetLogo: identification of valleys = rivers location in artificial landscape - netlogo

I want to produce the artificial landscape, containing hills, slopes and valleys. So far, so good. Now, I want to place a rivers in the bottom of the valley. I thought that the easiest way will be ask turtle to move uphill/downhill by elevation as drops here: http://modelingcommons.org/browse/one_model/2352#model_tabs_browse_info
However, as my landscape is not real, my valleys are also not linears, but just the "depressions" in the terrain, and thus my river localisation is really weird looking?
Please, is there a way to create hills and valleys reflecting the real terrain in netlogo without using GIS extension? I've found great models of Erosion, Watershed and GIS gradient example, but how can I initially place my turtles to stay only in valleys?
EDIT
the GIS gradient example provide excellent problem solving of movement of all the cells over the space, and they aggregate in valleys. However, as I want to by movement of my turtle "create" the river bed on the bottom of the valley, how can I place it? maybe start at the lowest point and stop after several ticks to not to allow to get on the top of the hill? thank you !
globals [
low
high
range ]
patches-own [
altitude ]
to setup
clear-all
setup-hills
scale-patches
color-patches
end
to setup-hills
ask n-of 2 patches [
set pcolor magenta ]
ask patches [
let max_dist sqrt (world-width ^ world-width + world-height ^ world-height)
set altitude world-width - distance patch 10 10
set altitude world-width - distance min-one-of patches with [pcolor = magenta][distance myself]
]
crt 1 [ ; create a turtle, needed to identify the lowest slope
set color red
let bottom_valley min-one-of patches [altitude]
move-to bottom_valley
]
end
to scale-patches
set low [altitude] of min-one-of patches [altitude]
set high [altitude] of max-one-of patches [altitude]
set range high - low
ask patches [
set altitude altitude - low ; shift every patch down so lowest altitude is 0
set altitude altitude * 99.0 / range ; scale every patch so that the lowest is 0 and highest is 999
]
repeat 5 [
diffuse altitude 0.5 ]
end
to color-patches
ask patches [
set pcolor scale-color green altitude 0 100]
end
to create-river
ask turtles [
let p max-one-of neighbors in-radius 1 [altitude]
if [altitude] of p >= altitude [
face p
move-to p
set pcolor blue
]
]
end

You have the right general idea. I recommend checking out the "GIS Gradient" model on your landscape. You can find it in the Models Library under Code Examples/GIS. Then think how to filter patches that have a minimum number of water particles passing through it over time.

Identification of system of rivers on the landscape using GIS Gradient Example:
http://modelingcommons.org/browse/one_model/2352#model_tabs_browse_info
The whole process of identification of the river system on the complex landscape is composed by 3 subprocesses:
identify the highest points of the landscape
place here the river source (create-source)
identify patches for a downhill stream
from the highest river source, by decreasing elevetion of neighboring cells to the lowest elevation of the river valley
when turtle reaches the edge of the world, turtle dies (go-downhill)
remove top hill points (as the river does not read the summit of the hill)
the river does not start at the top of the hill, but at the highest point of the valley
the highest "river" patches from the river beds system are removed (remove-river-from-top-hill)
The number of sources depends of type of GIS data you have available. The same for the number of patches you wish to remove from the top of the hill.
;; ----------------------------------------------
;; create river
;; ----------------------------------------------
to create-source
; identify the 5 highest points of the landscape
repeat 5 [
; avoid the highest points to be close to each other
ask max-one-of patches with [ not any? turtles-here and not any? turtles in-radius 20 ] [p_elev] [
;ask patches to sporout turtles
sprout 1 [
set size 1
set color orange
]
]
]
end
to go-downhill
; stop if there is no more turtles
if not any? turtles with [color = orange]
[ stop ]
; ask turtles located on top of thehills to move downhill
ask turtles with [color = orange] [
; die when you reach the edge of the world
if ([pxcor] of patch-here = max-pxcor) or ([pycor] of patch-here = max-pycor)
or ([pxcor] of patch-here = min-pxcor) or ([pycor] of patch-here = min-pycor) [
die ]
move-to patch-here ; go to patch center
set pcolor blue ; identify the use of patch
set p min-one-of neighbors with [pcolor != blue ] [p_elev] ;; or neighbors4 with [pcolor != blue]patches in-radius 3
if p != nobody [
; move downhill if elevation of patch you are standing on is higher then one of the neighboring patches
ifelse [p_elev] of p <= p_elev
[
face p
move-to p
set pcolor blue ; identify the use of patch
]
[
;move-to min-one-of patches with [pcolor != blue] [distance myself]
move-to min-one-of patches in-radius 2 with [pcolor != blue] [p_elev]
set pcolor blue ; identify the use of patch
]
]
]
end
to remove-river-from-top-hill
; remove 5% of the blue (river) patches placed on the top of the hill
let total_blue count patches with [pcolor = blue]
repeat total_blue * 0.05 [
ask max-one-of patches with [pcolor = blue] [p_elev] [
set pcolor yellow ]
]
end
Complex river system identified:
(river bed = BLUE, removed top of the hill = YELLOW):

Related

How to spawn turtles a certain amount of patches away from each other

I am trying to spawn turtles 5 patches away from each other but I'm not sure how, right now they all spawn on green patches (I don't want them to spawn on brown ones) and I'm not sure how exactly you control the distance between the spawning of turtles, thanks.
breed [ humans person ]
breed [ zombies zombie ]
to setup_world
clear-all
reset-ticks
ask patches [
set pcolor green
]
ask n-of 100 patches [
set pcolor brown
]
ask n-of 15 patches with [pcolor != brown][sprout-humans 1 [set size 5
set color blue
set shape "person"]]
ask n-of 5 patches with [pcolor != brown][sprout-zombies 1 [set size 4
set color red
set shape "person"]]
end
Have you read this question: NetLogo Create turtle at regular distance from each other?
Anyway, I thought that showing you some working functions would be helpful, here I made two alternatives, sprout-distanced1 and sprout-distanced2, you can test them both by alternating which line is commented; I also added a slider called Min-Distance to control the turtles spacing.
sprout-distanced1 uses the keyword carefully with is basically a try-else block, it's there in case that the turtle doesn't find a patch distanced enough to move to, in which case rather than sending a warning the turtle will stay where it is and print its distance to the closest turtle.
sprout-distanced2 uses a while loop, in case that the turtle doesn't find a place to move to that is at least Min-Distance from another turtle it will reduce the minimum radius by a small amount until it can distance itself from other turtles, if it had to move to a patch where it is less than Min-Distance away from other turtles it will log the distance at the Command Center.
breed [ humans person ]
breed [ zombies zombie ]
to setup_world
clear-all
reset-ticks
ask patches
[
set pcolor green
]
ask n-of 100 patches
[
set pcolor brown
]
ask n-of 15 patches with [pcolor != brown]
[
sprout-humans 1
[
set size 5
set color blue
set shape "person"
;sprout-distanced1
sprout-distanced2
]
]
ask n-of 5 patches with [pcolor != brown]
[
sprout-zombies 1
[
set size 4
set color red
set shape "person"
;sprout-distanced1
sprout-distanced2
]
]
end
to sprout-distanced1
carefully
[
; try to move at least Min-Distance away from other turtles
move-to one-of patches with [not any? other turtles in-radius Min-Distance]
]
[
; if can't move Min-Distance away from other turtles
; stay put and log the min distance to other turtle, just for reference
show distance min-one-of other turtles [distance myself]
setxy random-xcor random-ycor
sprout-distanced1
]
end
to sprout-distanced2
let min-dist Min-Distance
let moved? FALSE
while [not moved? and min-dist > 0]
[
; can distance it self somewhere?
ifelse any? patches with [not any? other turtles in-radius min-dist]
[
; if yes, go there
move-to one-of patches with [not any? other turtles in-radius min-dist]
set moved? TRUE
; if had to reduce the distancing radious log it
if moved? and min-dist < Min-Distance
[
show distance min-one-of other turtles [distance myself]
]
]
[
; no where to go, reduce the distancing radious
set min-dist min-dist - 0.1
]
]
end
Choose whichever suits better your model.

NetLogo: calculate geographic center of patch-set

I'm modeling territory selection in NetLogo, where turtles pick a territory center ("start-patch") and then build a territory out from there based on value of patches. Turtles always return to the start-patch after claiming a new patch, then choose, move to, and claim the next most valuable patch. After choosing a territory, the turtle knows which patches it owns, and patches know their owner.
Ultimately, the start-patch of a territory may not actually end up being the true geographic center. After a turtle has selected its territory, how might I ask it to evaluate the territory, identify the geographic center, and calculate proximity of the start-patch to the true center of the territory? (Note: I don't want to force turtles to keep the start-patch in the geographic center--they are free to choose any patches they want. But I may force turtles to re-select a territory if there isn't a close match--these territories are not very efficient otherwise.)
Here's an example of how territory start-patches (black stars) do not equal geographic centers. Some example code is below. Any suggestions? Thanks in advance!
patches-own [
benefit ;; ranges 0.1-1 and represents food available in the patch
owner ] ;; patches are owned once selected for a territory
turtles-own [
start-patch ;; the selected center of the territory
sum-value ;; sum of values of patches in my territory
territory-list ;; list of patches I've selected
territory ;; agentset of patches I've selected
established ] ;; true/false, true when has settled in a final territory after assessing geographic center
globals [threshold = 25]
to setup
ask patches [ set owner nobody ]
end
to go
ask turtles [
pick-center
build-territory]
tick
end
to pick-center
if start-patch = 0
[move-to best-center ;; (calculated by a reporter elsewhere as moving windows for a cluster of high-benefit patches)
set start-patch patch-here
set owner self
set territory-list (list patch-here)
set territory (patches with [owner = myself])
]
to build-territory
ifelse sum-value < threshold
[ pick-patch ] ;; keeps picking patches for territory until I've met my threshold
[ assess-geographic-center] ;; once met threshold, assess real center of patch-set
end
to pick-patch
let _destination highest-value ;; (this is calculated by reporters elsewhere based on benefit / travel costs to a patch)
face _destination forward 1
if patch-here = _destination
[ claim-patch _destination ]
end
to claim-patch [_patch]
ask _patch [set owner myself]
set sum-value sum-value + (benefit / (distance start-patch))
set territory-list lput patch-here territory-list
set territory (patch-set territory _patch)
move-to start-patch
end
to assess-geographic-center
;; Once the territory is built, the turtle should identify the actual
;; geographic center of the patch-set it has selected...how to do this?
;; Once it knows the center, the turtle should compare the distance to the original start-patch.
;; If >10 patches away, it will move to that start-patch and start over with selecting a territory....
end
Could you get away with just the mean pxcor and pycor of all patches? Something like:
to setup
ca
reset-ticks
let n 70
ask one-of patches [
set pcolor red
]
while [ ( count patches with [pcolor = red ] ) < n ] [
ask one-of patches with [ pcolor = red ] [
ask one-of neighbors4 [set pcolor red ]
]
]
let xmean mean [pxcor] of patches with [ pcolor = red ]
print xmean
let ymean mean [pycor] of patches with [ pcolor = red ]
print ymean
ask patch xmean ymean [ set pcolor blue
]
end
Following the previous answer, here is what I came up with. This goes in the last procedure in my original code:
to assess-geographic-center
let xmean mean [pxcor] of patches with [ owner = myself ]
let ymean mean [pycor] of patches with [ owner = myself ]
ask patch xmean ymean [ set pcolor black ] ;; make the geographic center visible
let geographic-center patch xmean ymean
let distance-away distance geographic-center ;; the turtle is on its start-patch when assessing this distance
ifelse distance-away <= 5
[ set established true ] ;; turtle is happy if start-patch and geographic-center are approximately equal, territory "established"
[ move-to geographic-center ;; otherwise, turtle moves to geographic-center,
reposition ] ;; and follows a procedure "reposition" to makes this the new start-patch and repick the territory
end

Create clusters of patches without changing occurrence

I am writing a Netlogo model which only involves patches. I have managed to create a landscape consisting of patches of 6 different colours (each representing a different vegetation in my project) according to probability. So red patches have a probability of 10% to occur on each patch, yellow 5%, brown 20% and so on.
An example of my code where this probability is set up:
let i random-float 1
ifelse i + random-float 0.1 <= 0.8 ;random 0.1 threshold for environmental noise
[ set pcolor green ]
[ ifelse i + random-float 0.1 <= 0.9
[ set pcolor yellow ]
[ set pcolor blue ] ]
However, this creates a random pattern for each colour. But I would like to create a clustered spatial pattern for one of them.Specifically, in my landscape, I want the proportion of brown patches to be 50%. But if I were to set this 50% probability for every patch, the brown patches will be randomly distributed. How do I get it to occupy 50% of my landscape, but appear in a clustered pattern?
I tried creating the clustered pattern using the Moore neighbourhood, but that obviously changes the proportion of brown patches.
I hope this is somewhat clear. Thanks for any help in advance.
You could seed based on your weights and then grow around the seeds. Here is a different approach: color all patches based on your weights, and then cluster the colors.
extensions [rnd] ;use the rnd extension
globals [threshold]
to setup
ca
set threshold 2
let _cw [[red 10] [yellow 20] [blue 70]] ;colors with weights
ask patches [set pcolor first rnd:weighted-one-of-list _cw [last ?]]
repeat 20 [cluster] ;adjust to taste
end
to cluster
ask patches [
if unhappy? [
swap-pcolor
]
]
end
to swap-pcolor
let _c pcolor
let _p one-of neighbors with [pcolor != [pcolor] of myself]
set pcolor [pcolor] of _p
ask _p [set pcolor _c]
end
to-report unhappy?
let _ct count neighbors with [pcolor = [pcolor] of myself]
report (_ct < threshold)
end

set a demand and supply curve for the model tragedy of the commons in the case of an overfished pond

I am new at net logo and I want to write a model based on tragedy of the commons in the case of an overfished pond. The purpose is to find an equilibrium between fishers and fishes based on an economic model with demand and supply. If there are less fishers, more fishes will be in the pond, then after a certain time (ticks) the number of fishers increases and less fishes will be in the pond. Maybe set like a number of fishes per day that can be fished. Thus, the solution is to find a convenient number of fishers as the fishes can still reproduce. I want to have a box in the interface where I can type in a number and see what happens with the number of fishes.
I have no idea how to set this up. I hope to hear from you :)
I started with this code:
breed [fishers fisher]
breed [fishes fish]
to setup
clear-all
reset-ticks
ask patches [set pcolor blue ] ;; lake/pond in form of a rectangle in color
ask patches [ if pxcor > 8 [ set pcolor green ]]
ask patches [ if pycor > 8 [ set pcolor green ]]
ask patches [ if pycor < -8 [ set pcolor green ]]
ask patches [ if pxcor < -8 [ set pcolor green ]]
ask one-of patches with [ pcolor = blue ] [ sprout 20 [set shape "fish" set color pink set size 1.5 ]] ;; creates fishes
ask one-of patches with [ pcolor = green ] [ sprout 2 [set shape "person" set color black set size 3 ] ] ;; creates fishers
end
to go
tick
;;fishes
ask turtles with [ shape = "fish" and color = pink ]
[ right random 360 forward 1
if [pcolor] of patch-ahead 1 = green [ right 180 fd 1 ]]
;; fishers
ask turtles with [ shape = "person" and color = black]
[;right random 360 forward 1
if any? patches with [pcolor = blue]
[set heading towards one-of patches with [pcolor = blue] forward 1]
if [pcolor] of patch-ahead 1 = blue [ right 180 fd 2 ]]
ask turtles with [shape = "person" and color = black]
[if any? turtles with [shape = "fish" and color = pink] in-radius 2
[ask turtles with [shape = "fish" and color = pink] in-radius 2 [die]]]
end
Firstly, I suggest you look through existing models in the Netlogo library (Wolf-sheep-predation model may help). You roughly have the right idea in your current code, but you should look at other models to improve. You've already set your different breeds of turtles, but you should also set up their respective shapes under 'setup'. This would help you a great deal later - instead of calling for
ask turtles with [ shape = "fish"...]
you can simply
ask fishes [do sth...]
For that 'box at the interface', you can have a slider at the interface determining the number of fishers you want your run to start with. With another slider, you can set the fishing pressure in your simulated run (i.e. how many fish each fisher will catch) and I suppose you can also consider how this changes when population of fish decreases.
Finally, for a model like yours, you can observe the supply and demand trend by plotting the curves of no. of fishers over time and no. of fishes over time. Again, look at the wolf-sheep-predation model to have an idea of how to do this.
I can't give you more than this I'm afraid since I'm no pro myself but hope this helps a little. Hope someone else would be able to give you a clearer idea.

On netlogo, what command do I use to make a turtle stop if the patch it wants to move to is a certain color

I'm making a maze on netlogo and I want to do it so that once it tries to walk into the violet lines, it'll stay on its own patch instead of moving forward. What command would that be? I tried bk 1 to reverse the fd 1 but it doesn't work all the time
You can undo your step like this:
ask turtles [
fd 1
if pcolor = violet [fd -1]
]
Or you can check ahead of time as Marzy answered. Basically it's the difference of asking for forgiveness vs permission :-)
I hope this example answer your questions:
turtles-own [target]
to setup
clear-all
reset-ticks
ask n-of 100 patches [
set pcolor red
]
create-turtles 1
[ move-to one-of patches with [pcolor != red]
set heading 90
set target one-of patches with [pcolor != red]
ask target
[
set pcolor green
]
]
end
to go
ask turtles
[ifelse pcolor != green
[
ifelse [pcolor] of patch-ahead 1 != red
[
Your-Move-Function
]
[
Your-Bounce-Function
]
leave-a-trail
]
[stop
print ticks
]
]
tick
end
to Your-Move-Function
let t target
face min-one-of all-possible-moves [distance t]
fd 1
end
to Your-Bounce-Function
let t target
face min-one-of all-possible-moves [distance t]
end
to-report all-possible-moves
report patches in-radius 1 with [pcolor != red and distance myself <= 1 and distance myself > 0 and plabel = "" ]
end
to leave-a-trail
ask patch-here [set plabel ticks]
end
This is how it works:
Random patches are colored Red to show walls or obstacles, one turtle is created in a random location with a random target which is colored green:
I have used a variable to store all available patches which turtle can step on , but since I have considered a target for the turtle, turtle chooses the one patch which is closest to the target, and since I have noticed in some cases it might go in circle I have asked the turtle to leave tick number which is its move number as a plabel, you can use a variable for that for specifying if that path was already selected or not.