Add support for 1 or 2 cells
This commit is contained in:
parent
47755c46b7
commit
519fa92aef
@ -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) {
|
||||||
boolean haveInterference = user1 == user2 && user1 != null;
|
User user2 = cells.get(1).schedule(ticks, ts, (reuse3 ? 50 : 0) + sp);
|
||||||
cell1.consumeResource(ticks, ts, sp, haveInterference);
|
boolean haveInterference = user1 == user2 && user1 != null;
|
||||||
cell2.consumeResource(ticks, ts, sp, haveInterference);
|
int finalTs = ts;
|
||||||
|
int finalSp = sp;
|
||||||
cell1.postScheduling(user1);
|
cells.forEach(c -> c.consumeResource(finalTicks, finalTs, finalSp, haveInterference));
|
||||||
cell2.postScheduling(user2);
|
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
|
// traite les données et les enregistre dans un fichier
|
||||||
try {
|
int finalTicks1 = ticks;
|
||||||
cell1.analyseData(ticks);
|
cells.forEach(c -> {
|
||||||
cell2.analyseData(ticks);
|
try {
|
||||||
} catch (IOException e) {
|
c.analyseData(finalTicks1);
|
||||||
System.out.println("Can't export data");
|
} catch (IOException e) {
|
||||||
}
|
System.err.println("IO Error: " + e.getMessage());
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
||||||
|
Reference in New Issue
Block a user