creating complex network in netlogo - netlogo

I'm trying to create a complex network, the no. of nodes is controlled by slider.
i want to create some nodes as target and some as sources. and want to connect them through edges.
breed [nodes node]
undirected-link-breed [edges edge]
to setup
;;
end
to add-nodes
create-nodes num-nodes [
setxy random-xcor random-ycor
]
end
how do I draw edges and to create some target and source nodes?

Related

Why is mean [nw:clustering-coefficient] of turtles showing zero?

I have the following network set up:
extensions [nw]
breed [agents agent]
agents-own [status
]
to setup
clear-all
ask patches [
set pcolor white
]
nw:generate-preferential-attachment agents links 100 1 [ set shape "person"
setxy random-xcor random-ycor
set status random 2
ifelse status = 0 [set status -1][set status 1]
ifelse status = 1 [set color green] [set color red] ]
display
output-print nw:mean-path-length
output-print mean [ nw:clustering-coefficient ] of agents
output-print mean [nw:betweenness-centrality ] of agents
output-print mean [ count my-links ] of agents
output-print count links
reset-ticks
end
The mean of the clustering-coefficient always shows zero (other reports show figures that make sense). If I try to show the c-c of an individual turtle I also get zero. Do I need to use a link breed rather than just 'link' in establishing the network? I tried running this with an undirected-link breed and it made no difference.
Am I missing something? The c-c should be >0 right?
Kevin
I am not too well versed with networks so I might be wrong here.
The clustering coefficient is a measure for how many of your link-neighbors are also link-neighbors of one another. The way you make your network however (preferential attachment with a single link) simply does not generate a network where your neighbors are ever neighbor to one another, hence the clustering coefficient of every turtle is 0. For example nw:generate-preferential-attachment agents links 100 2 does generate a few instances where you get three turtles all connected to one another so here you will have a higher clustering coefficient

Star shaped network with directed links from center

I want to generate star topology of a network with directed links from the central node to the other nodes. I have created star network with links to the central node from the external nodes, but I am not able to direct the links from the centre to other nodes.
directed-link-breed [Ls L]
to star
ca
nw:generate-star turtles Ls 100 ; using link breed
[
set color red
fd random 15
set shape "circle"
ask links [set color yellow]
]
nw:generate-star turtles Ls-to 100 ; it does not work
end
Unfortunately, there's no way to control the direction that nw:generate-star will generate the links in. However, it's quite easy to generate the star yourself:
to star
ca
create-turtles 100 [
set color red
fd random 15
set shape "circle"
]
ask turtle 0 [
setxy 0 0
create-Ls-to other turtles [ set color yellow ]
]
end

setting up turtles with preset distance between them (netlogo)

I am a high school student and I have to make a model about plants and plagues. I want to setup turtles with a preset distance from each other, but I can't figure out how to do that without creating an infinite loop. This is what my code looks like. Now it creates 20 turtles with random distance between them, but I want them to have a preset distance and as much turtles there can be on the screen with that distance between them.
to setup
clear-all
ask patches [ set pcolor 33 ]
make
repeat 20 [maken]
reset-ticks
end
to make
create-aardappelplanten 1[
setxy random-xcor random-ycor
set color green
set size 1.5
set shape "plant"
set age 1
]
end
Thank you so much!!

Determining the radius of turtle clusters and number of turtles in them - postprocessing

If I have a situation in which about a 1000 black turtles disperse at random angles and steps throughout the netlogo world for a given duration of ticks. Each turtle is assigned a random probability at each timestep during dispersal, and if this number exceeds a given threshold for any given turtle it changes it's color to red and stops moving. Additionally, black turtles (still moving) that happen to move within a patch of red turtles (stopped/settled), change their color to grey and settle (stop moving) as well. Finally, other black turtles (still moving) that happen to be move within a patch of either grey or red turtles (stopped/settled), also change their color to grey and settle (stop moving)
My question is a post-processing question for when the simulation duration is reached. How do I determine the number of clusters of red-grey turtles in the sea of black turtles? Also, how do I determine the size (radial extent) of each cluster? And finally, how do I determine the number of turtles in each cluster?
Jen is right: you need a clear idea of what constitutes a cluster before being able to truly answer that question.
That being said, one possible option is to use a clustering algorithm. I'd suggest taking a look at Christopher Frantz's dbscan extension.
Here is a quickly thrown together example:
extensions [ dbscan ]
to setup
clear-all
ask patches [ set pcolor white ]
create-turtles 1000 [
set color black
set label-color blue
setxy random-xcor random-ycor
]
ask n-of 5 turtles [
ask turtles in-radius 3 [
set color one-of [red grey]
]
]
end
to find-clusters
let red-grey-turtles turtles with [ member? color [red grey] ]
let clusters dbscan:cluster-by-location red-grey-turtles 3 3
(foreach clusters range length clusters [ [c i] ->
foreach c [ t ->
ask t [ set label i ]
]
])
end
Sorry for the lack of further explanations: I have a plane to catch...

random walk in netlogo- stoping condition issue

I have created a small network consist of nodes which are connected through links.
Some of the nodes are sources and some of the targets. I try to implement Random Walk algorithm.
I place walkers on source nodes, and walkers are moving randomly through the network. Now, I want to check walker reached to targets nodes, if all target nodes are visited by walker then ask walker to stop or die.
I'm new to NetLogo and don't know how to implement this logic.
Any help or guide will be appreciated.
One way to do this is to have your nodes know if they are a target, and if they have been visited. That way, if a turtle visits a node, that node can be marked as having been visited. Then, you can have a stop procedure at the end of your go procedure that checks if any nodes are still present that are a target but have not been visited. I have made slight modifications to the Link-Walking Turtles Example to show one way that you could do this- almost all the code below is directly pulled from that model.
breed [nodes node]
breed [walkers walker]
walkers-own [location]
nodes-own [ target? visited? ]
to setup
clear-all
set-default-shape nodes "circle"
create-nodes 30 [
set color blue
set target? false
set visited? false
]
ask nodes [ create-link-with one-of other nodes ]
repeat 500 [ layout ]
ask nodes [
setxy 0.95 * xcor 0.95 * ycor
]
ask n-of 5 nodes [
set target? true
set color white
]
create-walkers 1 [
set color red
set location one-of nodes
move-to location
]
reset-ticks
end
to layout
layout-spring nodes links 0.5 2 1
end
to go
ask links [ set thickness 0 ]
ask walkers [
let new-location one-of [link-neighbors] of location
move-to new-location
set location new-location
;; This gets turtles to ask their current location
;; to set visited and target to true.
ask location [
set visited? true
if target? = true [
set color red
]
]
]
;; Check for target nodes that have NOT been visited.
;; If there aren't any, stop the model.
if not any? nodes with [ target? = true and visited? = false ] [
print ("All target nodes have been visited.")
stop
]
tick
end