diff options
| author | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2016-04-07 20:36:17 +0200 |
|---|---|---|
| committer | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2016-04-07 20:36:17 +0200 |
| commit | ac90cc95816e599902e5505f47198cfb79d48a64 (patch) | |
| tree | f9c37cebd6fe6f71431a874e72cafd549020e020 /structure/Grid.java | |
| parent | f4e0747e5991736f64aef06883e41eaefdf3f7a3 (diff) | |
Clean code and add commentdevelop
Diffstat (limited to 'structure/Grid.java')
| -rw-r--r-- | structure/Grid.java | 98 |
1 files changed, 69 insertions, 29 deletions
diff --git a/structure/Grid.java b/structure/Grid.java index 08dd305..5f6a1e0 100644 --- a/structure/Grid.java +++ b/structure/Grid.java @@ -1,26 +1,26 @@ package structure; import java.util.*; -import java.util.Map.Entry; +/** + * Grid structure + * @author loic, adama + * + */ public class Grid { + // Define protocole name public enum Protocol { AODV, DSDV, CUSTOM } private ArrayList<Router> routers=new ArrayList<>(); public ArrayList<ArrayList<Integer>> links=new ArrayList<>(); - - private int[] pMoy={50,59,92,50,4,8,6,13,7,1,51,6}; - private int bestLink; private Protocol protocol; private int counterCUSTOM=5; - private Random rand = new Random(); - private final int maxWeight=100; - - int debitTotal=0,nbmesure=0; + private Random rand = new Random(); // Init rand + int debitTotal=0,nbmesure=0; // To compute debit moyen @@ -43,13 +43,14 @@ public class Grid { this.protocol=protocol; switch(protocol){ - case DSDV: + case AODV: this.bestLink=this.getBestLinkIndex(); break; case CUSTOM: this.bestLink=this.getBestLinkIndex(); break; - case AODV: + case DSDV: + // Change radio conditions 100 times HashMap<Integer,Integer> currentBestLink=new HashMap<>(); for(int i=0;i<100;i++){ int current=this.getBestLinkIndex(); @@ -61,8 +62,8 @@ public class Grid { } this.buildEdgeWithRandomWeigth(); } + // Get Best Link Set<Integer> entryTMP = currentBestLink.keySet(); - int max=currentBestLink.get(entryTMP.iterator().next()); int maxId=0; entryTMP = currentBestLink.keySet(); @@ -74,12 +75,8 @@ public class Grid { max=entry; maxId=entryId; } - - //System.out.println("Id : "+ entryId + " max "+ entry); - } this.bestLink=maxId; - // System.out.println("Retenu :"+maxId); break; @@ -88,12 +85,10 @@ public class Grid { } - + /** + * Build the 3x3 links with random weight + */ public void buildEdgeWithRandomWeigth(){ - - - - // First line this.buildLinkWithRandomWeight(routers.get(0), routers.get(1), 100); this.buildLinkWithRandomWeight(routers.get(1), routers.get(2),100); @@ -126,6 +121,9 @@ public class Grid { } + /** + * Build all paths (with chained router id) + */ private void buildPath(){ // Link1 @@ -185,12 +183,21 @@ public class Grid { } + /** + * Build link with a random weight + * @param router1 router 1 to link to router 2 + * @param router2 router 2 to link to router 1 + * @param pMoy max weight + */ private void buildLinkWithRandomWeight(Router router1, Router router2, int pMoy){ router1.buildLink(router2, rand.nextInt(pMoy)); } - + /** + * Get the best link by bottleneck + * @return + */ public int getBestLinkIndex(){ int currentBestLink=0; int currentBestLinkBottleneck=0; @@ -207,6 +214,11 @@ public class Grid { } + /** + * Get the bottleneck of the link + * @param link + * @return + */ public int getMaxBottleneck(ArrayList<Integer> link){ int max=this.getWeigthOfLink(link.get(0), link.get(1)); for(int j=1;j<link.size()-1;j++){ @@ -219,11 +231,19 @@ public class Grid { return max; } + /** + * Get the weight of a link + * @param router1 + * @param router2 + * @return + */ private int getWeigthOfLink(int router1,int router2){ return this.routers.get(router1).getWeight(this.routers.get(router2)); } - + /** + * Print infos + */ public void printLinkWeight(){ for(int i=0;i<this.links.size();i++){ ArrayList<Integer> link=this.links.get(i); @@ -232,13 +252,18 @@ public class Grid { System.out.print(this.getWeigthOfLink(link.get(j), link.get(j+1)) + " "); } System.out.println(" Goulot :"+this.getMaxBottleneck(link)); - //System.out.println(); } } - + /** + * Check if a link is part of an edge + * @param link + * @param src + * @param dest + * @return + */ public boolean isEdgeOfLink(ArrayList<Integer>link, Router src, Router dest){ for(int j=0;j<link.size()-1;j++){ Router current=this.routers.get(link.get(j)); @@ -268,22 +293,34 @@ public class Grid { } - + /** + * Getter for grid + * @return + */ public ArrayList<Router> getGrid() { return routers; } - + /** + * Setter for grid + * @param grid + */ public void setGrid(ArrayList<Router> grid) { this.routers = grid; } - + /** + * Getter for links + * @return + */ public ArrayList<ArrayList<Integer>> getLinks() { return links; } - + /** + * Setter for links + * @param links + */ public void setLinks(ArrayList<ArrayList<Integer>> links) { this.links = links; } @@ -307,7 +344,10 @@ public class Grid { } - + /** + * Getter for debitMoy + * @return + */ public int getDebitMoy(){ return this.debitTotal/this.nbmesure; } |
