aboutsummaryrefslogtreecommitdiff
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
parent3443b5b3367da1a31be4f594fda9c58abbbca605 (diff)
Add DSDV and AODV
-rw-r--r--main/Main.java2
-rw-r--r--structure/Graph.java13
-rw-r--r--structure/Grid.java60
3 files changed, 71 insertions, 4 deletions
diff --git a/main/Main.java b/main/Main.java
index fc84e86..f8941e6 100644
--- a/main/Main.java
+++ b/main/Main.java
@@ -19,7 +19,7 @@ import structure.Router;
public class Main {
public static void main(String[] args) {
- Grid g=new Grid();
+ Grid g=new Grid(Grid.Protocol.DSDV);
MyGraph gr=new MyGraph("Routage Oportuniste", g);
diff --git a/structure/Graph.java b/structure/Graph.java
index fde99f8..b1c786d 100644
--- a/structure/Graph.java
+++ b/structure/Graph.java
@@ -16,6 +16,9 @@ public class MyGraph extends SingleGraph{
private Grid grid;
+ private int miss=0;
+ private int success=0;
+
public MyGraph(String title, Grid grid) {
super(title);
// Allow CSS on view
@@ -92,7 +95,7 @@ public class MyGraph extends SingleGraph{
}
public void showBestLink(){
- ArrayList<Integer> bestLink=this.grid.getLinks().get(this.grid.getBestLinkIndex());
+ ArrayList<Integer> bestLink=this.grid.getLinks().get(this.grid.getBestLinkByProtocol());
for(int i=0;i<bestLink.size();i++){
Iterator<Node> nodes= this.getNodeIterator();
while(nodes.hasNext()){
@@ -144,6 +147,14 @@ public class MyGraph extends SingleGraph{
}
+ if(this.grid.getBestLinkByProtocol()==this.grid.getBestLinkIndex()){
+ this.success++;
+ }
+ else{
+ this.miss++;
+ }
+ System.out.println("Success = " + this.success + " Miss = " + this.miss);
+
//Build bestLink
this.showBestLink();
}
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;
+ }
+
+
+
+
}