public double ClusteringCoefficient(RandomModelBase network) { List <UndirectedEdge <int> > neighbors; double sum = 0; int count = 0; foreach (var v in network.Graph.Vertices) { neighbors = network.Graph.AdjacentEdges(v).ToList(); for (int i = 0; i < neighbors.Count; i++) { var s = neighbors.ElementAt(i); for (int j = i + 1; j < neighbors.Count; j++) { var edgesNeighbor = network.Graph.AdjacentEdges(s.Target).ToList(); if (edgesNeighbor.Count(e => e.Target == neighbors.ElementAt(j).Target) > 0) { count++; } } } if (count != 0) { sum += count * 2.0 / (neighbors.Count * (neighbors.Count - 1)); } count = 0; } return(sum / network.Graph.VertexCount); }
public Dictionary <int, int> Analyze(RandomModelBase graph) { var distribuitionDegree = new Dictionary <int, int>(); int max_degree = 0; foreach (var vertice in graph.Graph.Vertices) { int degree = graph.Graph.AdjacentDegree(vertice); Console.WriteLine(degree); max_degree += degree; if (distribuitionDegree.ContainsKey(degree)) { distribuitionDegree[degree] += 1; } else { distribuitionDegree.Add(degree, 1); } } return(distribuitionDegree); }
public double Analyze(RandomModelBase pNetwork) { double averageShortestPath = 0; int N = pNetwork.Graph.VertexCount; int invalidPaths = 0; for (int i = 0; i < N; i++) { int[] distance = new int[N]; bool[] used = new bool[N]; for (int j = 0; j < N; j++) { distance[j] = Int32.MaxValue; } var edgeIterator = pNetwork.Graph.AdjacentEdges(i).ToList(); foreach (var edge in edgeIterator) { int neighborIndex = edge.Source; if (neighborIndex == i) { neighborIndex = edge.Target; } distance[neighborIndex] = 1; } for (int allowed = 1; allowed < N; allowed++) { //Find the closest node int min = Int32.MaxValue; int index = 0; for (int j = 0; j < N; j++) { if ((min > distance[j]) && (!used[j])) { min = distance[j]; index = j; } } //Mark the closest node as used used[index] = true; var adjIterator = pNetwork.Graph.AdjacentEdges(i).ToList(); foreach (var adj in adjIterator) { int k = adj.Source; if (k == index) { k = adj.Target; } if (!used[k]) { int sum = distance[index] + 1; if (sum < distance[k]) { distance[k] = sum; } } } } for (int j = 0; j < N; j++) { if (i != j) { if ((distance[j] < Int32.MaxValue) && (distance[j] > 0)) { averageShortestPath += distance[j]; } else { invalidPaths++; } } } } return(averageShortestPath / ((double)(N * (N - 1.0d) - invalidPaths))); }