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 grid=new ArrayList<>(); private ArrayList> 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 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; }