diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index c41edcf..b5a6b2c 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -1,5 +1,8 @@ package fr.ntr; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -31,12 +34,14 @@ public class AccessPoint { private final double min, max; - public AccessPoint(Scheduler scheduler, double min, double max) { + public AccessPoint(Scheduler scheduler, ResourceBlock[][] frame, List users, int timeSlotNb, int subCarrierNb, double min, double max) { this.min = min; this.max = max; - this.users = new ArrayList<>(); + this.users = users; this.scheduler = scheduler; - this.frame = new ResourceBlock[timeSlotNb][subCarrierNb]; + this.frame = frame; + this.timeSlotNb = timeSlotNb; + this.subCarrierNb = subCarrierNb; } /** @@ -44,30 +49,34 @@ public class AccessPoint { * @param duration */ public void startSimulation(int duration, int nbUsers) { - init(nbUsers); for (int ticks = 0; ticks < duration; ++ticks) { // Simulation reset(); updateBandwidth(ticks); schedule(); // traite les données et les enregistre dans un fichier - analyseData(); + try { + analyseData(); + } catch (IOException e) { + System.out.println("Can't export data"); + } } } private void updateBandwidth(int ticks) { int n = 200; - int timeInterval = 50 + new Random().nextInt(50); + Random random = new Random(); + int timeInterval = 50 + random.nextInt(51); for(User user : users) { - // On regénère le tableau de débits toutes les 50 ms + // On régénère le tableau de débits toutes les 50 ms if(ticks % 50 == 0){ user.generateBandwidth(); } - // On regénère les sources toutes les 50-100 ms + // On régénère les sources toutes les 50-100 ms if(ticks % timeInterval == 0){ + timeInterval = 50 + random.nextInt(51); n = user.createPackets(n, ticks); - timeInterval = 50 + new Random().nextInt(51); } } } @@ -90,8 +99,17 @@ public class AccessPoint { scheduler.scheduling(); } - private void analyseData() { - + private void analyseData() throws IOException { + try(FileOutputStream file = new FileOutputStream("data.csv", true)) { + for(int i = 0; i < frame.length; i++) { + for(int j = 0; j < frame[i].length; j++) { + ResourceBlock ur = frame[i][j]; + String data = (i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";\n"); + System.out.println("data: " + data); + file.write(data.getBytes()); + } + } + } } private void plotData() { @@ -99,7 +117,6 @@ public class AccessPoint { } private void reset() { - this.users = new ArrayList<>(); this.frame = new ResourceBlock[timeSlotNb][subCarrierNb]; } diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index 3796cd7..70ae2e5 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -1,11 +1,14 @@ package fr.ntr; import fr.ntr.scheduler.RoundRobin; +import fr.ntr.scheduler.Scheduler; + +import java.util.ArrayList; +import java.util.List; public class Main { public static void main(String[] args) { - //TODO ajouter accès à AccessPoint if(args.length == 2) { int numberOfTicks; // Nombre de ticks de la simulation -> durée de la simulation @@ -19,13 +22,31 @@ public class Main { System.exit(1); return; } - - AccessPoint accessPoint = new AccessPoint(new RoundRobin("round robin", 0), 0, 50); + int timeSlotNb = 2; + int subCarrierNb = 100; + List users = generateUsers(20, timeSlotNb, subCarrierNb); + ResourceBlock[][] frame = new ResourceBlock[timeSlotNb][subCarrierNb]; + Scheduler scheduler = new RoundRobin("round robin", 0, frame, users); + AccessPoint accessPoint = new AccessPoint(scheduler, frame, users, timeSlotNb, subCarrierNb, 0, 50); accessPoint.startSimulation(numberOfTicks, maximumLoad); - } else { + } + else { System.err.println("Please give launch arguments"); System.err.println("gradle run --args=\" \""); System.exit(1); } } + + private static List generateUsers(int nbUsers, int timeSlotNb, int subCarrierNb) { + List users = new ArrayList<>(); + // 2 groupes d'utilisateurs, proches et éloignés + double[] distance = { 200d, 1000d }; + for (double v : distance) { + for (int j = 0; j < nbUsers; j++) { + User user = new User(v, timeSlotNb, subCarrierNb); + users.add(user); + } + } + return users; + } } \ No newline at end of file diff --git a/src/main/java/fr/ntr/ResourceBlock.java b/src/main/java/fr/ntr/ResourceBlock.java index 588e40e..4fcc575 100644 --- a/src/main/java/fr/ntr/ResourceBlock.java +++ b/src/main/java/fr/ntr/ResourceBlock.java @@ -2,18 +2,26 @@ package fr.ntr; public class ResourceBlock { private User user; - private double bandwith; + private double bandwidth; - public ResourceBlock (User user, double bandwith) { + public ResourceBlock (User user, double bandwidth) { this.user = user; - this.bandwith = bandwith; + this.bandwidth = bandwidth; } public void setUser(User user) { this.user = user; } - public void setBandwith(double bandwith) { - this.bandwith = bandwith; + public void setBandwidth(double bandwidth) { + this.bandwidth = bandwidth; + } + + public User getUser() { + return user; + } + + public double getBandwidth() { + return bandwidth; } } diff --git a/src/main/java/fr/ntr/scheduler/MaxSNR.java b/src/main/java/fr/ntr/scheduler/MaxSNR.java index c346bfd..9b7fd3a 100644 --- a/src/main/java/fr/ntr/scheduler/MaxSNR.java +++ b/src/main/java/fr/ntr/scheduler/MaxSNR.java @@ -1,18 +1,27 @@ package fr.ntr.scheduler; import java.util.List; +import fr.ntr.ResourceBlock; import fr.ntr.User; public class MaxSNR extends Scheduler { private List users; + private ResourceBlock[][] frame; + @Override public void scheduling() { User userMax = null; for(int ts = 0; ts < 2; ts++){ for(int sp = 0; sp < 100; sp++){ userMax = selectionUtilisateur(sp, ts, users); + userMax.getPacketsSent().add(userMax.getPacketsToSend().get(0)); + userMax.getPacketsToSend().remove(userMax.getPacketsToSend().get(0)); + frame[ts][sp].setUser(selectionUtilisateur(sp, ts, users)); + if (userMax.getPacketsToSend() == null) { + users.remove(userMax); + } } } } diff --git a/src/main/java/fr/ntr/scheduler/ProportionalFair.java b/src/main/java/fr/ntr/scheduler/ProportionalFair.java index 1e0b650..5ffe2fd 100644 --- a/src/main/java/fr/ntr/scheduler/ProportionalFair.java +++ b/src/main/java/fr/ntr/scheduler/ProportionalFair.java @@ -23,7 +23,7 @@ public class ProportionalFair extends Scheduler { } @Override - protected void TraitementDonnées() { + protected void TraitementDonnees() { // TODO Auto-generated method stub } diff --git a/src/main/java/fr/ntr/scheduler/RoundRobin.java b/src/main/java/fr/ntr/scheduler/RoundRobin.java index 2e806fe..e6f4020 100644 --- a/src/main/java/fr/ntr/scheduler/RoundRobin.java +++ b/src/main/java/fr/ntr/scheduler/RoundRobin.java @@ -15,9 +15,11 @@ public class RoundRobin extends Scheduler { private List users; private ResourceBlock[][] frame; - public RoundRobin(String name, int index) { + public RoundRobin(String name, int index, ResourceBlock[][] frame, List users) { this.name = name; this.index = index; + this.frame = frame; + this.users = users; } /** @@ -29,20 +31,21 @@ public class RoundRobin extends Scheduler { public void scheduling() { //selection aleatoire du premier utilisateur Random random = new Random(); - index = random.nextInt(users.size()-1); + index = random.nextInt(users.size()); //Pour chaque time slot et sous porteuses for (int Ts = 0; Ts < AccessPoint.getTimeSlotNb(); Ts++) { for(int Sp = 0; Sp < AccessPoint.getSubCarrierNb(); Sp++) { + // on enlève le packet transmis de la liste + // TODO Verify sub the packet send need Set packet + users.get(index).getPacketsSent().add(users.get(index).getPacketsToSend().get(0)); + users.get(index).getPacketsToSend().remove(users.get(index).getPacketsToSend().get(0)); + //on ajoute l'utilisateur a la frame + frame[Ts][Sp].setUser(UserSelection(Ts, Sp, users)); + //si un utilisateur n'a plus de packet a transmettre on supprime l'utilisateur de la liste if (users.get(index).getPacketsToSend() == null) { users.remove(index); - }else{ - - //sub the packet send need Set packet - users.get(index).getPacketsToSend(); } - frame[Ts][Sp].setUser(UserSelection(Ts, Sp, users)); - } } } @@ -52,12 +55,13 @@ public class RoundRobin extends Scheduler { * Return the user in function of TS and SP selected */ private User UserSelection(int Ts, int Sp, List users) { - + //compte le nombre de bloc attribue for (int i = 0; i < Ts; i++){ for (int j = 0; j < Sp; j++) { index++; } } + //on retourne l'utilisateur return users.get(index%(users.size() - 1)); } diff --git a/src/main/java/fr/ntr/scheduler/Scheduler.java b/src/main/java/fr/ntr/scheduler/Scheduler.java index c7c1137..e21432d 100644 --- a/src/main/java/fr/ntr/scheduler/Scheduler.java +++ b/src/main/java/fr/ntr/scheduler/Scheduler.java @@ -8,7 +8,7 @@ public abstract class Scheduler { * Return */ public abstract void scheduling(); - protected void TraitementDonnées() { + protected void TraitementDonnees() { } }