예제 #1
0
 private double avgIsolatedSize(Partition p) {
   double sum = 0;
   for (int i = 1; i < p.getComponents().length; i++) {
     sum += p.getComponents()[i].length;
   }
   return sum / p.getComponents().length;
 }
예제 #2
0
  @Override
  public void computeData(Graph g, Network n, HashMap<String, Metric> m) {
    this.runtime = new Timer();
    int[] excludeFirst = this.getExcludeFirst(g.getNodes().length);
    this.isolatedComponentSizeAvg = new double[excludeFirst.length];
    this.isolatedComponentSizeMax = new double[excludeFirst.length];
    this.isolatedComponentSizeMed = new double[excludeFirst.length];
    this.isolatedComponentSizeMin = new double[excludeFirst.length];
    this.numberOfIsolatedComponents = new double[excludeFirst.length];
    this.largestComponentSize = new double[excludeFirst.length];
    this.largestComponentSizeFraction = new double[excludeFirst.length];
    this.criticalPoint = 1.0;
    Random rand = new Random();
    Node[] sorted = this.sorter.sort(g, rand);
    for (int i = 0; i < excludeFirst.length; i++) {
      boolean[] exclude = this.getExclude(sorted, excludeFirst[i]);
      Partition p = this.partition(g, sorted, exclude);

      this.numberOfIsolatedComponents[i] = p.getComponents().length - 1;
      this.largestComponentSize[i] = p.getLargestComponent().length;
      this.largestComponentSizeFraction[i] =
          (double) p.getLargestComponent().length / (double) g.getNodes().length;

      if (this.numberOfIsolatedComponents[i] == 0) {
        this.isolatedComponentSizeAvg[i] = 0;
        this.isolatedComponentSizeMax[i] = 0;
        this.isolatedComponentSizeMed[i] = 0;
        this.isolatedComponentSizeMin[i] = 0;
      } else {
        this.isolatedComponentSizeAvg[i] = this.avgIsolatedSize(p);
        this.isolatedComponentSizeMax[i] = p.getComponents()[p.getComponents().length - 2].length;
        this.isolatedComponentSizeMed[i] =
            p.getComponents()[(int) Math.floor(p.getComponents().length / 2)].length;
        this.isolatedComponentSizeMin[i] = p.getComponents()[p.getComponents().length - 1].length;
      }

      if (this.largestComponentSize[i] < 0.5 * (g.getNodes().length - excludeFirst[i])
          && (double) excludeFirst[i] / (double) g.getNodes().length < this.criticalPoint) {
        this.criticalPoint = (double) excludeFirst[i] / (double) g.getNodes().length;
      }
    }
    this.runtime.end();
  }
예제 #3
0
 @Override
 public void computeData(Graph g, Network n, HashMap<String, Metric> m) {
   Partition p = this.getPartition(g);
   this.largestComponent = p.getComponents()[0].length;
   this.largestComponentFraction = this.largestComponent / (double) g.getNodes().length;
   this.components = new double[p.getComponents().length];
   this.componentsFraction = new double[p.getComponents().length];
   for (int i = 0; i < p.getComponents().length; i++) {
     this.components[i] = p.getComponents()[i].length;
     this.componentsFraction[i] = this.components[i] / (double) g.getNodes().length;
   }
 }