From d534f3f61b80296c2982b5eec667a6be463f3cc4 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 7 Apr 2023 09:58:54 +0200 Subject: [PATCH] Add interference --- src/main/java/fr/ntr/AccessPoint.java | 14 ++++---------- src/main/java/fr/ntr/Cell.java | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index edd06d7..b6a9672 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -30,11 +30,9 @@ public class AccessPoint { for (int sp = 0; sp < Cell.getSubCarrierNb(); sp++) { User user1 = cell1.schedule(ticks, ts, sp); User user2 = cell2.schedule(ticks, ts, sp); - if(user1 == user2 && user1 != null) { - computeInterference(user1, ts, sp); - } - cell1.consumeResource(ticks, ts, sp); - cell2.consumeResource(ticks, ts, sp); + boolean haveInterference = user1 == user2 && user1 != null; + cell1.consumeResource(ticks, ts, sp, haveInterference); + cell2.consumeResource(ticks, ts, sp, haveInterference); cell1.postScheduling(user1); cell2.postScheduling(user2); @@ -44,15 +42,11 @@ public class AccessPoint { // traite les données et les enregistre dans un fichier try { cell1.analyseData(ticks); - //cell2.analyseData(ticks); + cell2.analyseData(ticks); } catch (IOException e) { System.out.println("Can't export data"); } } } - - private void computeInterference(User user, int ts, int sp) { - - } } diff --git a/src/main/java/fr/ntr/Cell.java b/src/main/java/fr/ntr/Cell.java index 9ba7bb8..f373ed6 100644 --- a/src/main/java/fr/ntr/Cell.java +++ b/src/main/java/fr/ntr/Cell.java @@ -73,11 +73,12 @@ public class Cell { return scheduler.scheduling(tick, ts, sp); } - public void consumeResource(int tick, int ts, int sp) { + public void consumeResource(int tick, int ts, int sp, boolean haveInterference) { ResourceBlock rb = frame[ts][sp]; User user = rb.getUser(); if(user != null && !user.getPacketsToSend().isEmpty()) { Packets p = user.getPacketsToSend().get(0); + rb.setBandwidth(updateBandwidth(haveInterference, rb)); p.decreaseBitsNumberRemaining((int) rb.getBandwidth()); if(p.getBitsNumberRemaining() <= 0) { if(tick == 0){ @@ -91,6 +92,19 @@ public class Cell { } } + private double updateBandwidth(boolean haveInterference, ResourceBlock rb) { + if(haveInterference) { + if(rb.getUser().getDistance() < 200d) { + // User proche + return rb.getBandwidth() / 2; + } + // User loin + return rb.getBandwidth() / 4; + } else { + return rb.getBandwidth(); + } + } + public void analyseData(int tick) throws IOException { double delayAverage = 0.0; int nbPacketsSent = 0;