import org.graphstream.algorithm.Toolkit;
import org.graphstream.algorithm.generator.Generator;
import org.graphstream.algorithm.generator.RandomGenerator;
import org.graphstream.graph.Graph;
import org.graphstream.graph.implementations.DefaultGraph;
import org.graphstream.graph.implementations.SingleGraph;
import org.graphstream.stream.file.FileSourceEdge;

import java.io.IOException;
import java.util.Locale;

import static org.graphstream.algorithm.Toolkit.averageClusteringCoefficient;
import static org.graphstream.algorithm.Toolkit.isConnected;

public class TestReseauScientifique {

    public static void main(String ... args) throws IOException {
        String filePath = "src/data.txt";
        Graph g = new DefaultGraph("g");
        FileSourceEdge fs = new FileSourceEdge(true);

        fs.addSink(g);

        try {
            fs.begin(filePath);

            while (fs.nextEvents()) {
                // Optionally some code here ...
            }
        } catch( IOException e) {
            e.printStackTrace();
        }

        try {
            fs.end();
        } catch( IOException e) {
            e.printStackTrace();
        } finally {
            fs.removeSink(g);
        }
        System.out.println(g.getNodeCount());
        System.out.println(g.getEdgeCount());
        double k = (g.getEdgeCount()*2/(double)g.getNodeCount());
        System.out.println(k);
        double kCarre = (Math.pow(g.getEdgeCount()*2,2)/(double)g.getNodeCount());
        System.out.println(kCarre);
        System.out.println("k/<k²> = " + k/kCarre);
        System.out.println(averageClusteringCoefficient(g));
        System.out.println(isConnected(g));

        int[] dd = Toolkit.degreeDistribution(g);
        for (int i = 0; i < dd.length; i++) {
            if (dd[i] != 0) {
                System.out.printf(Locale.US, "%6d%20.8f%n", i, (double)dd[i] / g.getNodeCount());
            }
        }


       /* SingleGraph g2 = new SingleGraph("Random");
        Generator gen = new RandomGenerator(10);
        gen.addSink(g2);
        gen.begin();
        for(int i=0; i<195; i++)
            gen.nextEvents();
        gen.end();
        System.out.println(g2.getNodeCount());
        System.out.println(g2.getEdgeCount());
        System.out.println(g2.getEdgeCount()/(double)g2.getNodeCount());
        System.out.println(averageClusteringCoefficient(g2));
        System.out.println(g2.getEdgeCount()/(double)g2.getNodeCount()/g2.getNodeCount());
        System.out.println(isConnected(g2)); */
    }
}
