From b597d6859718a2daaa087f85d8be50d26c6f62c7 Mon Sep 17 00:00:00 2001 From: Remi Boure Date: Fri, 24 Mar 2023 10:31:50 +0100 Subject: [PATCH] PF scheduling --- src/main/java/fr/ntr/Main.java | 4 +- .../fr/ntr/scheduler/ProportionalFair.java | 70 +++++++++++++------ 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index 2bd2327..c6a9662 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.RoundRobin; import fr.ntr.scheduler.Scheduler; @@ -28,7 +29,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 MaxSNR(frame, users); + Scheduler scheduler = new ProportionalFair(frame, users); AccessPoint accessPoint = new AccessPoint(scheduler, frame, users, timeSlotNb, subCarrierNb, 0, 50); accessPoint.startSimulation(numberOfTicks); } diff --git a/src/main/java/fr/ntr/scheduler/ProportionalFair.java b/src/main/java/fr/ntr/scheduler/ProportionalFair.java index 5ffe2fd..4ef2757 100644 --- a/src/main/java/fr/ntr/scheduler/ProportionalFair.java +++ b/src/main/java/fr/ntr/scheduler/ProportionalFair.java @@ -1,33 +1,63 @@ package fr.ntr.scheduler; +import java.util.ArrayList; import java.util.List; +import fr.ntr.ResourceBlock; import fr.ntr.User; public class ProportionalFair extends Scheduler { + private List users; - private String name; - private int index; - - public ProportionalFair(String name, int index) { - this.name = name; - this.index = index; - } - - @Override - public void scheduling() { - } - - private void selectionUtilisateur(int Ts, int Sp, List Users) { - - } + private ResourceBlock[][] frame; - @Override - protected void TraitementDonnees() { - // TODO Auto-generated method stub - + public ProportionalFair(ResourceBlock[][] frame, List users) { + this.frame = frame; + this.users = users; + } + + @Override + public void scheduling() { + 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(new Double(avg)); } - + User selectedUser = null; + for(int ts = 0; ts < 2; ts++){ + for(int sp = 0; sp < 100; sp++){ + selectedUser = selectionUtilisateur(ts, sp, users, averageBandwiths); + if (selectedUser.getPacketsToSend().size() != 0) { + selectedUser.getPacketsSent().add(selectedUser.getPacketsToSend().get(0)); + selectedUser.getPacketsToSend().remove(selectedUser.getPacketsToSend().get(0)); + frame[ts][sp].setUser(selectedUser); + frame[ts][sp].setBandwidth(selectedUser.getBandwidthTable()[ts][sp]); + } + } + } + } + private User selectionUtilisateur(int ts, int sp, List users, List averageBandwiths) { + double PF = 0.0; + User selectedUser = null; + for(int i = 0; i < users.size(); i++){ + User u = users.get(i); + double mkn = u.getBandwidthTable()[ts][sp]; + double averageMkn = averageBandwiths.get(i); + double pf = mkn / averageMkn; + if (PF < pf){ + PF = pf; + selectedUser = u; + } + } + return selectedUser; + } }