From b073d58f21bee2ddb83d4e40cd02731155ab752f Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 4 Apr 2023 09:27:06 +0200 Subject: [PATCH] Improve pf performances --- src/main/java/fr/ntr/Main.java | 5 +- .../fr/ntr/scheduler/ProportionalFair.java | 52 ++++++++----------- 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index 407ebfe..8431425 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -1,6 +1,7 @@ package fr.ntr; import fr.ntr.scheduler.MaxSNR; +import fr.ntr.scheduler.ProportionalFair; import fr.ntr.scheduler.Scheduler; import java.io.File; @@ -49,8 +50,8 @@ public class Main { for(int i = 2; i <= maximumLoad; i += 2) { List users = generateUsers(i, timeSlotNb, subCarrierNb); ResourceBlock[][] frame = new ResourceBlock[timeSlotNb][subCarrierNb]; - Scheduler scheduler = new MaxSNR(frame, users); - // Scheduler scheduler = new ProportionalFair(frame, users); + // Scheduler scheduler = new MaxSNR(frame, users); + Scheduler scheduler = new ProportionalFair(frame, users); // Scheduler scheduler = new RoundRobin(frame, users); AccessPoint accessPoint = new AccessPoint(scheduler, frame, users); executor.submit(() -> accessPoint.startSimulation(numberOfTicks)); diff --git a/src/main/java/fr/ntr/scheduler/ProportionalFair.java b/src/main/java/fr/ntr/scheduler/ProportionalFair.java index 94e9403..6b33d51 100644 --- a/src/main/java/fr/ntr/scheduler/ProportionalFair.java +++ b/src/main/java/fr/ntr/scheduler/ProportionalFair.java @@ -3,57 +3,51 @@ package fr.ntr.scheduler; import java.util.ArrayList; import java.util.List; +import fr.ntr.AccessPoint; import fr.ntr.ResourceBlock; import fr.ntr.User; public class ProportionalFair extends Scheduler { + private final List users; - private List users; - - private ResourceBlock[][] frame; + private final ResourceBlock[][] frame; public ProportionalFair(ResourceBlock[][] frame, List users) { this.frame = frame; this.users = users; - } - + } + @Override public void scheduling(int ticks) { - ArrayList averageBandwiths = new ArrayList(); - for(User u : users){ - double avg = 0d; - double[][] bandwidthTable = u.getBandwidthTable(); - for(int i = 0; i < bandwidthTable.length; i++){ - for(int j = 0; j < bandwidthTable[i].length; j++){ - avg += bandwidthTable[i][j]; - } - } - avg = avg / (bandwidthTable.length * bandwidthTable[0].length); - averageBandwiths.add(avg); - } - for(int ts = 0; ts < 2; ts++){ - for(int sp = 0; sp < 100; sp++){ - User selectedUser = userSelection(ts, sp, users, averageBandwiths); + for(int ts = 0; ts < AccessPoint.getTimeSlotNb(); ts++){ + for(int sp = 0; sp < AccessPoint.getSubCarrierNb(); sp++){ + User selectedUser = userSelection(ts, sp, users); allocateRessource(selectedUser, frame, ts, sp, ticks); } } } - - private User userSelection(int ts, int sp, List users, List averageBandwiths) { + + private User userSelection(int ts, int sp, List users) { double PF = 0.0; User selectedUser = null; - for(int i = 0; i < users.size(); i++){ - User u = users.get(i); + for (User u : users) { + double avg = 0d; + double[][] bandwidthTable = u.getBandwidthTable(); + for (double[] doubles : bandwidthTable) { + for (double aDouble : doubles) { + avg += aDouble; + } + } + avg = avg / (bandwidthTable.length * bandwidthTable[0].length); double mkn = u.getBandwidthTable()[ts][sp]; - double averageMkn = averageBandwiths.get(i); - double pf = mkn / averageMkn; - if (PF < pf){ + double pf = mkn / avg; + if (PF < pf) { PF = pf; selectedUser = u; } } return selectedUser; - } - + } + }