package iwocs;

import org.graphstream.algorithm.Toolkit;
import org.graphstream.graph.Graph;

import iwocs.graphs.GraphUtils;
import iwocs.graphs.GraphIO;

/**
 * App which purpose is to experiment on a real life scaled interaction network
 * (scientific collaboration).
 */
public class App {
  public static void main(String[] args) {
    Graph g = GraphIO.getNerdsGraph();

    System.out.println("Nerds graph:");
    System.out.format("N: %d\nL: %d\n<k>: %.3f\n<C>: %.3f\nConnected: %b\n<d>: %.3f\n",
      g.getNodeCount(),
      g.getEdgeCount(),
      Toolkit.averageDegree(g),
      Toolkit.averageClusteringCoefficient(g),
      Toolkit.isConnected(g),
      GraphUtils.calculateMeanDistanceFromSample(g, 1000)
    );

    //export degree distribution
    GraphIO.exportDegreeDistribution(g, "data/nerds_degrees_distrib", true);

    //export distances distribution
    GraphIO.exportHashMapDistribution(
      GraphUtils.calculateDistancesDistributionFromSample(g, 1000, true),
      "data/nerds_distances_distrib"
    );

    Graph random = GraphUtils.getRandomGraph("random", g.getNodeCount(), Toolkit.averageDegree(g));

    System.out.println("\nRandom graph:");
    System.out.format("N: %d\nL: %d\n<k>: %.3f\n<C>: %.3f\nConnected: %b\n<d>: %.3f\n",
      random.getNodeCount(),
      random.getEdgeCount(),
      Toolkit.averageDegree(random),
      Toolkit.averageClusteringCoefficient(random),
      Toolkit.isConnected(random),
      GraphUtils.calculateMeanDistanceFromSample(random, 1000)
    );

    //export degree distribution
    GraphIO.exportDegreeDistribution(random, "data/random_degrees_distrib", true);

    //export distances distribution
    GraphIO.exportHashMapDistribution(
      GraphUtils.calculateDistancesDistributionFromSample(random, 1000, true),
      "data/random_distances_distrib"
    );

    Graph preferential = GraphUtils.getPreferentialGraph("preferential", g.getNodeCount(), Toolkit.averageDegree(g));

    System.out.println("\nPreferential graph:");
    System.out.format("N: %d\nL: %d\n<k>: %.3f\n<C>: %.3f\nConnected: %b\n<d>: %.3f\n",
      preferential.getNodeCount(),
      preferential.getEdgeCount(),
      Toolkit.averageDegree(preferential),
      Toolkit.averageClusteringCoefficient(preferential),
      Toolkit.isConnected(preferential),
      GraphUtils.calculateMeanDistanceFromSample(preferential, 1000)
    );

    //export degree distribution
    GraphIO.exportDegreeDistribution(preferential, "data/preferential_degrees_distrib", true);

    //export distances distribution
    GraphIO.exportHashMapDistribution(
      GraphUtils.calculateDistancesDistributionFromSample(preferential, 1000, true),
      "data/preferential_distances_distrib"
    );
  }
}