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;
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<Cell> 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);
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;
cell1.consumeResource(ticks, ts, sp, haveInterference);
cell2.consumeResource(ticks, ts, sp, haveInterference);
cell1.postScheduling(user1);
cell2.postScheduling(user2);
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
int finalTicks1 = ticks;
cells.forEach(c -> {
try {
cell1.analyseData(ticks);
cell2.analyseData(ticks);
c.analyseData(finalTicks1);
} 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);
//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) {