/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package jung;

import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.SparseMultigraph;
import edu.uci.ics.jung.graph.util.EdgeType;
import java.util.ArrayList;
import java.util.List;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 *
 * @author martin
 */
public class Jung {
    
    public Jung() {
    }
    
    @BeforeClass
    public static void setUpClass() {
    }
    
    @AfterClass
    public static void tearDownClass() {
    }
    
    @Before
    public void setUp() {
    }
    
    @After
    public void tearDown() {
    }
    
    @Test
    public void bench(){
         Graph<Object, Object> graph = new SparseMultigraph<Object, Object>();
         
         long a = System.currentTimeMillis();
         List<Integer> li = new ArrayList<>();
         for (int i=0;i<1000;i++){
             li.add(i);
             graph.addVertex(i);
         }
         
         long b = System.currentTimeMillis();
         List<String> ls = new ArrayList<>();
         for (int i=1000;i<2000;i++){
             ls.add(Integer.toString(i));
             graph.addVertex(Integer.toString(i));
         }
         
         long c = System.currentTimeMillis();
         for (String s : ls)
             for (Integer i : li)
                 graph.addEdge(s+i,s, i);
                  
         long d = System.currentTimeMillis();
         for (String s : ls)
             for (Object o :graph.getNeighbors(s)){
                 
             }
         
         long f = System.currentTimeMillis();
         //graph.addVertex("chien");
         for (String s : ls)
             graph.addEdge(s+"chien", s, "chien");
         
         long g = System.currentTimeMillis();
         for (String s : ls)
             for (Object o :graph.getNeighbors(s)){
                 if ("chien".equals(o))
                     graph.removeEdge(s+"chien");
             }
         
         long h = System.currentTimeMillis();
                 
         System.out.println("jung");
         System.out.println("insert "+ls.size()+" int : "+(b-a)+"ms");
         System.out.println("insert "+li.size()+" str : "+(c-b)+"ms");
         System.out.println("link all : "+(d-c)+"ms");
         System.out.println("iterate adjacent of all int : "+(f-d)+"ms");
         System.out.println("for all int insert chien : "+(g-f)+"ms");
         System.out.println("find all chien and destroy : "+(h-g)+"ms");
    }
    
     @Test
     public void hello() {
            // Graph<V, E> where V is the type of the vertices
           // and E is the type of the edges
           Graph<Integer, String> g = new SparseMultigraph<Integer, String>();
           // Add some vertices. From above we defined these to be type Integer.
           g.addVertex((Integer)1);
           g.addVertex((Integer)2);
           g.addVertex((Integer)3);
           // Add some edges. From above we defined these to be of type String
           // Note that the default is for undirected edges.
           g.addEdge("Edge-A", 1, 2); // Note that Java 1.5 auto-boxes primitives
           g.addEdge("Edge-B", 2, 3);
           // Let's see what we have. Note the nice output from the
           // SparseMultigraph<V,E> toString() method
           System.out.println("The graph g = " + g.toString());
           // Note that we can use the same nodes and edges in two different graphs.
           Graph<Integer, String> g2 = new SparseMultigraph<Integer, String>();
           g2.addVertex((Integer)1);
           g2.addVertex((Integer)2);
           g2.addVertex((Integer)3);
           g2.addEdge("Edge-A", 1,3);
           g2.addEdge("Edge-B", 2,3, EdgeType.DIRECTED);
           g2.addEdge("Edge-C", 3, 2, EdgeType.DIRECTED);
           g2.addEdge("Edge-P", 2,3); // A parallel edge
           System.out.println("The graph g2 = " + g2.toString()); 
     }
}
