import org.graphstream.graph.Edge;
import org.graphstream.graph.Graph;
import org.graphstream.graph.Node;
import org.graphstream.graph.implementations.SingleGraph;


public class GenerateurCollabo {
    private Graph g;
    private double p;


    public GenerateurCollabo(Graph g, double p){
        this.g = g;
        if(p >= 1) this.p = 1;
        else
            this.p = p;
    }

    public void addNode(){
        Node n = g.addNode(""+g.getNodeCount());
        if(g.getNodeCount() > 1){
            Node v = g.getNode((int)(Math.random()*(g.getNodeCount()-1)));
            for(Edge e:v.getEdgeSet()){
                System.out.println("e:" + e.getNode0() + e.getNode1());
                Node vv = e.getOpposite(v);
                System.out.println("N: " + n + " V: " + v + " VV: " + vv);
                if(Math.random()<p)
                    g.addEdge(n.getId() + vv.getId(), n, vv);
            }
            g.addEdge(n.getId()+v.getId(), n, v);
            System.out.println("next");
        }
    }

    public static void main(String[] args) {
        Graph g = new SingleGraph("Graph");
        GenerateurCollabo gc = new GenerateurCollabo(g, 0.1);
        for(int i=0; i<20; i++)
            gc.addNode();
        g.display();
    }

     /*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();
      */


}
