Add support for 1 or 2 cells

This commit is contained in:
Quentin Legot 2023-04-13 11:54:34 +02:00
parent 47755c46b7
commit 519fa92aef
2 changed files with 34 additions and 29 deletions

View File

@ -1,17 +1,18 @@
package fr.ntr; package fr.ntr;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.List;
public class AccessPoint { public class AccessPoint {
private final Cell cell1; private final List<Cell> cells;
private final Cell cell2;
private final boolean reuse3 = false; private final boolean reuse3;
public AccessPoint (Cell cell1, Cell cell2){ public AccessPoint (boolean reuse3, Cell... cells){
this.cell1 = cell1; this.reuse3 = reuse3;
this.cell2 = cell2; this.cells = Arrays.stream(cells).toList();
} }
/** /**
@ -21,35 +22,39 @@ public class AccessPoint {
public void startSimulation (int duration) { public void startSimulation (int duration) {
for (int ticks = 0; ticks < duration; ++ticks) { for (int ticks = 0; ticks < duration; ++ticks) {
// Simulation // Simulation
cell1.reset(); cells.forEach(Cell::reset);
cell2.reset();
cell1.updateBandwidth(ticks); int finalTicks = ticks;
cell2.updateBandwidth(ticks); cells.forEach(c -> c.updateBandwidth(finalTicks));
cell1.preScheduling(); cells.forEach(Cell::preScheduling);
cell2.preScheduling();
for(int ts = 0; ts < Cell.getTimeSlotNb(); ts++) { for(int ts = 0; ts < Cell.getTimeSlotNb(); ts++) {
for (int sp = 0; sp < (reuse3 ? Cell.getSubCarrierNb() / 2 : Cell.getSubCarrierNb()); sp++) { for (int sp = 0; sp < (reuse3 ? Cell.getSubCarrierNb() / 2 : Cell.getSubCarrierNb()); sp++) {
User user1 = cell1.schedule(ticks, ts, sp); User user1 = cells.get(0).schedule(ticks, ts, sp);
User user2 = cell2.schedule(ticks, ts, (reuse3 ? 50 : 0) + sp); if(cells.size() > 1) {
User user2 = cells.get(1).schedule(ticks, ts, (reuse3 ? 50 : 0) + sp);
boolean haveInterference = user1 == user2 && user1 != null; boolean haveInterference = user1 == user2 && user1 != null;
cell1.consumeResource(ticks, ts, sp, haveInterference); int finalTs = ts;
cell2.consumeResource(ticks, ts, sp, haveInterference); int finalSp = sp;
cells.forEach(c -> c.consumeResource(finalTicks, finalTs, finalSp, haveInterference));
cell1.postScheduling(user1); cells.get(0).postScheduling(user1);
cell2.postScheduling(user2); 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 // traite les données et les enregistre dans un fichier
int finalTicks1 = ticks;
cells.forEach(c -> {
try { try {
cell1.analyseData(ticks); c.analyseData(finalTicks1);
cell2.analyseData(ticks);
} catch (IOException e) { } catch (IOException e) {
System.out.println("Can't export data"); System.err.println("IO Error: " + e.getMessage());
System.exit(1);
} }
});
} }
} }
} }

View File

@ -95,7 +95,7 @@ public class Main {
Cell cell2 = new Cell(1, schedulerCell2, frame2, usersCell2, output); Cell cell2 = new Cell(1, schedulerCell2, frame2, usersCell2, output);
//création de l'AccessPoint //création de l'AccessPoint
AccessPoint accessPoint = new AccessPoint(cell1, cell2); AccessPoint accessPoint = new AccessPoint(false, cell1, cell2);
executor.submit(() -> accessPoint.startSimulation(numberOfTicks)); executor.submit(() -> accessPoint.startSimulation(numberOfTicks));
} }
catch (IOException e) { catch (IOException e) {