Create two regions with different topological relations in NetLogo - netlogo

I would like to create two regions that can have one of topological relation, for example two regions A and B: A covers B, or A contains B, or ... .
How can I create these two regions?
Any help that anybody can offer would be greatly appreciated!!

Supposing I have one region:
let region1 n-of 20 patches
Then here's how I'd make a new region that's entirely contained within region1:
let region2 n-of 10 region1
Or a new region that's disjoint from region1:
let region3 n-of 10 patches with [not member? self region1]

Related

Community detection in NetLogo

Does anyone have any code to detect communities in NetLogo by some attribute, let's say colour? By community I mean a group of turtles of the same colour surrounded by turtles of other colours. It's easy to do visually when the world doesn't wrap but viciously difficult when it does.
To be clear, there could be two distinct red communities that I would like to count as two (like islands in a sea of blue), and I've got multiple (more than two) colours.
If I set a link between a turtle and it's neighbour, if they are of the same colour, then using the Networks Extension I can do this using nw:weak-component-clusters. I just then need to count the number of items in the resulting list.
breed [people person]
to communities
ask links [die]
ask people [ask people-on neighbors [if color = [color] of myself [create-link-with myself]]]
nw:set-context people links
show length nw:weak-component-clusters
end

Moving downhill a patch variable while maintaining a global direction

I am building a dispersal model in a landscape with different landcover types: urban, forest, residential etc. Each one of these landcover types has a resistance-to-movement patch variable and they are found in clusters of patches:
urban - 4 + random-float 1.0
residential - 9 + random-float 1.0
forest - 1 + random-float 1.0.
I would like my turtles to move downhill the resistance values from one forest patch cluster to another. The issue I am having however, is that because the resistance values are not distributed in a gradient, the turtles will stay put if the resistance of its neighbours is the same or move backwards away from the forest patches if the resistance is lower in that direction.
Most models in the model library that use the downhill/uphill functions have gradient landscapes such as mountains, but mine are randomly distributed.
How can I get my turtles to move downhill while also maintaining a global direction towards the forest patches so that they do not move backwards?
Thanks!
That seems rather like a modelling problem than like a Netlogo problem to me.
How would you like the turtles to move, if they have visited all forest patches in that cluster?
Two ideas:
they move to the patch with the smallest resistance from all neighbor patches, that are closer to their destination, e.g. with min-one-of
face destination ; destination is a patch
; could be a global variable set in setup
let candidates (patch-set patch-right-and-ahead 30 1
patch-left-and-ahead 30 1
patch-ahead 1)
move-to min-one-of candidates [value] ; turtle moves to the candidate patch with the smallest "value"
or, if they have knowledge of the whole landscape, they could use a path search algorithm such as A* in order to minimize the sum of resistance on their path.

Does netlogo dbscan extension work for patches?

Does the netlogo dbscan (kmeans) clustering (by location) extension work for patches as well as turtles? Or does it work for only turtles?
Documentation is pretty clear that it's for turtles. Can you explain a bit more what you are trying to do? Clustering algorithms identify areas of more or less density. So spatial clustering is meaningless for patches. However, clustering-by-variable is meaningful, but not available.
If you want to cluster by some patch variable, why not simply create a turtle for every patch that has whatever patch variable you want to cluster by, and then cluster those turtles and transfer the cluster information back to their patches? This code demonstrates the approach but doesnt do anything with the clustering information.
extensions [dbscan]
patches-own [wealth]
turtles-own [wealth-here]
to testme
clear-all
ask patches [set wealth one-of [50 200 500]]
; let clusters dbscan:cluster-by-variable patches "wealth" 3 20 ; this generates error
ask patches [sprout 1 [set wealth-here wealth set size 0]]
let clusters dbscan:cluster-by-variable turtles "wealth-here" 3 20 ; this works
show clusters
end

Netlogo: How to plot degree of nodes vs. average "reward" of turtles with that degree?

I am building a model that tries to simulate a network-based market. In this model the turtles/nodes get a reward called points, which is a turtles-own variable.
I am now trying to plot a graph of the degree of the nodes against the average number of points that nodes with a given degree have. I have attempted to do this by creating a plot from the interface tab but I cannot manage to make this work.
Here are images of the windows of the plot settings.
Anybody know how can I make this work?
Also, I keep getting these "Runtime error: Can't find the maximum of an empty list" in all the plots/histograms I create. It is not a big deal at the moment as they seem to work fine, however if you know why these appear please let me know!
Thanks beforehand,
Carlos
For simplicity and to avoid overloading your plot setup, I like to use to-report procedures for things like this. As a quick example try this setup:
turtles-own [ points degree ]
to setup
ca
crt 50 [
set degree 5 + random 5
set points random 10
setxy random-xcor random-ycor
]
reset-ticks
end
Make a to-report each for a list of existing degrees, the average points of turtles that have each degree, and the maximum of those average point values:
to-report degrees-list
report sort remove-duplicates [degree] of turtles
end
to-report avg-points-list
let avg-list map [ i ->
mean [points] of turtles with [ degree = i ]
] degrees-list
report avg-list
end
to-report max-avg
report precision ( max avg-points-list + 1 ) 2
end
In this example, degrees-list reports [ 1 2 3 4 5 ], avg-points-list reports something like [6.5 3.9285714285714284 6 3.75 4.2], and max-avg reports something like 7.5- note that of course the exact values will vary since the setup is random.
Now, you can set up your plot window:
The actual plotting is handled by the foreach primitive in the plot pen, which uses plotxy to plot the point value in avg-points-list against the corresponding value in degrees-list. Should give a plot that looks something like:
Hope that's sort of what you're after!

Netlogo how to count turtles in same region

I divided the netlogo gird into 4 sections and give region unique id. Turtles are placed randomly. Now i want to check whether two turtles are present in same section. If they do then separate them. I am stuck in how to write if condition that checks whether two turtles are in same region or not. Any help would be really appreciated. Thanks in advance
Turtles have direct access to the attributes of their patches.
;demo
patches-own [section]
to setup
ca
ask patches [set section one-of [0 1 2 3]]
crt 200 [setxy random-xcor random-ycor]
end
to-report test [#t1 #t2]
report ([section] of #t1 = [section] of #t2)
end