the algorithm here is the completion of the process, their own thinking, do not know that there is no one raised. Here is a detailed algorithm for documenting the discovery process, which will be used later
Background description
Bishi do is "the prediction of virus transmission in social networks", the prophase process is to simulate several network data, and then from a node to spread, to study the prediction of the propagation process.
In one step, it is necessary to study the propagation process of a node with a distance of n from a bridge node (two connection points of two networks) as a virus source. Here's a requirement: look for nodes with a distance of n Node A.
Completion of the process is basically repeating the doctoral sister has published papers, but because the young arrogant to tutor said to do their own, only doctoral sister to provide the main line of thought. Every time you do it, give it to my PhD sister, and then tell me about him. found that a distance from Node A to n nodes, doctoral sisters are used Dijkstra algorithm first the entire Network node distance calculated, and then find the node needed.
However, the disadvantage of this is to waste unnecessary time and space, because our requirements only need to calculate the distance of a specific point a length d=n nodes, and do not need to calculate all the nodes of all distance length nodes.
Algorithm content
The idea of the algorithm is based on the most direct idea, that is, finding the node algorithm with Node a distance d=n:
- Find a neighbor node that is d=n-1 from Node A
- The first step in the node minus d=n-2,n-3, ... , the neighbor node of 1,0
JS write pseudo-code (directly using the data structure at the completion of the design)
/*
Looking for nodes in network Net, node distance distance
Net = {
' 1 ': {
' Status ': 1,//Node number 1 node status is infected.
' Connect ': [2,3,4,5]//Node number 1 of the node's neighbor node.
},
...
}
*/
functionFinddistancenodes (Net, node, distance) {
varFindnodes = [];
if(distance = = 0) {
Findnodes.push (node);
}Else{
//looking for neighbors from Distance-1 's nodes .
varLastdistancenodes = Finddistancenodes (Net, node, distance-1);
for(vari = 0; i < lastdistancenodes.length; i++) {
Findnodes = Array_merge (Net[lastdistancenodes[i]].connect, findnodes);
}
//Go heavy
Findnodes = Rmsamearr (findnodes);
//Remove node d=0,1,2,3,4 from the neighbors,... distance-1
for(vari = 0; i < distance; i++) {
Findnodes = Minarrfromarr (Findnodes, Finddistancenodes (Net, node, i));
}
}
returnFindnodes;
}
End
The above algorithm is verified by the result of completion, and the results of the doctoral sister are consistent, the overall speed is faster than its. This is a rough record of the research process, and I hope to feel the bitterness and sweetness of the bi-set.
A node algorithm for finding node d=n