From ac90cc95816e599902e5505f47198cfb79d48a64 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Thu, 7 Apr 2016 20:36:17 +0200 Subject: Clean code and add comment --- structure/Grid.java | 98 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 69 insertions(+), 29 deletions(-) (limited to 'structure/Grid.java') 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 routers=new ArrayList<>(); public ArrayList> 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 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 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 link){ int max=this.getWeigthOfLink(link.get(0), link.get(1)); for(int j=1;j 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(ArrayListlink, Router src, Router dest){ for(int j=0;j getGrid() { return routers; } - + /** + * Setter for grid + * @param grid + */ public void setGrid(ArrayList grid) { this.routers = grid; } - + /** + * Getter for links + * @return + */ public ArrayList> getLinks() { return links; } - + /** + * Setter for links + * @param links + */ public void setLinks(ArrayList> links) { this.links = links; } @@ -307,7 +344,10 @@ public class Grid { } - + /** + * Getter for debitMoy + * @return + */ public int getDebitMoy(){ return this.debitTotal/this.nbmesure; } -- cgit v1.2.3