This commit is contained in:
manzerbredes 2016-03-21 18:02:31 +01:00
parent f453154938
commit 0e1704bbcb
4 changed files with 71 additions and 21 deletions

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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

View file

@ -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;
}