From fa62f87db15218fb2f1aa529a34b4711068a8290 Mon Sep 17 00:00:00 2001 From: Loic GUEGAN Date: Fri, 29 Jul 2016 15:01:12 +0200 Subject: Add screen --- resources/screen.png | Bin 0 -> 39732 bytes structure/Graph.java | 162 ------------------------------------------------- structure/MyGraph.java | 162 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+), 162 deletions(-) create mode 100644 resources/screen.png delete mode 100644 structure/Graph.java create mode 100644 structure/MyGraph.java diff --git a/resources/screen.png b/resources/screen.png new file mode 100644 index 0000000..9f5541b Binary files /dev/null and b/resources/screen.png differ diff --git a/structure/Graph.java b/structure/Graph.java deleted file mode 100644 index 1c2dc0f..0000000 --- a/structure/Graph.java +++ /dev/null @@ -1,162 +0,0 @@ -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; - - private int miss=0; - private int success=0; - - 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; - - int i=0; - int ll=this.grid.getGrid().size(); - // Build node - for(Router r : this.grid.getGrid()){ - if(i==0){ - this.addNode(r.name).setAttribute("ui.label", "Source"); - } - else{ - if(i==ll-1){ - this.addNode(r.name).setAttribute("ui.label", "Destination"); - - } - else{ - this.addNode(r.name); - - } - - } - i++; - - } - - // Build Edges - this.buildEdges(); - - //Build bestLink - this.showBestLink(); - - } - - - - public void buildEdges(){ - - /*Iterator edges=this.getEdgeIterator(); - while(edges.hasNext()){ - Edge edge=edges.next(); - this.removeEdge(edge); - }*/ - - for(Router r : this.grid.getGrid()){ - - String current=r.name; - - - HashMap relier=r.getLinks(); - Set k=relier.keySet(); - Iterator i=k.iterator(); - while(i.hasNext()){ - Router currentRouter=i.next(); - - String currentRouterName=currentRouter.name; - try{ - Edge toAdd=this.addEdge(current+currentRouterName, current, currentRouterName); - toAdd.setAttribute("ui.label", relier.get(currentRouter)); - } - catch(Exception e){ - // System.out.println("Bug de merde."); - } - - } - - } - } - - public void showBestLink(){ - ArrayList bestLink=this.grid.getLinks().get(this.grid.getBestLinkByProtocol()); - for(int i=0;i nodes= this.getNodeIterator(); - while(nodes.hasNext()){ - Node node=nodes.next(); - Iterator 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;"); - } - } - - } - } - } - } - - public void update(){ - // Reset color - Iterator edges=this.getEdgeIterator(); - while(edges.hasNext()){ - Edge edge=edges.next(); - edge.setAttribute("ui.style", "fill-color:black;"); - } - // Update label - edges=this.getEdgeIterator(); - while(edges.hasNext()){ - Edge edge=edges.next(); - for(Router r : this.grid.getGrid()){ - String current=r.name; - - HashMap relier=r.getLinks(); - Set k=relier.keySet(); - Iterator i=k.iterator(); - while(i.hasNext()){ - Router currentRouter=i.next(); - - String currentRouterName=currentRouter.name; - if(edge.getId().equals(current+currentRouterName)||edge.getId().equals(currentRouterName+current)){ - edge.setAttribute("ui.label", relier.get(currentRouter)); - } - } - } - - } - - if(this.grid.getBestLinkByProtocol()==this.grid.getBestLinkIndex()){ - this.success++; - } - else{ - this.miss++; - } - System.out.println("Success = " + this.success + " Miss = " + this.miss + " try number :"+(this.success+this.miss)) ; - - //Build bestLink - this.showBestLink(); - } - -} diff --git a/structure/MyGraph.java b/structure/MyGraph.java new file mode 100644 index 0000000..1c2dc0f --- /dev/null +++ b/structure/MyGraph.java @@ -0,0 +1,162 @@ +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; + + private int miss=0; + private int success=0; + + 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; + + int i=0; + int ll=this.grid.getGrid().size(); + // Build node + for(Router r : this.grid.getGrid()){ + if(i==0){ + this.addNode(r.name).setAttribute("ui.label", "Source"); + } + else{ + if(i==ll-1){ + this.addNode(r.name).setAttribute("ui.label", "Destination"); + + } + else{ + this.addNode(r.name); + + } + + } + i++; + + } + + // Build Edges + this.buildEdges(); + + //Build bestLink + this.showBestLink(); + + } + + + + public void buildEdges(){ + + /*Iterator edges=this.getEdgeIterator(); + while(edges.hasNext()){ + Edge edge=edges.next(); + this.removeEdge(edge); + }*/ + + for(Router r : this.grid.getGrid()){ + + String current=r.name; + + + HashMap relier=r.getLinks(); + Set k=relier.keySet(); + Iterator i=k.iterator(); + while(i.hasNext()){ + Router currentRouter=i.next(); + + String currentRouterName=currentRouter.name; + try{ + Edge toAdd=this.addEdge(current+currentRouterName, current, currentRouterName); + toAdd.setAttribute("ui.label", relier.get(currentRouter)); + } + catch(Exception e){ + // System.out.println("Bug de merde."); + } + + } + + } + } + + public void showBestLink(){ + ArrayList bestLink=this.grid.getLinks().get(this.grid.getBestLinkByProtocol()); + for(int i=0;i nodes= this.getNodeIterator(); + while(nodes.hasNext()){ + Node node=nodes.next(); + Iterator 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;"); + } + } + + } + } + } + } + + public void update(){ + // Reset color + Iterator edges=this.getEdgeIterator(); + while(edges.hasNext()){ + Edge edge=edges.next(); + edge.setAttribute("ui.style", "fill-color:black;"); + } + // Update label + edges=this.getEdgeIterator(); + while(edges.hasNext()){ + Edge edge=edges.next(); + for(Router r : this.grid.getGrid()){ + String current=r.name; + + HashMap relier=r.getLinks(); + Set k=relier.keySet(); + Iterator i=k.iterator(); + while(i.hasNext()){ + Router currentRouter=i.next(); + + String currentRouterName=currentRouter.name; + if(edge.getId().equals(current+currentRouterName)||edge.getId().equals(currentRouterName+current)){ + edge.setAttribute("ui.label", relier.get(currentRouter)); + } + } + } + + } + + if(this.grid.getBestLinkByProtocol()==this.grid.getBestLinkIndex()){ + this.success++; + } + else{ + this.miss++; + } + System.out.println("Success = " + this.success + " Miss = " + this.miss + " try number :"+(this.success+this.miss)) ; + + //Build bestLink + this.showBestLink(); + } + +} -- cgit v1.2.3