diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index 01ac564..8592b0f 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -31,12 +31,14 @@ public class AccessPoint { private final double min, max; - public AccessPoint(Scheduler scheduler, double min, double max) { + public AccessPoint(Scheduler scheduler, ResourceBlock[][] frame, int timeSlotNb, int subCarrierNb, double min, double max) { this.min = min; this.max = max; this.users = new ArrayList<>(); this.scheduler = scheduler; - this.frame = new ResourceBlock[timeSlotNb][subCarrierNb]; + this.frame = frame; + this.timeSlotNb = timeSlotNb; + this.subCarrierNb = subCarrierNb; } /** @@ -57,17 +59,18 @@ public class AccessPoint { 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){ n = user.createPackets(n); - timeInterval = 50 + new Random().nextInt(51); + timeInterval = 50 + random.nextInt(51); } } } diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index 3796cd7..e72e29d 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -1,11 +1,11 @@ package fr.ntr; import fr.ntr.scheduler.RoundRobin; +import fr.ntr.scheduler.Scheduler; 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,8 +19,12 @@ public class Main { System.exit(1); return; } - - AccessPoint accessPoint = new AccessPoint(new RoundRobin("round robin", 0), 0, 50); + //TODO : change timeSlotNb and subCarrierNb + int timeSlotNb = 0; + int subCarrierNb = 0; + ResourceBlock[][] frame = new ResourceBlock[timeSlotNb][subCarrierNb]; + Scheduler scheduler = new RoundRobin("round robin", 0, frame); + AccessPoint accessPoint = new AccessPoint(scheduler, frame, timeSlotNb, subCarrierNb, 0, 50); accessPoint.startSimulation(numberOfTicks, maximumLoad); } else { System.err.println("Please give launch arguments"); diff --git a/src/main/java/fr/ntr/User.java b/src/main/java/fr/ntr/User.java index 8d62352..84861da 100644 --- a/src/main/java/fr/ntr/User.java +++ b/src/main/java/fr/ntr/User.java @@ -35,11 +35,11 @@ public class User { public int createPackets(int m) { Random random = new Random(); - int mbis = (int) random.nextDouble() * (2 * m); + int mbis = random.nextInt(2 * m); int nbPacketsToSend = mbis / Packets.packetSize; this.leftForNextSource = mbis % Packets.packetSize; for(int i = 0; i < nbPacketsToSend; i++){ - this.packetsToSend.add(new Packets(i, i, i)); // Voir pour les valeurs du contructeur Packets + this.packetsToSend.add(new Packets(i, i, i)); // Voir pour les valeurs du constructeur Packets } return mbis; } diff --git a/src/main/java/fr/ntr/scheduler/MaxSNR.java b/src/main/java/fr/ntr/scheduler/MaxSNR.java index c346bfd..0fc7211 100644 --- a/src/main/java/fr/ntr/scheduler/MaxSNR.java +++ b/src/main/java/fr/ntr/scheduler/MaxSNR.java @@ -1,18 +1,28 @@ 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); + if (userMax.getPacketsToSend() == null) { + users.remove(userMax); + }else{ + //sub the packet send need Set packet + userMax.getPacketsToSend(); + } + frame[ts][sp].setUser(selectionUtilisateur(sp, ts, users)); } } } diff --git a/src/main/java/fr/ntr/scheduler/RoundRobin.java b/src/main/java/fr/ntr/scheduler/RoundRobin.java index f803b03..b70b8ed 100644 --- a/src/main/java/fr/ntr/scheduler/RoundRobin.java +++ b/src/main/java/fr/ntr/scheduler/RoundRobin.java @@ -15,9 +15,10 @@ 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) { this.name = name; this.index = index; + this.frame = frame; } /**