From ac6de0d3bed1d9849addf0ffd8700721fa8d7580 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Mon, 21 Mar 2016 20:44:25 +0100 Subject: Add DSDV and AODV --- structure/Grid.java | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) (limited to 'structure/Grid.java') diff --git a/structure/Grid.java b/structure/Grid.java index 0255909..d075196 100644 --- a/structure/Grid.java +++ b/structure/Grid.java @@ -1,14 +1,19 @@ package structure; import java.util.*; +import java.util.Map.Entry; public class Grid { - + public enum Protocol { + AODV, DSDV + } private ArrayList grid=new ArrayList<>(); private ArrayList> links=new ArrayList<>(); + private int bestLinkByProtocol; + private Random rand = new Random(); private final int maxWeight=100; @@ -16,7 +21,7 @@ public class Grid { /** * Build a 3x3 Grid */ - public Grid(){ + public Grid(Protocol protocol){ // Build Grid for(int i=0;i<9;i++){ @@ -26,6 +31,45 @@ public class Grid { this.buildRandomLink(); this.buildLinks(); + + switch(protocol){ + case AODV: + this.bestLinkByProtocol=this.getBestLinkIndex(); + break; + case DSDV: + + HashMap currentBestLink=new HashMap<>(); + for(int i=0;i<10000;i++){ + int current=this.getBestLinkIndex(); + if(currentBestLink.containsKey(current)){ + currentBestLink.put(current, currentBestLink.get(current)+1); + } + else{ + currentBestLink.put(current, 1); + } + this.buildRandomLink(); + } + Set entryTMP = currentBestLink.keySet(); + + int max=currentBestLink.get(entryTMP.iterator().next()); + int maxId=0; + entryTMP = currentBestLink.keySet(); + Iterator it=entryTMP.iterator(); + while(it.hasNext()) { + int entryId=it.next(); + int entry=currentBestLink.get(entryId); + if(entry> max){ + max=entry; + maxId=entryId; + } + + System.out.println("Id : "+ entryId + " max "+ entry); + + } + this.bestLinkByProtocol=maxId; + System.out.println("Retenu :"+maxId); + break; + } } @@ -219,6 +263,18 @@ public class Grid { this.links = links; } + + + /** + * @return the bestLinkByProtocol + */ + public int getBestLinkByProtocol() { + return bestLinkByProtocol; + } + + + + } -- cgit v1.2.3