Merge branch 'interference' into 'ajout_cellule'
Interference See merge request 18008147/ntr!2
This commit is contained in:
commit
ede383eab8
@ -11,7 +11,7 @@ plugins {
|
||||
}
|
||||
|
||||
run {
|
||||
args = ["10000", "17"]
|
||||
args = ["10000", "40"]
|
||||
}
|
||||
|
||||
application {
|
||||
|
@ -1,8 +1,6 @@
|
||||
package fr.ntr;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AccessPoint {
|
||||
|
||||
@ -23,14 +21,28 @@ public class AccessPoint {
|
||||
// Simulation
|
||||
cell1.reset();
|
||||
cell2.reset();
|
||||
|
||||
cell1.updateBandwidth(ticks);
|
||||
cell2.updateBandwidth(ticks);
|
||||
cell1.schedule(ticks);
|
||||
cell2.schedule(ticks);
|
||||
cell1.preScheduling();
|
||||
cell2.preScheduling();
|
||||
for(int ts = 0; ts < Cell.getTimeSlotNb(); ts++) {
|
||||
for (int sp = 0; sp < Cell.getSubCarrierNb(); sp++) {
|
||||
User user1 = cell1.schedule(ticks, ts, sp);
|
||||
User user2 = cell2.schedule(ticks, ts, sp);
|
||||
boolean haveInterference = user1 == user2 && user1 != null;
|
||||
cell1.consumeResource(ticks, ts, sp, haveInterference);
|
||||
cell2.consumeResource(ticks, ts, sp, haveInterference);
|
||||
|
||||
cell1.postScheduling(user1);
|
||||
cell2.postScheduling(user2);
|
||||
}
|
||||
}
|
||||
|
||||
// traite les données et les enregistre dans un fichier
|
||||
try {
|
||||
cell1.analyseData(ticks);
|
||||
//cell2.analyseData(ticks);
|
||||
cell2.analyseData(ticks);
|
||||
} catch (IOException e) {
|
||||
System.out.println("Can't export data");
|
||||
}
|
||||
|
@ -61,8 +61,48 @@ public class Cell {
|
||||
}
|
||||
}
|
||||
|
||||
public void schedule(int tick) {
|
||||
scheduler.scheduling(tick);
|
||||
public void preScheduling() {
|
||||
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, boolean haveInterference) {
|
||||
ResourceBlock rb = frame[ts][sp];
|
||||
User user = rb.getUser();
|
||||
if(user != null && !user.getPacketsToSend().isEmpty()) {
|
||||
Packets p = user.getPacketsToSend().get(0);
|
||||
rb.setBandwidth(updateBandwidth(haveInterference, rb));
|
||||
p.decreaseBitsNumberRemaining((int) rb.getBandwidth());
|
||||
if(p.getBitsNumberRemaining() <= 0) {
|
||||
if(tick == 0){
|
||||
p.setDurationSending(1);
|
||||
}else {
|
||||
p.setDurationSending(tick);
|
||||
}
|
||||
user.getPacketsSent().add(p);
|
||||
user.getPacketsToSend().remove(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private double updateBandwidth(boolean haveInterference, ResourceBlock rb) {
|
||||
if(haveInterference) {
|
||||
if(rb.getUser().getDistance() < 200d) {
|
||||
// User proche
|
||||
return rb.getBandwidth() / 2;
|
||||
}
|
||||
// User loin
|
||||
return rb.getBandwidth() / 4;
|
||||
} else {
|
||||
return rb.getBandwidth();
|
||||
}
|
||||
}
|
||||
|
||||
public void analyseData(int tick) throws IOException {
|
||||
|
@ -13,7 +13,6 @@ import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Main {
|
||||
|
||||
@ -73,13 +72,12 @@ public class Main {
|
||||
List<User> usersCell1 = generateUsers(i, timeSlotNb, subCarrierNb);
|
||||
List<User> usersCell2 = generateUsers(i, timeSlotNb, subCarrierNb);
|
||||
//copie de 1/4 des utilisateurs de cell1 vers cell2
|
||||
Random r = new Random();
|
||||
for(int j = 0; j < i/4; j++){
|
||||
Random r = new Random();
|
||||
int idxCopy = r.nextInt(i);
|
||||
User copiedUser = usersCell1.get(idxCopy);
|
||||
// On vérifie qu'on ne l'a pas déjà copié dans cell2
|
||||
while(usersCell2.contains(copiedUser)){
|
||||
r = new Random();
|
||||
if(usersCell2.contains(copiedUser)) {
|
||||
idxCopy = r.nextInt(i);
|
||||
copiedUser = usersCell1.get(idxCopy);
|
||||
}
|
||||
@ -90,10 +88,9 @@ public class Main {
|
||||
ResourceBlock[][] frame1 = new ResourceBlock[timeSlotNb][subCarrierNb];
|
||||
ResourceBlock[][] frame2 = new ResourceBlock[timeSlotNb][subCarrierNb];
|
||||
|
||||
//TODO : changes schedulers
|
||||
//génération des schedulers
|
||||
Scheduler schedulerCell1 = new RoundRobin(frame1, frame2, usersCell1);
|
||||
Scheduler schedulerCell2 = new RoundRobin(frame2, frame1, usersCell2);
|
||||
Scheduler schedulerCell1 = new RoundRobin(frame1, usersCell1);
|
||||
Scheduler schedulerCell2 = new RoundRobin(frame2, usersCell2);
|
||||
|
||||
try {
|
||||
//préparation à exportation des données de chaque cellule
|
||||
@ -113,14 +110,8 @@ public class Main {
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
executor.shutdown();
|
||||
try {
|
||||
executor.awaitTermination(2, TimeUnit.MINUTES);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
executor.shutdownNow();
|
||||
executor.close();
|
||||
System.out.println("Executor closed");
|
||||
}
|
||||
else {
|
||||
System.err.println("Please give launch arguments");
|
||||
@ -135,7 +126,7 @@ public class Main {
|
||||
int half = nbUsers / 2;
|
||||
for (int i = 0; i < nbUsers; i++) {
|
||||
User user;
|
||||
if(i >= half ){
|
||||
if(i >= half){
|
||||
user = new User(500d, timeSlotNb, subCarrierNb);
|
||||
}
|
||||
else {
|
||||
|
@ -8,24 +8,28 @@ import fr.ntr.User;
|
||||
public class MaxSNR extends Scheduler {
|
||||
|
||||
private final List<User> users;
|
||||
private final ResourceBlock[][] myFrame;
|
||||
private final ResourceBlock[][] neighborFrame;
|
||||
|
||||
public MaxSNR(ResourceBlock[][] myFrame, ResourceBlock[][] neighborFrame, List<User> users) {
|
||||
this.myFrame = myFrame;
|
||||
this.neighborFrame = neighborFrame;
|
||||
public MaxSNR(ResourceBlock[][] myFrame, List<User> users) {
|
||||
super(myFrame);
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduling(int ticks) {
|
||||
User userMax;
|
||||
for(int ts = 0; ts < 2; ts++){
|
||||
for(int sp = 0; sp < 100; sp++){
|
||||
userMax = userSelection(ts, sp);
|
||||
allocateRessource(userMax, myFrame, neighborFrame, ts, sp, ticks);
|
||||
}
|
||||
}
|
||||
public User scheduling(int ticks, int ts, int sp) {
|
||||
User user = userSelection(ts, sp);
|
||||
allocateRessource(user, ts, sp, ticks);
|
||||
return user;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postScheduling(User userSelected) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preScheduling() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,18 +11,28 @@ public class ProportionalFair extends Scheduler {
|
||||
|
||||
private final List<User> users;
|
||||
|
||||
private final ResourceBlock[][] myFrame;
|
||||
private final ResourceBlock[][] neighborFrame;
|
||||
private ArrayList<Double> averageBandwidth;
|
||||
|
||||
public ProportionalFair(ResourceBlock[][] myFrame, ResourceBlock[][] neighborFrame, List<User> users) {
|
||||
this.myFrame = myFrame;
|
||||
this.neighborFrame = neighborFrame;
|
||||
public ProportionalFair(ResourceBlock[][] myFrame, List<User> users) {
|
||||
super(myFrame);
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduling(int ticks) {
|
||||
ArrayList<Double> averageBandwiths = new ArrayList<>();
|
||||
public User scheduling(int ticks, int ts, int sp) {
|
||||
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){
|
||||
double avg = 0d;
|
||||
double[][] bandwidthTable = u.getBandwidthTable();
|
||||
@ -32,23 +42,17 @@ public class ProportionalFair extends Scheduler {
|
||||
}
|
||||
}
|
||||
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);
|
||||
allocateRessource(selectedUser, myFrame, neighborFrame, ts, sp, ticks);
|
||||
}
|
||||
averageBandwidth.add(avg);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
double mkn = u.getBandwidthTable()[ts][sp];
|
||||
double averageMkn = averageBandwiths.get(i);
|
||||
double averageMkn = averageBandwidth.get(i);
|
||||
double pf = mkn / averageMkn;
|
||||
if (PF < pf){
|
||||
PF = pf;
|
||||
|
@ -3,7 +3,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import fr.ntr.Cell;
|
||||
import fr.ntr.ResourceBlock;
|
||||
import fr.ntr.User;
|
||||
|
||||
@ -11,13 +10,11 @@ import fr.ntr.User;
|
||||
public class RoundRobin extends Scheduler {
|
||||
|
||||
private final List<User> users;
|
||||
private final ResourceBlock[][] myFrame;
|
||||
private final ResourceBlock[][] neighborFrame;
|
||||
private List<User> userCopy;
|
||||
|
||||
|
||||
public RoundRobin(ResourceBlock[][] myFrame, ResourceBlock[][] neighborFrame, List<User> users) {
|
||||
this.myFrame = myFrame;
|
||||
this.neighborFrame = neighborFrame;
|
||||
public RoundRobin(ResourceBlock[][] myFrame, List<User> users) {
|
||||
super(myFrame);
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
@ -27,22 +24,25 @@ public class RoundRobin extends Scheduler {
|
||||
* Return
|
||||
*/
|
||||
@Override
|
||||
public void scheduling(int ticks) {
|
||||
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()) {
|
||||
break loop;
|
||||
}
|
||||
User userSelected = userSelection(userCopy);
|
||||
allocateRessource(userSelected, myFrame, neighborFrame, ts, sp, ticks);
|
||||
if(!userSelected.getPacketsToSend().isEmpty())
|
||||
userCopy.add(userSelected);
|
||||
}
|
||||
public User scheduling(int ticks, int ts, int sp) {
|
||||
if(userCopy.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
User user = userSelection(userCopy);
|
||||
allocateRessource(user, ts, sp, ticks);
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postScheduling(User userSelected) {
|
||||
if(userSelected != null && !userSelected.getPacketsToSend().isEmpty())
|
||||
userCopy.add(userSelected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preScheduling() {
|
||||
userCopy = users.stream().filter(u -> !u.getPacketsToSend().isEmpty()).collect(Collectors.toList());
|
||||
Collections.shuffle(userCopy);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,39 +6,21 @@ import fr.ntr.User;
|
||||
|
||||
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];
|
||||
ResourceBlock rb2 = neighborFrame[ts][sp];
|
||||
|
||||
public abstract User scheduling(int ticks, int ts, int 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()) {
|
||||
User user2 = rb2.getUser();
|
||||
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]);
|
||||
if(p.getBitsNumberRemaining() <= 0) {
|
||||
if(ticks == 0){
|
||||
p.setDurationSending(1);
|
||||
}else {
|
||||
p.setDurationSending(ticks);
|
||||
}
|
||||
userMax.getPacketsSent().add(p);
|
||||
userMax.getPacketsToSend().remove(p);
|
||||
}
|
||||
myFrame[ts][sp].setUser(userMax);
|
||||
myFrame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user