Reputation: 387
I have a landscape that includes a road network as in the below figure.
I would like to calculate an average number of roads (or white line in the figure) that link each color polygon (for example a black polygon) between them. In a network, a link corresponds to a road, a node corresponds to a color polygon and I think that to calculate an average number of roads between color polygons means to calculate the average node degree of the network. For example, in the figure, the two black polygons are linked by two roads. So, the degree of a black polygon is 2. Is it possible to calculate a node degree with the extension Network of Netlogo ?
Thanks in advance for your help.
Upvotes: 2
Views: 718
Reputation: 12580
Normal NetLogo contains link
agents that link turtles even without an extension. Calculating degree is usually just a matter of doing [ count my-links ] of node
where node
is the turtle you want to know the degree of. However, in NetLogo, turtles can't be connected by more than one link. The typical workaround for this is create a links-own
variable (just like turtles-own
or patches-own
variable) . This variable is often called weight
, but you can call it whatever you want. In that case, you would do [ sum [ weight ] of my-links ] of node
to calculate the degree.
This is all assuming you have a network representation of your roadways, which it doesn't sound like you do. Furthermore, I'm not sure what you're trying to represent is a network, since (as shown in your picture) roads branch at intersections. Thus more than two polygons could be connected by a single (for some definition of "single") road. This is often called a hypernetwork or hypergraph. However, this is probably a heavier weight concept than what you want.
Now, I'm not entirely sure what you're really trying to calculate. Is it:
The number of roads connected to a polygon would be pretty easy to calculate, assuming each road is 1 pixel wide. You could just do:
count (patch-set [ neighbors4 with [ is-road? ] ] of polygon)
where polygon
is a patch set containing the patches of the polygon and is-road?
is a reporter that returns true
for road patches and false
for non-road patches (this could be something pcolor = white
). Note that this will break if roads are wider than 1 patch or if the same road can touch a polygon in other places. Let me know if that's the case and I'll expand this into something that can that into account.
The number of polygons directly connected to the polygon is more difficult. The basic idea would be to follow the roads out until you hit other polygons and count the number that you hit. Code for this is somewhat tricky. I think the best way to go about it would be to have two patch-sets, frontier
and explored
and list of found polygons. frontier
should initialize to every road patch touch the polygon. Each iteration, get the polygons touching the frontier
and add them to the list of found polygons if they're not already in there. Add the frontier
to explored
. Get all the road patches touching the frontier
that are not in explored
. Set the frontier
to this new set of patches. Keep going until frontier
is empty. This is a version of breadth-first search. There could be a better way to do this.
Upvotes: 1