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.*;
import java.util.Locale;

public class MesuresRI {

    private static final String FILE_PATH = "data/com-dblp.ungraph.txt";
    private static final String OUTPUT_DATA = "data/dd_dblp.dat";

    public static void main(String ... args) throws IOException {
        Graph graph = new DefaultGraph("g");
        FileSourceEdge fs = new FileSourceEdge();
        BufferedWriter writer = new BufferedWriter(new FileWriter(OUTPUT_DATA));

        try {
            fs.addSink(graph);
            fs.readAll(FILE_PATH);

            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) {
                    writer.write(String.format(Locale.US, "%6d%20.8f%n", k, (double)dd[k] / graph.getNodeCount()));
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            fs.end();
        } finally {
            writer.close();
            fs.removeSink(graph);
        }
    }
}


