aboutsummaryrefslogtreecommitdiff
path: root/structure/Grid.java
diff options
context:
space:
mode:
authormanzerbredes <loic.guegan_secondary@yahoo.fr>2016-03-21 20:44:25 +0100
committermanzerbredes <loic.guegan_secondary@yahoo.fr>2016-03-21 20:44:25 +0100
commitac6de0d3bed1d9849addf0ffd8700721fa8d7580 (patch)
tree7a544624a29159df3f45681897600cbf60381ccb /structure/Grid.java
parent3443b5b3367da1a31be4f594fda9c58abbbca605 (diff)
Add DSDV and AODV
Diffstat (limited to 'structure/Grid.java')
-rw-r--r--structure/Grid.java60
1 files changed, 58 insertions, 2 deletions
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<Router> grid=new ArrayList<>();
private ArrayList<ArrayList<Integer>> 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<Integer,Integer> 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<Integer> entryTMP = currentBestLink.keySet();
+
+ int max=currentBestLink.get(entryTMP.iterator().next());
+ int maxId=0;
+ entryTMP = currentBestLink.keySet();
+ Iterator<Integer> 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;
+ }
+
+
+
+
}