diff options
| author | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2016-03-21 17:28:53 +0100 |
|---|---|---|
| committer | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2016-03-21 17:28:53 +0100 |
| commit | f453154938a0e1a3ba387ff1d7c0630e54b23855 (patch) | |
| tree | c43369b87577b2c087c825ba5d7b15f8ef6af631 | |
| parent | c03d794605cc158f6e0df2c44b5a014c9aa66e5d (diff) | |
Add personal graph
| -rw-r--r-- | main/Main.java | 55 | ||||
| -rw-r--r-- | structure/Graph.java | 108 | ||||
| -rw-r--r-- | structure/Grid.java | 12 |
3 files changed, 121 insertions, 54 deletions
diff --git a/main/Main.java b/main/Main.java index c1a4e1c..9efbccb 100644 --- a/main/Main.java +++ b/main/Main.java @@ -8,8 +8,12 @@ import java.util.Set; import org.graphstream.graph.Edge; import org.graphstream.graph.Graph; import org.graphstream.graph.implementations.SingleGraph; +import org.graphstream.ui.layout.springbox.EdgeSpring; +import org.graphstream.ui.swingViewer.basicRenderer.EdgeRenderer; +import org.graphstream.ui.util.EdgePoints; import structure.Grid; +import structure.MyGraph; import structure.Router; public class Main { @@ -17,52 +21,17 @@ public class Main { public static void main(String[] args) { Grid g=new Grid(); - - System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer"); - Graph graph = new SingleGraph("Tutorial 1"); - graph.addAttribute("ui.stylesheet", "url('resources/style.css')"); + MyGraph gr=new MyGraph("Routage Oportuniste", g); - ArrayList<Router> grid=g.getGrid(); - for(Router r : grid){ - graph.addNode(r.name); - - } - ArrayList<Integer> bestLink=g.getLinks().get(g.getBestLinkIndex()); - for(Router r : grid){ - String current=r.name; - HashMap<Router, Integer> relier=r.getLinks(); - Set<Router> k=relier.keySet(); - Iterator<Router> i=k.iterator(); - while(i.hasNext()){ - Router currentRouter=i.next(); - String currentRouterName=currentRouter.name; - try{ - //graph.addEdge(current+currentRouter, current, currentRouter).addAttribute("ui.style", "fill-color: rgb(0,100,255);"); - - if(g.isEdgeOfLink(bestLink, r, currentRouter)){ - Edge toAdd=graph.addEdge(current+currentRouterName, current, currentRouterName); - toAdd.setAttribute("ui.label", relier.get(currentRouter)); - toAdd.setAttribute("ui.style", "fill-color:red;"); - - }else{ - graph.addEdge(current+currentRouterName, current, currentRouterName).setAttribute("ui.label", relier.get(currentRouter)); - - } - + gr.display(); + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } - - } - catch(Exception e){ - // System.out.println("Bug de merde."); - } - - } - - } - g.printLinkWeight(); - - graph.display(); } } diff --git a/structure/Graph.java b/structure/Graph.java new file mode 100644 index 0000000..fd26653 --- /dev/null +++ b/structure/Graph.java @@ -0,0 +1,108 @@ +package structure; + +import java.util.*; + +import org.graphstream.graph.Edge; +import org.graphstream.graph.Graph; +import org.graphstream.graph.Node; +import org.graphstream.graph.implementations.SingleGraph; +import org.graphstream.ui.layout.springbox.EdgeSpring; +import org.graphstream.ui.swingViewer.basicRenderer.EdgeRenderer; +import org.graphstream.ui.util.EdgePoints; + + +public class MyGraph extends SingleGraph{ + + + private Grid grid; + + public MyGraph(String title, Grid grid) { + super(title); + // Allow CSS on view + System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer"); + // Set graph CSS + this.addAttribute("ui.stylesheet", "url('resources/style.css')"); + + // Assign grid + this.grid=grid; + + // Build node + for(Router r : this.grid.getGrid()){ + this.addNode(r.name); + + } + + // Build Edges + this.buildEdges(); + + //Build bestLink + this.showBestLink(); + + } + + + + public void buildEdges(){ + + for(Router r : this.grid.getGrid()){ + + String current=r.name; + + + HashMap<Router, Integer> relier=r.getLinks(); + Set<Router> k=relier.keySet(); + Iterator<Router> i=k.iterator(); + while(i.hasNext()){ + Router currentRouter=i.next(); + String currentRouterName=currentRouter.name; + try{ + //graph.addEdge(current+currentRouter, current, currentRouter).addAttribute("ui.style", "fill-color: rgb(0,100,255);"); + + /* if(g.isEdgeOfLink(bestLink, r, currentRouter)){ + toAdd=graph.addEdge(current+currentRouterName, current, currentRouterName); + toAdd.setAttribute("ui.label", relier.get(currentRouter)); + toAdd.setAttribute("ui.style", "fill-color:red;"); + + }else{*/ + this.addEdge(current+currentRouterName, current, currentRouterName).setAttribute("ui.label", relier.get(currentRouter)); + + //} + + + + } + catch(Exception e){ + // System.out.println("Bug de merde."); + } + + } + + } + } + + public void showBestLink(){ + ArrayList<Integer> bestLink=this.grid.getLinks().get(this.grid.getBestLinkIndex()); + for(int i=0;i<bestLink.size();i++){ + Iterator<Node> nodes= this.getNodeIterator(); + while(nodes.hasNext()){ + Node node=nodes.next(); + Iterator<Edge> edges=node.getEdgeIterator(); + while(edges.hasNext()){ + Edge edge=edges.next(); + + if(i<(bestLink.size()-1)){ + int destIndex=bestLink.get(i+1); + String src=this.grid.getGrid().get(bestLink.get(i)).name; + String dest=this.grid.getGrid().get(bestLink.get(i+1)).name; + if((edge.getNode0().getId().equals(src) && edge.getNode1().getId().equals(dest))||(edge.getNode1().getId().equals(src) && edge.getNode0().getId().equals(dest))){ + edge.setAttribute("ui.style", "fill-color:red;"); + } + } + + } + } + } + } + + +} diff --git a/structure/Grid.java b/structure/Grid.java index bd0af2a..20f2a4f 100644 --- a/structure/Grid.java +++ b/structure/Grid.java @@ -131,17 +131,7 @@ public class Grid { return currentBestLink; } - /*private int getMaxBottleneck(ArrayList<Integer> link){ - int max=this.getWeigthOfLink(link.get(0), link.get(1)); - for(int j=1;j<link.size()-1;j++){ - int currentMax=this.getWeigthOfLink(link.get(j), link.get(j+1)); - if(max<currentMax){ - max=currentMax; - } - - } - return max; - }*/ + private int getMaxBottleneck(ArrayList<Integer> link){ int max=this.getWeigthOfLink(link.get(0), link.get(1)); for(int j=1;j<link.size()-1;j++){ |
