diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index 8bac863..fb4d279 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -8,21 +8,17 @@ public class AccessPoint { private final Cell cell1; private final Cell cell2; - private final List cellList; public AccessPoint(Cell cell1, Cell cell2){ this.cell1 = cell1; this.cell2 = cell2; - cellList = new ArrayList<>(); - cellList.add(cell1); - cellList.add(cell2); } /** * Lancer la simulation * @param duration */ - public void startSimulation(int duration, List users) { + public void startSimulation(int duration) { for (int ticks = 0; ticks < duration; ++ticks) { // Simulation cell1.reset(); @@ -35,8 +31,8 @@ public class AccessPoint { // computeInterference(); // traite les données et les enregistre dans un fichier try { - cell1.analyseData(ticks, users); - cell2.analyseData(ticks, users); + cell1.analyseData(ticks); + cell2.analyseData(ticks); } catch (IOException e) { System.out.println("Can't export data"); } diff --git a/src/main/java/fr/ntr/Cell.java b/src/main/java/fr/ntr/Cell.java index 7d1a924..f2cf382 100644 --- a/src/main/java/fr/ntr/Cell.java +++ b/src/main/java/fr/ntr/Cell.java @@ -65,7 +65,7 @@ public class Cell { scheduler.scheduling(tick); } - public void analyseData(int tick, List users) throws IOException { + public void analyseData(int tick) throws IOException { double delayAverage = 0.0; int nbPacketsSent = 0; for(User u: users){ diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index 86dbeed..d2712a0 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -55,19 +55,23 @@ public class Main { Cell.setSubCarrierNb(subCarrierNb); ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); for(int i = 2; i <= maximumLoad; i += 2) { - List users = generateUsers(i, timeSlotNb, subCarrierNb); - ResourceBlock[][] frame = new ResourceBlock[timeSlotNb][subCarrierNb]; + List usersCell1 = generateUsers(i, timeSlotNb, subCarrierNb); + List usersCell2 = generateUsers(i, timeSlotNb, subCarrierNb); + + ResourceBlock[][] frame1 = new ResourceBlock[timeSlotNb][subCarrierNb]; + ResourceBlock[][] frame2 = new ResourceBlock[timeSlotNb][subCarrierNb]; + //TODO : changes schedulers - Scheduler schedulerCell1 = new RoundRobin(frame, users); - Scheduler schedulerCell2 = new RoundRobin(frame, users); + Scheduler schedulerCell1 = new RoundRobin(frame1, frame2, usersCell1); + Scheduler schedulerCell2 = new RoundRobin(frame2, frame1, usersCell2); try{ - FileOutputStream output = new FileOutputStream("export" + File.separator + users.size() + ".csv", true); + FileOutputStream output = new FileOutputStream("export" + File.separator + (usersCell1.size()+usersCell2.size()) + ".csv", true); output.write("tick;x;y;user;bandwidth;delay;cell;\n".getBytes()); - Cell cell1 = new Cell(0, schedulerCell1, frame, users, output); - Cell cell2 = new Cell(1, schedulerCell2, frame, users, output); + Cell cell1 = new Cell(0, schedulerCell1, frame1, usersCell1, output); + Cell cell2 = new Cell(1, schedulerCell2, frame2, usersCell2, output); AccessPoint accessPoint = new AccessPoint(cell1, cell2); - executor.submit(() -> accessPoint.startSimulation(numberOfTicks, users)); + executor.submit(() -> accessPoint.startSimulation(numberOfTicks)); } catch(IOException e) { System.err.println(e.getClass().getSimpleName() + " : " + e.getMessage()); System.exit(1); @@ -90,7 +94,7 @@ public class Main { private static List generateUsers(int nbUsers, int timeSlotNb, int subCarrierNb) { List users = new ArrayList<>(); // 2 groupes d'utilisateurs, proches et éloignés - double[] distance = { 200d, 400d }; + double[] distance = { 150d, 500d }; for (double v : distance) { for (int j = 0; j < nbUsers; j++) { User user = new User(v, timeSlotNb, subCarrierNb); diff --git a/src/main/java/fr/ntr/scheduler/MaxSNR.java b/src/main/java/fr/ntr/scheduler/MaxSNR.java index 9a8ab40..4d240e2 100644 --- a/src/main/java/fr/ntr/scheduler/MaxSNR.java +++ b/src/main/java/fr/ntr/scheduler/MaxSNR.java @@ -7,10 +7,12 @@ import fr.ntr.User; public class MaxSNR extends Scheduler { private final List users; - private final ResourceBlock[][] frame; + private final ResourceBlock[][] myFrame; + private final ResourceBlock[][] neighborFrame; - public MaxSNR( ResourceBlock[][] frame, List users) { - this.frame = frame; + public MaxSNR(ResourceBlock[][] myFrame, ResourceBlock[][] neighborFrame, List users) { + this.myFrame = myFrame; + this.neighborFrame = neighborFrame; this.users = users; } @@ -20,7 +22,14 @@ public class MaxSNR extends Scheduler { for(int ts = 0; ts < 2; ts++){ for(int sp = 0; sp < 100; sp++){ userMax = userSelection(ts, sp); - allocateRessource(userMax, frame, ts, sp, ticks); + allocateRessource(userMax, myFrame, neighborFrame, ts, sp, ticks); + } + } + + for(int ts = 0; ts < 2; ts++){ + for(int sp = 0; sp < 100; sp++){ + userMax = userSelection(ts, sp); + allocateRessource(userMax, myFrame, neighborFrame, ts, sp, ticks); } } } diff --git a/src/main/java/fr/ntr/scheduler/ProportionalFair.java b/src/main/java/fr/ntr/scheduler/ProportionalFair.java index 6865746..2d7f8bc 100644 --- a/src/main/java/fr/ntr/scheduler/ProportionalFair.java +++ b/src/main/java/fr/ntr/scheduler/ProportionalFair.java @@ -11,10 +11,12 @@ public class ProportionalFair extends Scheduler { private final List users; - private final ResourceBlock[][] frame; + private final ResourceBlock[][] myFrame; + private final ResourceBlock[][] neighborFrame; - public ProportionalFair(ResourceBlock[][] frame, List users) { - this.frame = frame; + public ProportionalFair(ResourceBlock[][] myFrame, ResourceBlock[][] neighborFrame, List users) { + this.myFrame = myFrame; + this.neighborFrame = neighborFrame; this.users = users; } @@ -35,7 +37,7 @@ public class ProportionalFair extends Scheduler { for(int ts = 0; ts < 2; ts++){ for(int sp = 0; sp < 100; sp++){ User selectedUser = userSelection(ts, sp, users, averageBandwiths); - allocateRessource(selectedUser, frame, ts, sp, ticks); + allocateRessource(selectedUser, myFrame, neighborFrame, ts, sp, ticks); } } } diff --git a/src/main/java/fr/ntr/scheduler/RoundRobin.java b/src/main/java/fr/ntr/scheduler/RoundRobin.java index aeadccb..f34aa42 100644 --- a/src/main/java/fr/ntr/scheduler/RoundRobin.java +++ b/src/main/java/fr/ntr/scheduler/RoundRobin.java @@ -11,10 +11,13 @@ import fr.ntr.User; public class RoundRobin extends Scheduler { private final List users; - private final ResourceBlock[][] frame; + private final ResourceBlock[][] myFrame; + private final ResourceBlock[][] neighborFrame; - public RoundRobin(ResourceBlock[][] frame, List users) { - this.frame = frame; + + public RoundRobin(ResourceBlock[][] myFrame, ResourceBlock[][] neighborFrame, List users) { + this.myFrame = myFrame; + this.neighborFrame = neighborFrame; this.users = users; } @@ -35,7 +38,7 @@ public class RoundRobin extends Scheduler { break loop; } User userSelected = userSelection(userCopy); - allocateRessource(userSelected, frame, ts, sp, ticks); + allocateRessource(userSelected, myFrame, neighborFrame, ts, sp, ticks); if(!userSelected.getPacketsToSend().isEmpty()) userCopy.add(userSelected); } diff --git a/src/main/java/fr/ntr/scheduler/Scheduler.java b/src/main/java/fr/ntr/scheduler/Scheduler.java index 29e2fe6..066d506 100644 --- a/src/main/java/fr/ntr/scheduler/Scheduler.java +++ b/src/main/java/fr/ntr/scheduler/Scheduler.java @@ -13,8 +13,25 @@ public abstract class Scheduler { */ public abstract void scheduling(int ticks); - protected void allocateRessource(User userMax, ResourceBlock[][] frame, int ts, int sp, int ticks) { + protected void allocateRessource(User userMax, ResourceBlock[][] myFrame, ResourceBlock[][] neighborFrame, int ts, int sp, int ticks) { + ResourceBlock rb1 = myFrame[ts][sp]; + ResourceBlock rb2 = neighborFrame[ts][sp]; if (userMax != null && !userMax.getPacketsToSend().isEmpty()) { + User user2 = rb2.getUser(); + if ((userMax != null || user2 != null) && userMax == user2) { + double bandwidth1 = rb1.getBandwidth(); + double bandwidth2 = rb2.getBandwidth(); + //User proche + if (userMax.getDistance() < 200d) { + rb1.getUser().getBandwidthTable()[ts][sp] = bandwidth1 / 2; + rb2.getUser().getBandwidthTable()[ts][sp] = bandwidth2 / 2; + } + //User loin + else { + rb1.getUser().getBandwidthTable()[ts][sp] = bandwidth1 / 4; + rb2.getUser().getBandwidthTable()[ts][sp] = bandwidth2 / 4; + } + } Packets p = userMax.getPacketsToSend().get(userMax.getPacketsToSend().size()-1); if(p.getBitsNumberRemaining() >= 0){ p.decreaseBitsNumberRemaining((int) userMax.getBandwidthTable()[ts][sp]); @@ -36,8 +53,8 @@ public abstract class Scheduler { userMax.getPacketsSent().add(p); userMax.getPacketsToSend().remove(p); } - frame[ts][sp].setUser(userMax); - frame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]); + myFrame[ts][sp].setUser(userMax); + myFrame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]); } } } \ No newline at end of file