package com.github.oxal;

import org.graphstream.algorithm.Toolkit;
import org.graphstream.graph.Graph;
import org.graphstream.graph.implementations.DefaultGraph;
import org.graphstream.graph.implementations.SingleGraph;
import org.graphstream.stream.file.FileSource;
import org.graphstream.stream.file.FileSourceEdge;
import org.graphstream.stream.file.FileSourceFactory;

import java.io.IOException;
import java.util.stream.Collector;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        String filePath = "src/main/resources/graph.txt";
        Graph g = new DefaultGraph("g");
        FileSource fs = new FileSourceEdge();

        fs.addSink(g);

        try {
            fs.readAll(filePath);
        } catch (IOException e) {
            e.printStackTrace();
        }

        //nb de node
        System.out.println("nb node " + g.getNodeCount());

        //nb de edge
        System.out.println("nb edge " + g.getEdgeCount());


        //moyenne de degré
        System.out.println("moy degre " + Toolkit.averageDegree(g));

        /**
         *
         System.out.println(g.getNodeSet()
         .stream()
         .mapToDouble(n -> n.getDegree())
         .average()
         .getAsDouble()
         );
         */

        //coef cluster
        System.out.println("coef cluster " + Toolkit.averageClusteringCoefficient(g));


        //connexe
        System.out.println("connexe " + Toolkit.isConnected(g));

        int[] tab = Toolkit.degreeDistribution(g);

        for (int i = 0; i<tab.length; i++){
            System.out.println(i + " : " + tab[i]);
        }


    }
}
