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());
        System.out.println(g.getEdgeCount()/(double)g.getNodeCount());
        System.out.println(averageClusteringCoefficient(g));
        System.out.println(isConnected(g));

        int[] dd = Toolkit.degreeDistribution(g);
        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] / 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));
    }
}
