import org.graphstream.graph.Graph;
import org.graphstream.graph.implementations.DefaultGraph;
import org.graphstream.stream.file.FileSource;
import org.graphstream.stream.file.FileSourceDGS;

import java.io.IOException;

/**
 * The goal of this class is to compute the correlation Dimension of the graph store in a dgs file
 *
 */
public class CorrelationDimension {

	/**
	 * The goal of the function is to add to the input argument graph g all the nodes present in the dgs file at the
	 * argument path.
	 *
	 * @param g graph to which we want to add the nodes
	 * @param path the path to the dgs file where the graph data is store
	 */
	public void add_node_to_graph_from_dgs_file(Graph g, String path, int nb_noeuds) throws IOException {
		FileSource fs = new FileSourceDGS();

		fs.addSink(g);
		int i = 0;
		try {
			fs.begin(path);
			while (fs.nextEvents() && i <= nb_noeuds) {
				i = i + 1;
			}
		} catch( IOException e) {
			throw  new IOException(e);
		}
	}

	public static void main(String... args) {
		String path = args[0];
		int nb_noeuds = Integer.parseInt(args[1]);
		System.out.println("path : " + path);
		if (path.endsWith("dgs")) {
			Graph g = new DefaultGraph("graph_test");
			CorrelationDimension correlationDimension = new CorrelationDimension();
			try {
				correlationDimension.add_node_to_graph_from_dgs_file(g, path, nb_noeuds);
			} catch (IOException e) {
				e.printStackTrace();
			}
			System.out.println("nombre de noeud : " + g.getNodeCount());
		}
	}
}
