|
@@ -142,26 +142,26 @@ public class GraphMetrics {
|
|
|
// Example Test
|
|
|
public static void main(String[] args){
|
|
|
Graph G = new Graph();
|
|
|
- G.V = new Vertex[5];
|
|
|
+ G.V = new Vertex[4];
|
|
|
for(int i=0;i<G.V.length;i++)
|
|
|
{
|
|
|
G.V[i] = new Vertex(i);
|
|
|
}
|
|
|
- G.E = new Edge[5];
|
|
|
+ G.E = new Edge[4];
|
|
|
|
|
|
G.E[0] = new Edge(0, 1, 1);
|
|
|
G.E[1] = new Edge(1, 2, 1);
|
|
|
G.E[2] = new Edge(2, 3, 1);
|
|
|
G.E[3] = new Edge(3, 0, 1);
|
|
|
- G.E[4] = new Edge(0, 4, 1);
|
|
|
|
|
|
- G.S = new Vertex[3];
|
|
|
+ G.S = new Vertex[4];
|
|
|
G.S[0] = new Vertex(0);
|
|
|
G.S[1] = new Vertex(1);
|
|
|
- G.S[2] = new Vertex(4);
|
|
|
+ G.S[2] = new Vertex(2);
|
|
|
+ G.S[3] = new Vertex(3);
|
|
|
|
|
|
System.out.println("minimumCut: " + minimumCut(G.V, G.E));
|
|
|
- System.out.println("AvgShortestDistance " + averageShortestDistance(G.V, G.E));
|
|
|
+ System.out.println("AvgShortestDistance " + averageShortestDistance(G));
|
|
|
System.out.println("DisjointPath " + averageEdgeDisjointPathProblem(G));
|
|
|
}
|
|
|
|
|
@@ -366,19 +366,17 @@ public class GraphMetrics {
|
|
|
}
|
|
|
return D;
|
|
|
}
|
|
|
- static double averageShortestDistance(Vertex[] V, Edge[] E) {
|
|
|
- if(V.length <= 1) return 0.0;
|
|
|
- double[][] D = basicAllPairsShortestPath(V, E);
|
|
|
- double sum = 0;
|
|
|
- int maxColumn = 1;
|
|
|
- for(int row = 1; row < D.length; row++) {
|
|
|
- for(int column = 0; column < maxColumn; column++) {
|
|
|
- sum += D[row][column];
|
|
|
+ static double averageShortestDistance(Graph G) {
|
|
|
+ if(G.V.length <= 1) return 0.0;
|
|
|
+ double[][] D = basicAllPairsShortestPath(G.V, G.E);
|
|
|
+ double sum = 0.0;
|
|
|
+ for(int s = 0; s < G.S.length; s++) {
|
|
|
+ for(int t = s; t < G.S.length; t++) {
|
|
|
+ sum += D[G.S[s].id][G.S[t].id];
|
|
|
}
|
|
|
- maxColumn++;
|
|
|
}
|
|
|
- int numbers = ((D.length - 1) * (D.length)) / 2;
|
|
|
- return sum / (double)numbers;
|
|
|
+ //Returns the Average
|
|
|
+ return sum / ((G.S.length * (G.S.length - 1)) / 2);
|
|
|
}
|
|
|
/**
|
|
|
* @return Updated Distance Matrix D and flag List
|