* @return string averagePathLength, the result
*/
public static String computeAveragePathLength(DNVGraph graph)
{
ArrayList<DNVNode> nodeList = new ArrayList<DNVNode>(graph.getVisibleNodes(0).values());
DNVNode nodeBeingVisited = new DNVNode();
double averagePathLength = 0.0;
int nodeBeingVisitedWeight = 0;
int temp = 0;
Double degree = 0.0;
ArrayList<DNVNode> tmp = new ArrayList<DNVNode>();
ArrayList<NextNode> nextNode = new ArrayList<NextNode>();
Hashtable<DNVNode, Integer> visitedNode = new Hashtable<DNVNode, Integer>();
Enumeration e;
String result = "";
Double counter = 0.0;
Double sum = 0.0;
int values = 0;
int size = 0;
//For all nodes from the node list
for(int n=0;n<nodeList.size();n++)
{
visitedNode = new Hashtable<DNVNode, Integer>();
nextNode = new ArrayList<NextNode>();
//get the current node being visited
nodeBeingVisited = nodeList.get(n);
nodeBeingVisitedWeight = 0;
//get all of the current node neighbors
tmp = (ArrayList<DNVNode>) nodeBeingVisited.getNeighbors(true);
temp = nodeBeingVisitedWeight+1;
for(int i=0;i<tmp.size();i++)
{
nextNode.add(new NextNode(tmp.get(i),temp));
}
//Add the current node to the visited node list
visitedNode.put(nodeBeingVisited,nodeBeingVisitedWeight);
//While the next node list is not empty
while(nextNode.isEmpty() == false)
{
//Get the current node being visited
nodeBeingVisited = nextNode.get(0).getNode();
//if the node hasn't been visited yet
if(visitedNode.containsKey(nodeBeingVisited) == false)
{
nodeBeingVisitedWeight = nextNode.get(0).getWeight();
//get its neighbors & add them at the end of the next node list
tmp = (ArrayList<DNVNode>) nodeBeingVisited.getNeighbors(true);
temp = nodeBeingVisitedWeight + 1;
for(int x=0;x<tmp.size();x++)
{
nextNode.add(new NextNode(tmp.get(x),temp));
}
//add the current node into the visited node list
visitedNode.put(nodeBeingVisited,nodeBeingVisitedWeight);
}
//remove the node from the next node list
nextNode.remove(0);
}
values = 0;
e = visitedNode.keys();
//get all the weights ans add them up together
while (e.hasMoreElements()){
Object str = e.nextElement();
values += visitedNode.get(str);
}
size = visitedNode.size();
//get the APL for the current node
sum += Double.parseDouble(Integer.toString(values))/Double.parseDouble(Integer.toString(size));
counter++;
degree += nodeBeingVisited.getDegree();
}