Change structure

This commit is contained in:
manzerbredes 2016-03-14 18:27:27 +01:00
parent e1375756dd
commit c9ec878c32
2 changed files with 49 additions and 3 deletions

View file

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

View file

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