From 519fa92aefa84444ccf1f806e92b432f6dd58e2c Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 13 Apr 2023 11:54:34 +0200 Subject: [PATCH] Add support for 1 or 2 cells --- src/main/java/fr/ntr/AccessPoint.java | 61 +++++++++++++++------------ src/main/java/fr/ntr/Main.java | 2 +- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index d5ded6d..f925f69 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -1,17 +1,18 @@ package fr.ntr; import java.io.IOException; +import java.util.Arrays; +import java.util.List; public class AccessPoint { - private final Cell cell1; - private final Cell cell2; + private final List cells; - private final boolean reuse3 = false; + private final boolean reuse3; - public AccessPoint (Cell cell1, Cell cell2){ - this.cell1 = cell1; - this.cell2 = cell2; + public AccessPoint (boolean reuse3, Cell... cells){ + this.reuse3 = reuse3; + this.cells = Arrays.stream(cells).toList(); } /** @@ -21,35 +22,39 @@ public class AccessPoint { public void startSimulation (int duration) { for (int ticks = 0; ticks < duration; ++ticks) { // Simulation - cell1.reset(); - cell2.reset(); + cells.forEach(Cell::reset); - cell1.updateBandwidth(ticks); - cell2.updateBandwidth(ticks); - cell1.preScheduling(); - cell2.preScheduling(); + int finalTicks = ticks; + cells.forEach(c -> c.updateBandwidth(finalTicks)); + cells.forEach(Cell::preScheduling); for(int ts = 0; ts < Cell.getTimeSlotNb(); ts++) { for (int sp = 0; sp < (reuse3 ? Cell.getSubCarrierNb() / 2 : Cell.getSubCarrierNb()); sp++) { - User user1 = cell1.schedule(ticks, ts, sp); - User user2 = cell2.schedule(ticks, ts, (reuse3 ? 50 : 0) + 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); - + User user1 = cells.get(0).schedule(ticks, ts, sp); + if(cells.size() > 1) { + User user2 = cells.get(1).schedule(ticks, ts, (reuse3 ? 50 : 0) + sp); + boolean haveInterference = user1 == user2 && user1 != null; + int finalTs = ts; + int finalSp = sp; + cells.forEach(c -> c.consumeResource(finalTicks, finalTs, finalSp, haveInterference)); + cells.get(0).postScheduling(user1); + cells.get(1).postScheduling(user2); + } else { + cells.get(0).consumeResource(ticks, ts, sp, false); + cells.get(0).postScheduling(user1); + } } } // traite les données et les enregistre dans un fichier - try { - cell1.analyseData(ticks); - cell2.analyseData(ticks); - } catch (IOException e) { - System.out.println("Can't export data"); - } - + int finalTicks1 = ticks; + cells.forEach(c -> { + try { + c.analyseData(finalTicks1); + } catch (IOException e) { + System.err.println("IO Error: " + e.getMessage()); + System.exit(1); + } + }); } } } diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index 1af9f89..288c8e3 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -95,7 +95,7 @@ public class Main { Cell cell2 = new Cell(1, schedulerCell2, frame2, usersCell2, output); //création de l'AccessPoint - AccessPoint accessPoint = new AccessPoint(cell1, cell2); + AccessPoint accessPoint = new AccessPoint(false, cell1, cell2); executor.submit(() -> accessPoint.startSimulation(numberOfTicks)); } catch (IOException e) {