diff options
| author | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2016-03-22 10:49:04 +0100 |
|---|---|---|
| committer | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2016-03-22 10:49:04 +0100 |
| commit | bd27005eadf8c9526bf0167ea19a2d949bcca1f9 (patch) | |
| tree | 9d1fe394fd11b3d3a1430e2828c6bdae56b48709 | |
| parent | 7f3a91e6dcbc8277613db6e21b2fd11b344f7a19 (diff) | |
test
| -rw-r--r-- | main/Main.java | 11 | ||||
| -rw-r--r-- | structure/Grid.java | 81 |
2 files changed, 50 insertions, 42 deletions
diff --git a/main/Main.java b/main/Main.java index c1f2693..eaa8d41 100644 --- a/main/Main.java +++ b/main/Main.java @@ -19,13 +19,14 @@ import structure.Router; public class Main { public static void main(String[] args) { - Grid g=new Grid(Grid.Protocol.CUSTOM); + Grid g=new Grid(Grid.Protocol.AODV); + // Build Graph for graphstream MyGraph gr=new MyGraph("Routage Oportuniste", g); - - - gr.display(); + + + // Update Graph while(true){ try { Thread.sleep(1000); @@ -33,7 +34,7 @@ public class Main { // TODO Auto-generated catch block e.printStackTrace(); } - g.buildRandomLink(); + g.buildEdgeWithRandomWeigth(); System.out.println("Update !"); gr.update(); } diff --git a/structure/Grid.java b/structure/Grid.java index e929f5d..e5db1ef 100644 --- a/structure/Grid.java +++ b/structure/Grid.java @@ -9,39 +9,46 @@ public class Grid { AODV, DSDV, CUSTOM } - private ArrayList<Router> grid=new ArrayList<>(); + private ArrayList<Router> routers=new ArrayList<>(); private ArrayList<ArrayList<Integer>> links=new ArrayList<>(); - private int bestLinkByProtocol; - private Protocol protocolChoose; + + private int bestLink; + private Protocol protocol; private int counterCUSTOM=5; private Random rand = new Random(); - private final int maxWeight=100; + + + + /** * Build a 3x3 Grid */ public Grid(Protocol protocol){ - // Build Grid + // Build router liste for(int i=0;i<9;i++){ - this.grid.add(new Router()); + this.routers.add(new Router()); } - this.buildRandomLink(); - this.buildLinks(); - this.protocolChoose=protocol; + this.buildEdgeWithRandomWeigth(); + + this.buildPath(); + + + this.protocol=protocol; switch(protocol){ case AODV: - this.bestLinkByProtocol=this.getBestLinkIndex(); + this.bestLink=this.getBestLinkIndex(); break; case DSDV: case CUSTOM: HashMap<Integer,Integer> currentBestLink=new HashMap<>(); - for(int i=0;i<10000;i++){ + for(int i=0;i<100000;i++){ int current=this.getBestLinkIndex(); if(currentBestLink.containsKey(current)){ currentBestLink.put(current, currentBestLink.get(current)+1); @@ -49,7 +56,7 @@ public class Grid { else{ currentBestLink.put(current, 1); } - this.buildRandomLink(); + this.buildEdgeWithRandomWeigth(); } Set<Integer> entryTMP = currentBestLink.keySet(); @@ -68,7 +75,7 @@ public class Grid { System.out.println("Id : "+ entryId + " max "+ entry); } - this.bestLinkByProtocol=maxId; + this.bestLink=maxId; System.out.println("Retenu :"+maxId); break; @@ -79,34 +86,34 @@ public class Grid { - public void buildRandomLink(){ + public void buildEdgeWithRandomWeigth(){ // First line - this.buildLinkWithRandomWeight(grid.get(0), grid.get(1)); - this.buildLinkWithRandomWeight(grid.get(1), grid.get(2)); + this.buildLinkWithRandomWeight(routers.get(0), routers.get(1)); + this.buildLinkWithRandomWeight(routers.get(1), routers.get(2)); // Second line - this.buildLinkWithRandomWeight(grid.get(3), grid.get(4)); - this.buildLinkWithRandomWeight(grid.get(4), grid.get(5)); + this.buildLinkWithRandomWeight(routers.get(3), routers.get(4)); + this.buildLinkWithRandomWeight(routers.get(4), routers.get(5)); // Third line - this.buildLinkWithRandomWeight(grid.get(6), grid.get(7)); - this.buildLinkWithRandomWeight(grid.get(7), grid.get(8)); + this.buildLinkWithRandomWeight(routers.get(6), routers.get(7)); + this.buildLinkWithRandomWeight(routers.get(7), routers.get(8)); // First column - this.buildLinkWithRandomWeight(grid.get(0), grid.get(3)); - this.buildLinkWithRandomWeight(grid.get(3), grid.get(6)); + this.buildLinkWithRandomWeight(routers.get(0), routers.get(3)); + this.buildLinkWithRandomWeight(routers.get(3), routers.get(6)); // Second column - this.buildLinkWithRandomWeight(grid.get(1), grid.get(4)); - this.buildLinkWithRandomWeight(grid.get(4), grid.get(7)); + this.buildLinkWithRandomWeight(routers.get(1), routers.get(4)); + this.buildLinkWithRandomWeight(routers.get(4), routers.get(7)); // Third column - this.buildLinkWithRandomWeight(grid.get(2), grid.get(5)); - this.buildLinkWithRandomWeight(grid.get(5), grid.get(8)); + this.buildLinkWithRandomWeight(routers.get(2), routers.get(5)); + this.buildLinkWithRandomWeight(routers.get(5), routers.get(8)); } - private void buildLinks(){ + private void buildPath(){ // Link1 ArrayList<Integer> link1=new ArrayList<>(); @@ -200,7 +207,7 @@ public class Grid { } private int getWeigthOfLink(int router1,int router2){ - return this.grid.get(router1).getWeight(this.grid.get(router2)); + return this.routers.get(router1).getWeight(this.routers.get(router2)); } @@ -221,10 +228,10 @@ public class Grid { public boolean isEdgeOfLink(ArrayList<Integer>link, Router src, Router dest){ for(int j=0;j<link.size()-1;j++){ - Router current=this.grid.get(link.get(j)); + Router current=this.routers.get(link.get(j)); if(src.name.equals(current.name)){ if(j<link.size()-1){ - Router currentDest=this.grid.get(link.get(j+1)); + Router currentDest=this.routers.get(link.get(j+1)); if(currentDest.name.equals(dest.name)){ return true; @@ -233,10 +240,10 @@ public class Grid { } } for(int j=0;j<link.size()-1;j++){ - Router current=this.grid.get(link.get(j)); + Router current=this.routers.get(link.get(j)); if(dest.name.equals(current.name)){ if(j<link.size()-1){ - Router currentDest=this.grid.get(link.get(j+1)); + Router currentDest=this.routers.get(link.get(j+1)); if(currentDest.name.equals(src.name)){ return true; @@ -250,12 +257,12 @@ public class Grid { public ArrayList<Router> getGrid() { - return grid; + return routers; } public void setGrid(ArrayList<Router> grid) { - this.grid = grid; + this.routers = grid; } @@ -274,15 +281,15 @@ public class Grid { * @return the bestLinkByProtocol */ public int getBestLinkByProtocol() { - if(this.protocolChoose==Protocol.CUSTOM){ + if(this.protocol==Protocol.CUSTOM){ this.counterCUSTOM--; if(this.counterCUSTOM==0){ - this.bestLinkByProtocol=this.getBestLinkIndex(); + this.bestLink=this.getBestLinkIndex(); this.counterCUSTOM=5; } } - return bestLinkByProtocol; + return bestLink; } |
