This commit is contained in:
Tr1xt4n 2023-03-24 10:37:56 +01:00
commit 2db4e91962
2 changed files with 53 additions and 21 deletions

View File

@ -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<User> 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);
}

View File

@ -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<User> users;
private String name;
private int index;
private ResourceBlock[][] frame;
public ProportionalFair(String name, int index) {
this.name = name;
this.index = index;
public ProportionalFair(ResourceBlock[][] frame, List<User> users) {
this.frame = frame;
this.users = users;
}
@Override
public void scheduling() {
ArrayList<Double> averageBandwiths = new ArrayList<Double>();
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 void selectionUtilisateur(int Ts, int Sp, List<User> Users) {
private User selectionUtilisateur(int ts, int sp, List<User> users, List<Double> 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;
}
@Override
protected void TraitementDonnees() {
// TODO Auto-generated method stub
}
}