From c7e2fed18823869b39efed4f410ad97aa491c30a Mon Sep 17 00:00:00 2001 From: Loris Date: Fri, 17 Mar 2023 11:11:26 +0100 Subject: [PATCH] Moved User generation in Main class --- src/main/java/fr/ntr/AccessPoint.java | 19 ++----------------- src/main/java/fr/ntr/Main.java | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index 8afa8d7..afcc157 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -34,10 +34,10 @@ public class AccessPoint { private final double min, max; - public AccessPoint(Scheduler scheduler, ResourceBlock[][] frame, int timeSlotNb, int subCarrierNb, 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 = frame; this.timeSlotNb = timeSlotNb; @@ -49,7 +49,6 @@ public class AccessPoint { * @param duration */ public void startSimulation(int duration, int nbUsers) { - init(nbUsers); for (int ticks = 0; ticks < duration; ++ticks) { // Simulation reset(); @@ -82,20 +81,6 @@ public class AccessPoint { } } - /** - * Génération du débit et des paquets - */ - private void init(int nbUsers) { - // 2 groupes d'utilisateurs, proches et éloignés - double[] distance = { 200d, 1000d }; - for (int i = 0; i < distance.length; i++) { - for(int j = 0; j < nbUsers; j++){ - User user = new User(distance[i], timeSlotNb, subCarrierNb); - this.users.add(user); - } - } - } - private void schedule() { scheduler.scheduling(); } diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index e72e29d..eb99408 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -3,6 +3,9 @@ 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) { @@ -22,14 +25,30 @@ public class Main { //TODO : change timeSlotNb and subCarrierNb int timeSlotNb = 0; int subCarrierNb = 0; + List users = generateUsers(20, timeSlotNb, subCarrierNb); + //TODO : generate users 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 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 (int i = 0; i < distance.length; i++) { + for(int j = 0; j < nbUsers; j++){ + User user = new User(distance[i], timeSlotNb, subCarrierNb); + users.add(user); + } + } + return users; + } } \ No newline at end of file