aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormanzerbredes <loic.guegan_secondary@yahoo.fr>2016-03-21 18:02:31 +0100
committermanzerbredes <loic.guegan_secondary@yahoo.fr>2016-03-21 18:02:31 +0100
commit0e1704bbcb3279e4779f09c06127a7c76cc8fb04 (patch)
treef84e7d18e76df053c9bcb194da163f278873eada
parentf453154938a0e1a3ba387ff1d7c0630e54b23855 (diff)
Add live
-rw-r--r--main/Main.java15
-rw-r--r--structure/Graph.java55
-rw-r--r--structure/Grid.java10
-rw-r--r--structure/Router.java12
4 files changed, 71 insertions, 21 deletions
diff --git a/main/Main.java b/main/Main.java
index 9efbccb..fc84e86 100644
--- a/main/Main.java
+++ b/main/Main.java
@@ -26,11 +26,16 @@ public class Main {
gr.display();
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ while(true){
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ g.buildRandomLink();
+ System.out.println("Update !");
+ gr.update();
}
}
diff --git a/structure/Graph.java b/structure/Graph.java
index fd26653..3092a4f 100644
--- a/structure/Graph.java
+++ b/structure/Graph.java
@@ -43,7 +43,13 @@ public class MyGraph extends SingleGraph{
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;
@@ -54,22 +60,11 @@ public class MyGraph extends SingleGraph{
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);
+ Edge toAdd=this.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.");
@@ -104,5 +99,37 @@ public class MyGraph extends SingleGraph{
}
}
+ public void update(){
+ // Reset color
+ Iterator<Edge> 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<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;
+ if(edge.getId().equals(current+currentRouterName)||edge.getId().equals(currentRouterName+current)){
+ edge.setAttribute("ui.label", relier.get(currentRouter));
+ }
+ }
+ }
+
+ }
+
+ //Build bestLink
+ this.showBestLink();
+ }
}
diff --git a/structure/Grid.java b/structure/Grid.java
index 20f2a4f..0255909 100644
--- a/structure/Grid.java
+++ b/structure/Grid.java
@@ -23,6 +23,14 @@ public class Grid {
this.grid.add(new Router());
}
+ this.buildRandomLink();
+
+ this.buildLinks();
+ }
+
+
+
+ public void buildRandomLink(){
// First line
this.buildLinkWithRandomWeight(grid.get(0), grid.get(1));
this.buildLinkWithRandomWeight(grid.get(1), grid.get(2));
@@ -47,10 +55,8 @@ public class Grid {
this.buildLinkWithRandomWeight(grid.get(2), grid.get(5));
this.buildLinkWithRandomWeight(grid.get(5), grid.get(8));
- this.buildLinks();
}
-
private void buildLinks(){
// Link1
diff --git a/structure/Router.java b/structure/Router.java
index d977471..fce5977 100644
--- a/structure/Router.java
+++ b/structure/Router.java
@@ -15,7 +15,15 @@ public class Router {
this.name=""+id;
}
+ public void resetLinks(){
+ this.links=new HashMap<>();
+ }
+
public void buildLink(Router router, int weight){
+ this.links.remove(router);
+ router.removeLink(this);
+
+
this.links.put(router, weight);
router.addLink(this, weight);
}
@@ -32,6 +40,10 @@ public class Router {
return links;
}
+ public void removeLink(Router router){
+ this.links.remove(router);
+ }
+
public void setLinks(HashMap<Router, Integer> links) {
this.links = links;
}