Add DSDV and AODV
This commit is contained in:
parent
3443b5b336
commit
ac6de0d3be
3 changed files with 71 additions and 4 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue