aboutsummaryrefslogtreecommitdiff
path: root/structure/MyGraph.java
diff options
context:
space:
mode:
Diffstat (limited to 'structure/MyGraph.java')
-rw-r--r--structure/MyGraph.java63
1 files changed, 25 insertions, 38 deletions
diff --git a/structure/MyGraph.java b/structure/MyGraph.java
index 77a1f77..a5c6f8f 100644
--- a/structure/MyGraph.java
+++ b/structure/MyGraph.java
@@ -2,23 +2,27 @@ package structure;
import java.util.*;
-import org.graphstream.graph.Edge;
-import org.graphstream.graph.Graph;
-import org.graphstream.graph.Node;
+import org.graphstream.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;
+/**
+ * Class for display graph with GraphStream
+ * @author loic, adama
+ *
+ */
public class MyGraph extends SingleGraph{
+ // Grid associate to the graph
private Grid grid;
-
- private int miss=0;
- private int success=0;
-
+
+ /**
+ * Build a graph with a grid
+ *
+ * @param title
+ * @param grid
+ */
public MyGraph(String title, Grid grid) {
super(title);
// Allow CSS on view
@@ -61,20 +65,13 @@ public class MyGraph extends SingleGraph{
}
-
+ /**
+ * Build edges
+ */
public void buildEdges(){
- /*Iterator<Edge> edges=this.getEdgeIterator();
- while(edges.hasNext()){
- Edge edge=edges.next();
- this.removeEdge(edge);
- }*/
-
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();
@@ -87,14 +84,14 @@ public class MyGraph extends SingleGraph{
toAdd.setAttribute("ui.label", relier.get(currentRouter));
}
catch(Exception e){
- // System.out.println("Bug de merde.");
- }
-
+ }
}
-
}
}
+ /**
+ * Update best link on screen
+ */
public void showBestLink(){
ArrayList<Integer> bestLink=this.grid.getLinks().get(this.grid.getBestLinkByProtocol());
for(int i=0;i<bestLink.size();i++){
@@ -106,7 +103,6 @@ public class MyGraph extends SingleGraph{
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))){
@@ -119,6 +115,9 @@ public class MyGraph extends SingleGraph{
}
}
+ /**
+ * Update all the graph on screen
+ */
public void update(){
// Reset color
Iterator<Edge> edges=this.getEdgeIterator();
@@ -144,20 +143,8 @@ public class MyGraph extends SingleGraph{
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();
}