I have a huge disconnected network. To check this I use nw:eigenvector-centrality. It reports false, if the graph is disconnected (link). Now I want to identify the disconnected nodes / areas, in order to remove them from the network.
Any ideas how I could do this?
Check out nw:weak-component-clusters
Alternatively, if you have one turtle you know is in the network (which you probably do), you can tell if any other turtle is connected by whether its reachable from that one turtle. So:
turtles with [ nw:distance-to known-turtle = false ]
will give you the agentset of turtles not reachable from known-turtle.
Related
I would like to know how I can count the degrees of separation among nodes within a network.
I have created a network with two breeds that spread virus through time.
to setup
create-people_inf 5 [set label "Infected"]
create-people_well 20 [set label "Good health"]
end
Then I added new nodes to the preexisting ones as follows:
ask people_inf
[ create-links-to other people_inf
[set color red ]
let this_turtle self
ask people_well
[
if random-float 1 < 0.5
[
create-link-to this_turtle [set color green]
]
]
]
This is just a default network. My question would be on how I can count the degrees of separation between one selected node and another one, randomly chosen. I thought of adding a flag and consider a logical condition (if connected?=true), but I do not know to consider the nodes in between. My approach would give me only information on one node and its directed connections.
Any suggestion is more than welcomed. Thanks.
You need to use the Network (nw) extension, see documentation at https://ccl.northwestern.edu/netlogo/docs/nw.html. From that, you can use the nw:distance-to for any turtle to find the number of hops to any specified turtle
I have managed to create a set of nodes and link them. However most of the time the nodes that generated do not form a continuous link with each other. By that I mean, for example if 8 nodes are generated (N1,N2,N3,N4,N5,N6,N7,N8).
Connection maybe N1-N3-N5,
and another set N2-N4-N6-N8-N7. I want both sets to have some sort of connection, i.e N5-N7. So that if I were to run a nw extenstion function, such as nw:turtles-on-path-to, I wont get an error saying it can find the path from N3 to N8.
ideally I would also like if some of the nodes are connected to more than one node, for example N2-N4, N2-N6, N2-N5.
Any ideas how to do it? Thanks in advance
breed [nodes node]
create-nodes 30[
set color blue
set size 1.5
set shape"circle"
]
ask nodes [create-link-with one-of other nodes]
repeat 500 [layout-spring nodes link 0.2 5 1]
ask nodes [setxy 0.95 * xcor * 0.95 ycor]
Your basic problem is that you don't have enough edges. You have N edges with N nodes (because each node is asked to add one edge). You need N-1 edges just to create a chain, so you only have one spare to create an extra connection.
Once you have enough edges, you can then do some sort of rewiring where you check if there's more than one component (nw:weak-component-clusters) and, if so, create an edge between a randomly selected node in one cluster to a randomly selected node in another cluster (and delete a random edge if you want to maintain the same total number of edges). Keep doing that (while) until you only have one component.
I have a network of turltes that each share two links. At the start of each turn the turtles decide to cooperate or defect, which updates a beta distribution of likelihood of cooperation in the next tick. If the turtles fail to cooperate over n turns they no longer interact. Through this I am able to create clusters in the cooperation network.
Right now, I am trying to figure out how to make the turtles move closer together proportional to the weight of their ties. Is there code to do this? I have only been able to find example code for patches.
I think this model might have something similar to what you want:
http://modelingcommons.org/browse/one_model/3632#model_tabs_browse_procedures
I am using NetLogo for a simulation in which i have to deal with many turtles each representing a robot. I need to find an algorithm for leader selection. I want to make leaders in between the crowd which will ultimately lead crowd toward the predefined target. Or is there any other way to which any turtle dynamically changes its behavior to become a leader. Any one if could help.
As we see in the model library a model named "Flocking". In which a random turtles leads all turtles. But i don't need random turtle i need the leader which should be at center or at corners of crowd.
There are two immediate possibilities: a leader breed, or an is-leader? turtle attribute. Note that a turtle's breed can be changed dynamically, just like any other attribute.
If you will have multiple leaders you may need to keep track of who follows them. Three ways to do this: a leader can maintain an agent set of followers, or each robot can have a leader attribute set to the appropriate leader (which might be nobody or self for a leader 'bot), or (as a more powerful variant of the second approach) you could create a directed links from each follower to its leader.
hth.
In my simulation each turtle has a my-home variable which is the patch agent family lives in, so agents with same Family-ID have same my-home until one of agents moves out or family grows to more than 7 agents.
when an agent wants to move out , I have to check if there is any patch nearby which is not another's agent my-home, what I have done is to store all my-homes in a list and check if any selected possible next home is not a member of this list, but I believe there should be better way to do this:
let all-homes [my-home] of agents with [belongs_to = BS]
set my-home min-one-of patches with [not member? self all-homes and label_ = BS][distance m]
m is current home address
min-one-of patches with ... assesses every patch in the entire world before picking a winner. That's going to be slow. I'd suggest searching nearby patches first, then farther patches, and so forth. Most of the time the turtle will find a new home after only a very brief search, so you'll have replaced code that's O(n) in the number of patches with code that's O(1)-ish. That should fix the main performance problem with this code.
The simplest such search routine I can think of is for the turtle to simply head in a random direction and keep moving fd 1 until it lands on a free patch. But if you want to do something more rigorous that always results in finding the closest possible new home, you could do that too; you'll just have more code to write.
Building the all-homes list is probably only a secondary performance problem here, but it's fixable too. The simplest fix I can think of is to add:
patches-own [home?]
initialize it with ask patches [ set home? false ], and then make sure that whenever a turtle adopts a patch as its home, it does ask my-home [ set home? true ]. Now you can replace member? self all-homes with simply home?. After all, you don't really need to know what all of the home patches are; you only need to know whether some particular patch is a home patch.