Merge branch 'master' of https://gitlab.istic.univ-rennes1.fr/18008147/ntr
This commit is contained in:
commit
376c76b17c
@ -1,6 +1,7 @@
|
||||
package fr.ntr;
|
||||
|
||||
import fr.ntr.scheduler.RoundRobin;
|
||||
import fr.ntr.scheduler.MaxSNR;
|
||||
import fr.ntr.scheduler.ProportionalFair;
|
||||
import fr.ntr.scheduler.Scheduler;
|
||||
|
||||
import java.io.File;
|
||||
@ -10,6 +11,7 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Main {
|
||||
|
||||
@ -44,16 +46,23 @@ public class Main {
|
||||
});
|
||||
AccessPoint.setTimeSlotNb(timeSlotNb);
|
||||
AccessPoint.setSubCarrierNb(subCarrierNb);
|
||||
try(ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())) {
|
||||
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 ProportionalFair(frame, users);
|
||||
Scheduler scheduler = new RoundRobin(frame, users);
|
||||
AccessPoint accessPoint = new AccessPoint(scheduler, frame, users);
|
||||
executor.submit(() -> accessPoint.startSimulation(numberOfTicks));
|
||||
ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||
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 ProportionalFair(frame, users);
|
||||
// Scheduler scheduler = new RoundRobin(frame, users);
|
||||
AccessPoint accessPoint = new AccessPoint(scheduler, frame, users);
|
||||
executor.submit(() -> accessPoint.startSimulation(numberOfTicks));
|
||||
}
|
||||
executor.shutdown();
|
||||
try {
|
||||
if(!executor.awaitTermination(2, TimeUnit.MINUTES)) {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
System.err.println("Please give launch arguments");
|
||||
|
@ -1,18 +1,18 @@
|
||||
package fr.ntr.scheduler;
|
||||
import java.util.List;
|
||||
|
||||
import fr.ntr.Packets;
|
||||
import fr.ntr.AccessPoint;
|
||||
import fr.ntr.ResourceBlock;
|
||||
import fr.ntr.User;
|
||||
|
||||
public class MaxSNR extends Scheduler {
|
||||
|
||||
private List<User> users;
|
||||
private final List<User> users;
|
||||
|
||||
private ResourceBlock[][] frame;
|
||||
private final ResourceBlock[][] frame;
|
||||
|
||||
|
||||
public MaxSNR( ResourceBlock[][] frame, List<User> users) {
|
||||
public MaxSNR(ResourceBlock[][] frame, List<User> users) {
|
||||
this.frame = frame;
|
||||
this.users = users;
|
||||
}
|
||||
@ -20,8 +20,8 @@ public class MaxSNR extends Scheduler {
|
||||
@Override
|
||||
public void scheduling(int ticks) {
|
||||
User userMax;
|
||||
for(int ts = 0; ts < 2; ts++){
|
||||
for(int sp = 0; sp < 100; sp++){
|
||||
for(int ts = 0; ts < AccessPoint.getTimeSlotNb(); ts++){
|
||||
for(int sp = 0; sp < AccessPoint.getSubCarrierNb(); sp++){
|
||||
userMax = userSelection(ts, sp);
|
||||
allocateRessource(userMax, frame, ts, sp, ticks);
|
||||
}
|
||||
@ -36,11 +36,10 @@ public class MaxSNR extends Scheduler {
|
||||
double maxSnr = 0.0;
|
||||
User userMax = null;
|
||||
for(User u: users) {
|
||||
if (!u.getPacketsToSend().isEmpty()) {
|
||||
if (maxSnr < u.getBandwidthTable()[ts][sp]) {
|
||||
maxSnr = u.getBandwidthTable()[ts][sp];
|
||||
userMax = u;
|
||||
}
|
||||
if (!u.getPacketsToSend().isEmpty() && (maxSnr < u.getBandwidthTable()[ts][sp])) {
|
||||
maxSnr = u.getBandwidthTable()[ts][sp];
|
||||
userMax = u;
|
||||
|
||||
}
|
||||
}
|
||||
return userMax;
|
||||
|
@ -3,15 +3,15 @@ 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<User> users;
|
||||
|
||||
private List<User> users;
|
||||
|
||||
private ResourceBlock[][] frame;
|
||||
private final ResourceBlock[][] frame;
|
||||
|
||||
public ProportionalFair(ResourceBlock[][] frame, List<User> users) {
|
||||
this.frame = frame;
|
||||
@ -20,35 +20,29 @@ public class ProportionalFair extends Scheduler {
|
||||
|
||||
@Override
|
||||
public void scheduling(int ticks) {
|
||||
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(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<User> users, List<Double> averageBandwiths) {
|
||||
private User userSelection(int ts, int sp, List<User> 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;
|
||||
}
|
||||
|
@ -16,18 +16,8 @@ public abstract class Scheduler {
|
||||
protected void allocateRessource(User userMax, ResourceBlock[][] frame, int ts, int sp, int ticks) {
|
||||
if (userMax != null && !userMax.getPacketsToSend().isEmpty()) {
|
||||
Packets p = userMax.getPacketsToSend().get(userMax.getPacketsToSend().size()-1);
|
||||
if(p.getBitsNumberRemaining() >= 0){
|
||||
p.decreaseBitsNumberRemaining((int) userMax.getBandwidthTable()[ts][sp]);
|
||||
if(p.getBitsNumberRemaining() <= 0) {
|
||||
if(ticks == 0){
|
||||
p.setDurationSending(1);
|
||||
}else {
|
||||
p.setDurationSending(ticks);
|
||||
}
|
||||
userMax.getPacketsSent().add(p);
|
||||
userMax.getPacketsToSend().remove(p);
|
||||
}
|
||||
} else {
|
||||
p.decreaseBitsNumberRemaining((int) userMax.getBandwidthTable()[ts][sp]);
|
||||
if(p.getBitsNumberRemaining() <= 0) {
|
||||
if(ticks == 0){
|
||||
p.setDurationSending(1);
|
||||
}else {
|
||||
|
Reference in New Issue
Block a user