diff options
| author | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2016-03-21 21:03:28 +0100 |
|---|---|---|
| committer | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2016-03-21 21:03:28 +0100 |
| commit | 7f3a91e6dcbc8277613db6e21b2fd11b344f7a19 (patch) | |
| tree | 7515903dcc90342ae97ac01cbcbd4aa9c23ac09f | |
| parent | ac6de0d3bed1d9849addf0ffd8700721fa8d7580 (diff) | |
Add custom protocol
| -rw-r--r-- | main/Main.java | 2 | ||||
| -rw-r--r-- | structure/Graph.java | 2 | ||||
| -rw-r--r-- | structure/Grid.java | 23 |
3 files changed, 20 insertions, 7 deletions
diff --git a/main/Main.java b/main/Main.java index f8941e6..c1f2693 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.Protocol.DSDV); + Grid g=new Grid(Grid.Protocol.CUSTOM); MyGraph gr=new MyGraph("Routage Oportuniste", g); diff --git a/structure/Graph.java b/structure/Graph.java index b1c786d..1c2dc0f 100644 --- a/structure/Graph.java +++ b/structure/Graph.java @@ -153,7 +153,7 @@ public class MyGraph extends SingleGraph{ else{ this.miss++; } - System.out.println("Success = " + this.success + " Miss = " + this.miss); + System.out.println("Success = " + this.success + " Miss = " + this.miss + " try number :"+(this.success+this.miss)) ; //Build bestLink this.showBestLink(); diff --git a/structure/Grid.java b/structure/Grid.java index d075196..e929f5d 100644 --- a/structure/Grid.java +++ b/structure/Grid.java @@ -6,14 +6,15 @@ import java.util.Map.Entry; public class Grid { public enum Protocol { - AODV, DSDV + AODV, DSDV, CUSTOM } private ArrayList<Router> grid=new ArrayList<>(); private ArrayList<ArrayList<Integer>> links=new ArrayList<>(); private int bestLinkByProtocol; - + private Protocol protocolChoose; + private int counterCUSTOM=5; private Random rand = new Random(); private final int maxWeight=100; @@ -31,13 +32,14 @@ public class Grid { this.buildRandomLink(); this.buildLinks(); - + this.protocolChoose=protocol; + switch(protocol){ case AODV: this.bestLinkByProtocol=this.getBestLinkIndex(); break; - case DSDV: - + case DSDV: + case CUSTOM: HashMap<Integer,Integer> currentBestLink=new HashMap<>(); for(int i=0;i<10000;i++){ int current=this.getBestLinkIndex(); @@ -69,7 +71,10 @@ public class Grid { this.bestLinkByProtocol=maxId; System.out.println("Retenu :"+maxId); break; + + } + } @@ -269,6 +274,14 @@ public class Grid { * @return the bestLinkByProtocol */ public int getBestLinkByProtocol() { + if(this.protocolChoose==Protocol.CUSTOM){ + this.counterCUSTOM--; + if(this.counterCUSTOM==0){ + this.bestLinkByProtocol=this.getBestLinkIndex(); + this.counterCUSTOM=5; + } + + } return bestLinkByProtocol; } |
