/****************************************************************************/ /* Author: Mathias Golombek */ /* Title: Analyzing Tool for generated Graphs */ /* Date: 4/30/2002 */ /****************************************************************************/ package Main; import Model.*; import Graph.*; import Export.*; import Topology.*; import Util.*; import Import.*; import java.io.*; import java.util.*; /* * This class analyses an !!!undirected!!! graph in Brite's internal graph representation. * It provides computing : * -degree distribution (-> computeDegreeDistribution() creates .degrees ) * -cluster coefficient (-> computeClusterCoefficient() creates .cluster ) * -hop distribution (-> computeHopDistributionAndCharacteristicPathLength() creates .hops ) * -characteristic path length (-> computeHopDistributionAndCharacteristicPathLength() creates .charPath ) */ final public class Analyzer { private Graph graph; //the analyzed graph private String name; //the name of the outputfiles /** * @param g The graph that shall be analyzed * @param name This String representates the beginning of all files produced with this analyzer */ public Analyzer(Graph g, String name){ graph = g; this.name = name; System.out.println("Analyzing the generated Network"); } /** This method computes the degree distribution and writes this distribution into a file .degree */ public void computeDegreeDistribution(){ System.out.println("Computing the degree-distribution"); Node[] nodes = graph.getNodesArray(); int distribution[] = new int[nodes.length]; int degree = 0; //temporary Variable for (int i=0; i 0){ //System.out.println(i+":"+distribution[i]); outFile.write(i+":"+distribution[i]+"\n"); } } outFile.close(); } catch (Exception e){ System.out.println("Analyzer.computeDegreeDistribution: Error while writing!"); } } /* This method computes the cluster coefficient which means the average of the connectivity between the direct neighbors of all nodes * Attention: this method appends the cluster coefficient value to the file .cluster for statistical analyzing of more graphs */ public void computeClusterCoefficient(){ System.out.println("Computing the cluster coefficient"); Calendar startTime = new GregorianCalendar(); // for measuring the computing time of the method Node[] nodes = graph.getNodesArray(); // saves all nodes of the Graph final int NUMBER_OF_NODES = nodes.length; // the number of nodes in the Graph. It is saved to a constant because it is often used Hashtable allNeighbors = new Hashtable(); // this hashmap saves the neighbors for each node double counter = 0; // 1: save the neighbors of all nodes to save time later for (int i=0; i.charPath for statistical analyzing of more graphs * This method needs unfortunately much time because the problem finding all shortest paths between all pairs needs O(n^3) steps !!!! */ public void computeHopDistributionAndCharacteristicPathLength(){ System.out.println("Computing the hop distribution and the characteristic path length"); Calendar startTime = new GregorianCalendar(); // for measuring the computing time of the method Node[] nodes = graph.getNodesArray(); // saves all nodes of the Graph final int NUMBER_OF_NODES = nodes.length; // the number of nodes in the Graph. It is saved to a constant because it is often used int[] seenHosts = new int [NUMBER_OF_NODES]; // saves the number of seen hosts of all nodes int[] countsSeenHosts2 = new int[NUMBER_OF_NODES]; // saves the cumulative number of seen Hosts within k hops(sum of all nodes) Hashtable allNeighbors = new Hashtable(); // this hashmap saves the neighbors for each node boolean[] newHosts = new boolean[NUMBER_OF_NODES]; // this matrix saves for each node and each step which nodes are "new" seen (this matrix is initialized newly in each step) boolean[] copyOfRowI= new boolean[NUMBER_OF_NODES]; // this matrix saves one row out of the adjacence-matrix so no modification are made on the adj-matrix boolean[] visited = new boolean[NUMBER_OF_NODES]; // this matrix saves the already visited nodes for each node (this matrix is initialized newly for each node) // 1: search all neighbors and take them into one big adjacence-list for (int i=0; i so we can go to step } System.out.print("."); //indicating the method is still running !!! One point stands for computing one node //System.out.println("Ready with node "+ (i+1) +" of "+NUMBER_OF_NODES); } System.out.println(); //----------------Hop Distribution--------------------------------- // we have to modify the countseenHosts-array because before in each step (since step 2) were only considered the new seen Hosts, // but we need the cumulative sum int[] cumulative = new int[NUMBER_OF_NODES]; cumulative[0] = NUMBER_OF_NODES; for (int i=1; i