diff options
| author | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2016-03-14 18:27:27 +0100 |
|---|---|---|
| committer | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2016-03-14 18:27:27 +0100 |
| commit | c9ec878c327ddd80387be303745a9b2e9ae65d1f (patch) | |
| tree | 166f3c2c4cb4d6e1443cb3b75ceca69e3f53f2c2 | |
| parent | e1375756dda1e8074c11a4278a323ff639dce288 (diff) | |
Change structure
| -rw-r--r-- | main/Main.java | 4 | ||||
| -rw-r--r-- | structure/Grid.java | 48 |
2 files changed, 49 insertions, 3 deletions
diff --git a/main/Main.java b/main/Main.java index df6ebd3..cad6995 100644 --- a/main/Main.java +++ b/main/Main.java @@ -6,7 +6,7 @@ public class Main { public static void main(String[] args) { Grid g=new Grid(); - - g.printGrid(); + g.printLinkWeight(); + System.out.println("Best link : " + g.getBestLinkIndex()); } } diff --git a/structure/Grid.java b/structure/Grid.java index 042d41c..c7b1211 100644 --- a/structure/Grid.java +++ b/structure/Grid.java @@ -15,6 +15,8 @@ public class Grid { private Random rand = new Random(); + private static final int maxWeight=100; + /** * Build a 3x3 Grid */ @@ -49,6 +51,7 @@ public class Grid { this.buildLinkWithRandomWeight(grid.get(2), grid.get(5)); this.buildLinkWithRandomWeight(grid.get(5), grid.get(8)); + this.buildLinks(); } @@ -112,11 +115,54 @@ public class Grid { private void buildLinkWithRandomWeight(Router router1, Router router2){ - router1.buildLink(router2, rand.nextInt(50)); + router1.buildLink(router2, rand.nextInt(this.maxWeight)); + } + + + + public int getBestLinkIndex(){ + int currentBestLink=0; + int currentBestLinkBottleneck=0; + for(int i=0;i<this.links.size();i++){ + ArrayList<Integer> currentLink=this.links.get(i); + int currentLinkBottleneck=this.getMaxBottleneck(currentLink); + if(currentBestLinkBottleneck<currentLinkBottleneck){ + currentBestLink=i; + currentBestLinkBottleneck=currentLinkBottleneck; + } + } + + return currentBestLink; } + private int getMaxBottleneck(ArrayList<Integer> link){ + int max=this.getWeigthOfLink(link.get(0), link.get(1)); + for(int j=1;j<link.size()-1;j++){ + int currentMax=this.getWeigthOfLink(link.get(j), link.get(j+1)); + if(max<currentMax){ + max=currentMax; + } + + } + return max; + } + private int getWeigthOfLink(int router1,int router2){ + return this.grid.get(router1).getWeight(this.grid.get(router2)); + } + + public void printLinkWeight(){ + for(int i=0;i<this.links.size();i++){ + ArrayList<Integer> link=this.links.get(i); + System.out.print("Link number " + i + " ==> "); + for(int j=0;j<link.size()-1;j++){ + //System.out.print(this.getWeigthOfLink(link.get(j), link.get(j+1)) + " "); + } + System.out.println(this.getMaxBottleneck(link)); + //System.out.println(); + } + } |
