package unlh.ri;

import org.graphstream.algorithm.Toolkit;
import org.graphstream.graph.Graph;
import org.graphstream.graph.implementations.DefaultGraph;
import org.graphstream.stream.file.FileSourceEdge;
import java.io.IOException;
import java.util.Locale;

public class MesuresRI {
    public static void main(String ... args) throws IOException {
        String filePath = "data/com-dblp.ungraph.txt";
        Graph graph = new DefaultGraph("g");
        FileSourceEdge fs = new FileSourceEdge();
        try {
            fs.addSink(graph);
            fs.readAll(filePath);

            System.out.println("N :" + graph.getNodeCount() );
            System.out.println("L :" + graph.getEdgeCount() );
            System.out.println("<k> :" + Toolkit.averageDegree(graph) );
            System.out.println("<C>:" + Toolkit.averageClusteringCoefficient(graph));
            System.out.println("Connexe : "+ Toolkit.isConnected(graph));
            // graph.display();
            System.out.println("" );
            int[] dd = Toolkit.degreeDistribution(graph);
            for (int k = 0; k < dd.length; k++) {
                if (dd[k] != 0) {
                    System.out.printf(Locale.US, "%6d%20.8f%n", k, (double)dd[k] / graph.getNodeCount());
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
            fs.end();
        } finally {
            fs.removeSink(graph);
        }
    }
}


