From 590f0e49b92d85e8982ed7fbc34d575f117497e8 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 17 Mar 2023 12:08:19 +0100 Subject: [PATCH] Fix analyzeData and createPackets --- .gitignore | 3 ++- src/main/java/fr/ntr/AccessPoint.java | 6 +++++- src/main/java/fr/ntr/ResourceBlock.java | 4 ++++ src/main/java/fr/ntr/User.java | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 0fb3dc0..5da58cd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ build bin/ .idea -.project \ No newline at end of file +.project +data.csv \ No newline at end of file diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index cfdb28f..ff482dc 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -106,7 +106,6 @@ public class AccessPoint { 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()); } } @@ -119,6 +118,11 @@ public class AccessPoint { private void reset() { // TODO insert new UR + for(int i = 0; i < timeSlotNb; i++) { + for(int j = 0; j < subCarrierNb; j++) { + frame[i][j] = new ResourceBlock(0); + } + } } public int getFrameSize() { diff --git a/src/main/java/fr/ntr/ResourceBlock.java b/src/main/java/fr/ntr/ResourceBlock.java index 4fcc575..a26fdfb 100644 --- a/src/main/java/fr/ntr/ResourceBlock.java +++ b/src/main/java/fr/ntr/ResourceBlock.java @@ -5,7 +5,11 @@ public class ResourceBlock { private double bandwidth; public ResourceBlock (User user, double bandwidth) { + this(bandwidth); this.user = user; + } + + public ResourceBlock(double bandwidth) { this.bandwidth = bandwidth; } diff --git a/src/main/java/fr/ntr/User.java b/src/main/java/fr/ntr/User.java index dce601b..4375b56 100644 --- a/src/main/java/fr/ntr/User.java +++ b/src/main/java/fr/ntr/User.java @@ -44,7 +44,7 @@ public class User { public int createPackets(int m, int ticks) { Random random = new Random(); // On tire un nombre entre 0 et 2 * m - int mbis = random.nextInt(2 * (m + this.leftForNextSource)); + int mbis = m == 0 ? 0 : random.nextInt(2 * (m + this.leftForNextSource)); // On calcule le nombre de paquets qu'on peut transmettre int nbPacketsToSend = mbis / Packets.packetSize; // On conserve le nombre de bits restants pour la prochaine génération