Modification schedulers pour gérer les interférences

This commit is contained in:
Quentin Legot 2023-04-07 08:57:56 +02:00
parent ec7f265940
commit 4093336d40
8 changed files with 129 additions and 93 deletions

View File

@ -11,7 +11,7 @@ plugins {
} }
run { run {
args = ["10000", "17"] args = ["10000", "20"]
} }
application { application {

View File

@ -1,8 +1,6 @@
package fr.ntr; package fr.ntr;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class AccessPoint { public class AccessPoint {
@ -23,10 +21,27 @@ public class AccessPoint {
// Simulation // Simulation
cell1.reset(); cell1.reset();
cell2.reset(); cell2.reset();
cell1.updateBandwidth(ticks); cell1.updateBandwidth(ticks);
cell2.updateBandwidth(ticks); cell2.updateBandwidth(ticks);
cell1.schedule(ticks); for(int ts = 0; ts < 2; ts++) {
cell2.schedule(ticks); for (int sp = 0; sp < 100; sp++) {
cell1.preScheduling();
cell2.preScheduling();
User user1 = cell1.schedule(ticks, ts, sp);
User user2 = cell2.schedule(ticks, ts, sp);
if(user1 == user2 && user1 != null) {
computeInterference(user1, ts, sp);
}
cell1.consumeResource(ticks, ts, sp);
cell2.consumeResource(ticks, ts, sp);
cell1.postScheduling(user1);
cell2.postScheduling(user2);
}
}
// traite les données et les enregistre dans un fichier // traite les données et les enregistre dans un fichier
try { try {
cell1.analyseData(ticks); cell1.analyseData(ticks);
@ -37,4 +52,8 @@ public class AccessPoint {
} }
} }
private void computeInterference(User user, int ts, int sp) {
}
} }

View File

@ -61,8 +61,33 @@ public class Cell {
} }
} }
public void schedule(int tick) { public void preScheduling() {
scheduler.scheduling(tick); scheduler.preScheduling();
}
public void postScheduling(User userSelected) {
scheduler.postScheduling(userSelected);
}
public User schedule(int tick, int ts, int sp) {
return scheduler.scheduling(tick, ts, sp);
}
public void consumeResource(int tick, int ts, int sp) {
ResourceBlock rb = frame[ts][sp];
User user = rb.getUser();
Packets p = user.getPacketsToSend().get(user.getPacketsToSend().size()-1);
p.decreaseBitsNumberRemaining((int) user.getBandwidthTable()[ts][sp]);
if(p.getBitsNumberRemaining() <= 0) {
if(tick == 0){
p.setDurationSending(1);
}else {
p.setDurationSending(tick);
}
user.getPacketsSent().add(p);
user.getPacketsToSend().remove(p);
}
} }
public void analyseData(int tick) throws IOException { public void analyseData(int tick) throws IOException {

View File

@ -13,7 +13,6 @@ import java.util.Objects;
import java.util.Random; import java.util.Random;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class Main { public class Main {
@ -73,13 +72,12 @@ public class Main {
List<User> usersCell1 = generateUsers(i, timeSlotNb, subCarrierNb); List<User> usersCell1 = generateUsers(i, timeSlotNb, subCarrierNb);
List<User> usersCell2 = generateUsers(i, timeSlotNb, subCarrierNb); List<User> usersCell2 = generateUsers(i, timeSlotNb, subCarrierNb);
//copie de 1/4 des utilisateurs de cell1 vers cell2 //copie de 1/4 des utilisateurs de cell1 vers cell2
for(int j = 0; j < i/4; j++){
Random r = new Random(); Random r = new Random();
for(int j = 0; j < i/4; j++){
int idxCopy = r.nextInt(i); int idxCopy = r.nextInt(i);
User copiedUser = usersCell1.get(idxCopy); User copiedUser = usersCell1.get(idxCopy);
// On vérifie qu'on ne l'a pas déjà copié dans cell2 // On vérifie qu'on ne l'a pas déjà copié dans cell2
while(usersCell2.contains(copiedUser)){ if(usersCell2.contains(copiedUser)) {
r = new Random();
idxCopy = r.nextInt(i); idxCopy = r.nextInt(i);
copiedUser = usersCell1.get(idxCopy); copiedUser = usersCell1.get(idxCopy);
} }
@ -90,10 +88,9 @@ public class Main {
ResourceBlock[][] frame1 = new ResourceBlock[timeSlotNb][subCarrierNb]; ResourceBlock[][] frame1 = new ResourceBlock[timeSlotNb][subCarrierNb];
ResourceBlock[][] frame2 = new ResourceBlock[timeSlotNb][subCarrierNb]; ResourceBlock[][] frame2 = new ResourceBlock[timeSlotNb][subCarrierNb];
//TODO : changes schedulers
//génération des schedulers //génération des schedulers
Scheduler schedulerCell1 = new RoundRobin(frame1, frame2, usersCell1); Scheduler schedulerCell1 = new RoundRobin(frame1, usersCell1);
Scheduler schedulerCell2 = new RoundRobin(frame2, frame1, usersCell2); Scheduler schedulerCell2 = new RoundRobin(frame2, usersCell2);
try { try {
//préparation à exportation des données de chaque cellule //préparation à exportation des données de chaque cellule
@ -113,14 +110,7 @@ public class Main {
System.exit(1); System.exit(1);
} }
} }
executor.shutdown(); executor.close();
try {
executor.awaitTermination(2, TimeUnit.MINUTES);
}
catch (InterruptedException e) {
e.printStackTrace();
}
executor.shutdownNow();
} }
else { else {
System.err.println("Please give launch arguments"); System.err.println("Please give launch arguments");

View File

@ -8,24 +8,28 @@ import fr.ntr.User;
public class MaxSNR extends Scheduler { public class MaxSNR extends Scheduler {
private final List<User> users; private final List<User> users;
private final ResourceBlock[][] myFrame;
private final ResourceBlock[][] neighborFrame;
public MaxSNR(ResourceBlock[][] myFrame, ResourceBlock[][] neighborFrame, List<User> users) { public MaxSNR(ResourceBlock[][] myFrame, List<User> users) {
this.myFrame = myFrame; super(myFrame);
this.neighborFrame = neighborFrame;
this.users = users; this.users = users;
} }
@Override @Override
public void scheduling(int ticks) { public User scheduling(int ticks, int ts, int sp) {
User userMax; User user = userSelection(ts, sp);
for(int ts = 0; ts < 2; ts++){ allocateRessource(user, ts, sp, ticks);
for(int sp = 0; sp < 100; sp++){ return user;
userMax = userSelection(ts, sp);
allocateRessource(userMax, myFrame, neighborFrame, ts, sp, ticks);
} }
@Override
public void postScheduling(User userSelected) {
} }
@Override
public void preScheduling() {
} }
/** /**

View File

@ -11,18 +11,28 @@ public class ProportionalFair extends Scheduler {
private final List<User> users; private final List<User> users;
private final ResourceBlock[][] myFrame; private ArrayList<Double> averageBandwidth;
private final ResourceBlock[][] neighborFrame;
public ProportionalFair(ResourceBlock[][] myFrame, ResourceBlock[][] neighborFrame, List<User> users) { public ProportionalFair(ResourceBlock[][] myFrame, List<User> users) {
this.myFrame = myFrame; super(myFrame);
this.neighborFrame = neighborFrame;
this.users = users; this.users = users;
} }
@Override @Override
public void scheduling(int ticks) { public User scheduling(int ticks, int ts, int sp) {
ArrayList<Double> averageBandwiths = new ArrayList<>(); User user = userSelection(ts, sp, users);
allocateRessource(user, ts, sp, ticks);
return user;
}
@Override
public void postScheduling(User userSelected) {
}
@Override
public void preScheduling() {
averageBandwidth = new ArrayList<>();
for(User u : users){ for(User u : users){
double avg = 0d; double avg = 0d;
double[][] bandwidthTable = u.getBandwidthTable(); double[][] bandwidthTable = u.getBandwidthTable();
@ -32,23 +42,17 @@ public class ProportionalFair extends Scheduler {
} }
} }
avg = avg / (bandwidthTable.length * bandwidthTable[0].length); avg = avg / (bandwidthTable.length * bandwidthTable[0].length);
averageBandwiths.add(avg); averageBandwidth.add(avg);
}
for(int ts = 0; ts < 2; ts++){
for(int sp = 0; sp < 100; sp++){
User selectedUser = userSelection(ts, sp, users, averageBandwiths);
allocateRessource(selectedUser, myFrame, neighborFrame, 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; double PF = 0.0;
User selectedUser = null; User selectedUser = null;
for(int i = 0; i < users.size(); i++){ for(int i = 0; i < users.size(); i++){
User u = users.get(i); User u = users.get(i);
double mkn = u.getBandwidthTable()[ts][sp]; double mkn = u.getBandwidthTable()[ts][sp];
double averageMkn = averageBandwiths.get(i); double averageMkn = averageBandwidth.get(i);
double pf = mkn / averageMkn; double pf = mkn / averageMkn;
if (PF < pf){ if (PF < pf){
PF = pf; PF = pf;

View File

@ -3,7 +3,6 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import fr.ntr.Cell;
import fr.ntr.ResourceBlock; import fr.ntr.ResourceBlock;
import fr.ntr.User; import fr.ntr.User;
@ -11,13 +10,11 @@ import fr.ntr.User;
public class RoundRobin extends Scheduler { public class RoundRobin extends Scheduler {
private final List<User> users; private final List<User> users;
private final ResourceBlock[][] myFrame; private List<User> userCopy;
private final ResourceBlock[][] neighborFrame;
public RoundRobin(ResourceBlock[][] myFrame, ResourceBlock[][] neighborFrame, List<User> users) { public RoundRobin(ResourceBlock[][] myFrame, List<User> users) {
this.myFrame = myFrame; super(myFrame);
this.neighborFrame = neighborFrame;
this.users = users; this.users = users;
} }
@ -27,22 +24,26 @@ public class RoundRobin extends Scheduler {
* Return * Return
*/ */
@Override @Override
public void scheduling(int ticks) { public User scheduling(int ticks, int ts, int sp) {
List<User> userCopy = users.stream().filter(u -> !u.getPacketsToSend().isEmpty()).collect(Collectors.toList());
Collections.shuffle(userCopy);
//Pour chaque time slot et sous porteuses
loop: for (int ts = 0; ts < Cell.getTimeSlotNb(); ts++) {
for(int sp = 0; sp < Cell.getSubCarrierNb(); sp++) {
if(userCopy.isEmpty()) { if(userCopy.isEmpty()) {
break loop; return null;
} }
User userSelected = userSelection(userCopy); User user = userSelection(userCopy);
allocateRessource(userSelected, myFrame, neighborFrame, ts, sp, ticks); allocateRessource(user, ts, sp, ticks);
return user;
}
@Override
public void postScheduling(User userSelected) {
if(!userSelected.getPacketsToSend().isEmpty()) if(!userSelected.getPacketsToSend().isEmpty())
userCopy.add(userSelected); userCopy.add(userSelected);
} }
}
@Override
public void preScheduling() {
userCopy = users.stream().filter(u -> !u.getPacketsToSend().isEmpty()).collect(Collectors.toList());
Collections.shuffle(userCopy);
} }
/** /**

View File

@ -6,29 +6,22 @@ import fr.ntr.User;
public abstract class Scheduler { public abstract class Scheduler {
protected final ResourceBlock[][] myFrame;
public abstract void scheduling(int ticks); public Scheduler(ResourceBlock[][] myFrame) {
this.myFrame = myFrame;
}
protected void allocateRessource(User userMax, ResourceBlock[][] myFrame, ResourceBlock[][] neighborFrame, int ts, int sp, int ticks) {
ResourceBlock rb1 = myFrame[ts][sp]; public abstract User scheduling(int ticks, int ts, int sp);
ResourceBlock rb2 = neighborFrame[ts][sp];
public abstract void postScheduling(User userSelected);
public abstract void preScheduling();
public void allocateRessource(User userMax, int ts, int sp, int ticks) {
if (userMax != null && !userMax.getPacketsToSend().isEmpty()) { if (userMax != null && !userMax.getPacketsToSend().isEmpty()) {
User user2 = rb2.getUser(); /* Packets p = userMax.getPacketsToSend().get(userMax.getPacketsToSend().size()-1);
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);
p.decreaseBitsNumberRemaining((int) userMax.getBandwidthTable()[ts][sp]); p.decreaseBitsNumberRemaining((int) userMax.getBandwidthTable()[ts][sp]);
if(p.getBitsNumberRemaining() <= 0) { if(p.getBitsNumberRemaining() <= 0) {
if(ticks == 0){ if(ticks == 0){
@ -38,7 +31,7 @@ public abstract class Scheduler {
} }
userMax.getPacketsSent().add(p); userMax.getPacketsSent().add(p);
userMax.getPacketsToSend().remove(p); userMax.getPacketsToSend().remove(p);
} } */
myFrame[ts][sp].setUser(userMax); myFrame[ts][sp].setUser(userMax);
myFrame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]); myFrame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]);
} }