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.SingleGraph;
import org.graphstream.stream.file.FileSource;
import org.graphstream.stream.file.FileSourceEdge;

import java.io.IOException;

public class Mesures {

    // fonction de génération d'un reseau aleatoire
    public Graph generer_Aleatoire(int taille, double degre) {

        Graph graph = new SingleGraph("Graphe aléatoire");
        System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer");
        graph.addAttribute("ui.quality");
        graph.addAttribute("ui.antialias");
        Generator g = new RandomGenerator(degre);
        g.addSink(graph);
        g.begin();

        for (int i = 0; i < taille; i++)
            g.nextEvents();
        g.end();
        return graph;
    }


    public static void main(String[] args){
        Mesures mes = new Mesures();
        //lecture fichier
        String filePath = "src/main/resources/com-dblp.ungraph.txt";
        Graph graph = new SingleGraph("g");
        graph.addAttribute("ui.quality");
        graph.addAttribute("ui.antialias");
        graph.addAttribute("ui.stylesheet","url('data/design.css')");

        FileSource fs = new FileSourceEdge();
        fs.addSink(graph);

        try {
            fs.readAll(filePath);

        } catch (IOException e) {
            e.printStackTrace();
        }

        // Coefficient de clustering
        int noeuds = graph.getNodeCount();
        int liens = graph.getEdgeCount();
        System.out.println("Noeud = " + noeuds);
        System.out.println("Liens = " + liens);
        double degMoyen = Toolkit.averageDegree(graph);
        System.out.println("degré moyen = " + degMoyen);
        System.out.println("coefficient de clustering: " + Toolkit.averageClusteringCoefficient(graph));
        //GenerateurGS_Reseau generateurGS_reseau = new GenerateurGS_Reseau();
        System.out.println("coefficient de clustering pour un réseau aléatoire de la même taille et du même degré moyen est : "
                + Toolkit.averageClusteringCoefficient(mes.generer_Aleatoire(noeuds,
                degMoyen)));

    }
}
