Exemplo n.º 1
0
  public static String PrintStats(Graph g) {
    int totalSeedNodes = 0;
    int totalTestNodes = 0;
    int totalSeedAndTestNodes = 0;
    int totalEdges = 0;
    int totalVertices = 0;
    int maxDegree = Integer.MIN_VALUE;
    int minDegree = Integer.MAX_VALUE;

    for (String vName : g.vertices().keySet()) {
      Vertex v = g.vertices().get(vName);
      ++totalVertices;

      int degree = v.GetNeighborNames().length;
      if (degree > maxDegree) {
        maxDegree = degree;
      }
      if (degree < minDegree) {
        minDegree = degree;
      }

      totalEdges += v.neighbors().size();

      if (v.isSeedNode()) {
        ++totalSeedNodes;
      }
      if (v.isTestNode()) {
        ++totalTestNodes;
      }
      if (v.isSeedNode() && v.isTestNode()) {
        ++totalSeedAndTestNodes;
      }
    }

    String retStr = "Total seed vertices: " + totalSeedNodes + "\n";
    retStr += "Total test vertices: " + totalTestNodes + "\n";
    retStr += "Total seed vertices which are also test vertices: " + totalSeedAndTestNodes + "\n";
    retStr += "Total vertices: " + totalVertices + "\n";
    retStr += "Total edges: " + totalEdges + "\n";
    retStr += "Average degree: " + (1.0 * totalEdges) / totalVertices + "\n";
    retStr += "Min degree: " + minDegree + "\n";
    retStr += "Max degree: " + maxDegree + "\n";

    return (retStr);
  }
Exemplo n.º 2
0
  private static String GetDiameter(DefaultDirectedWeightedGraph<Vertex, DefaultWeightedEdge> g) {
    String retDiaReport = "";

    //		HashMap<Vertex,KShortestPaths<Vertex,DefaultWeightedEdge>> kShortestPathMap =
    //			new HashMap<Vertex,KShortestPaths<Vertex,DefaultWeightedEdge>>();

    boolean isConnected = true;
    int diameter = -1;

    int totalProcessed = 0;

    Iterator<Vertex> vIter = g.vertexSet().iterator();
    while (vIter.hasNext()) {
      Vertex v = vIter.next();
      if (!v.isSeedNode()) {
        continue;
      }

      ++totalProcessed;
      if (totalProcessed % 1000 == 0) {
        logger.info("Processed: " + totalProcessed + " curr_dia: " + diameter);
      }

      KShortestPaths<Vertex, DefaultWeightedEdge> ksp = new KShortestPaths(g, v, 1);
      // kShortestPathMap.put(v, new KShortestPaths(g, v, _kPrime));

      Iterator<Vertex> vIter2 = g.vertexSet().iterator();
      while (vIter2.hasNext()) {
        Vertex nv = vIter2.next();

        // skip self comparison
        if (v.equals(nv)) {
          continue;
        }

        List<GraphPath<Vertex, DefaultWeightedEdge>> paths = ksp.getPaths(nv);

        if (paths == null) {
          isConnected = false;
        } else if (paths.get(0).getEdgeList().size() > diameter) {
          diameter = paths.get(0).getEdgeList().size();
        }
      }
    }

    retDiaReport += "Connected(from_seed_nodes): " + (isConnected ? "true" : "false") + "\n";
    retDiaReport += "Diameter(from_seed_nodes): " + diameter + "\n";

    return (retDiaReport);
  }