Merge branch 'master' of gitlab.istic.univ-rennes1.fr:18008147/ntr

This commit is contained in:
Remi Boure 2023-03-17 11:39:04 +01:00
commit 4689f2a921
7 changed files with 91 additions and 32 deletions

View File

@ -1,5 +1,8 @@
package fr.ntr; package fr.ntr;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@ -31,12 +34,14 @@ public class AccessPoint {
private final double min, max; private final double min, max;
public AccessPoint(Scheduler scheduler, double min, double max) { public AccessPoint(Scheduler scheduler, ResourceBlock[][] frame, List<User> users, int timeSlotNb, int subCarrierNb, double min, double max) {
this.min = min; this.min = min;
this.max = max; this.max = max;
this.users = new ArrayList<>(); this.users = users;
this.scheduler = scheduler; this.scheduler = scheduler;
this.frame = new ResourceBlock[timeSlotNb][subCarrierNb]; this.frame = frame;
this.timeSlotNb = timeSlotNb;
this.subCarrierNb = subCarrierNb;
} }
/** /**
@ -44,30 +49,34 @@ public class AccessPoint {
* @param duration * @param duration
*/ */
public void startSimulation(int duration, int nbUsers) { public void startSimulation(int duration, int nbUsers) {
init(nbUsers);
for (int ticks = 0; ticks < duration; ++ticks) { for (int ticks = 0; ticks < duration; ++ticks) {
// Simulation // Simulation
reset(); reset();
updateBandwidth(ticks); updateBandwidth(ticks);
schedule(); schedule();
// traite les données et les enregistre dans un fichier // traite les données et les enregistre dans un fichier
try {
analyseData(); analyseData();
} catch (IOException e) {
System.out.println("Can't export data");
}
} }
} }
private void updateBandwidth(int ticks) { private void updateBandwidth(int ticks) {
int n = 200; int n = 200;
int timeInterval = 50 + new Random().nextInt(50); Random random = new Random();
int timeInterval = 50 + random.nextInt(51);
for(User user : users) { for(User user : users) {
// On regénère le tableau de débits toutes les 50 ms // On régénère le tableau de débits toutes les 50 ms
if(ticks % 50 == 0){ if(ticks % 50 == 0){
user.generateBandwidth(); user.generateBandwidth();
} }
// On regénère les sources toutes les 50-100 ms // On régénère les sources toutes les 50-100 ms
if(ticks % timeInterval == 0){ if(ticks % timeInterval == 0){
timeInterval = 50 + random.nextInt(51);
n = user.createPackets(n, ticks); n = user.createPackets(n, ticks);
timeInterval = 50 + new Random().nextInt(51);
} }
} }
} }
@ -90,8 +99,17 @@ public class AccessPoint {
scheduler.scheduling(); scheduler.scheduling();
} }
private void analyseData() { private void analyseData() throws IOException {
try(FileOutputStream file = new FileOutputStream("data.csv", true)) {
for(int i = 0; i < frame.length; i++) {
for(int j = 0; j < frame[i].length; j++) {
ResourceBlock ur = frame[i][j];
String data = (i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";\n");
System.out.println("data: " + data);
file.write(data.getBytes());
}
}
}
} }
private void plotData() { private void plotData() {
@ -99,7 +117,6 @@ public class AccessPoint {
} }
private void reset() { private void reset() {
this.users = new ArrayList<>();
this.frame = new ResourceBlock[timeSlotNb][subCarrierNb]; this.frame = new ResourceBlock[timeSlotNb][subCarrierNb];
} }

View File

@ -1,11 +1,14 @@
package fr.ntr; package fr.ntr;
import fr.ntr.scheduler.RoundRobin; import fr.ntr.scheduler.RoundRobin;
import fr.ntr.scheduler.Scheduler;
import java.util.ArrayList;
import java.util.List;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
//TODO ajouter accès à AccessPoint
if(args.length == 2) { if(args.length == 2) {
int numberOfTicks; // Nombre de ticks de la simulation -> durée de la simulation int numberOfTicks; // Nombre de ticks de la simulation -> durée de la simulation
@ -19,13 +22,31 @@ public class Main {
System.exit(1); System.exit(1);
return; return;
} }
int timeSlotNb = 2;
AccessPoint accessPoint = new AccessPoint(new RoundRobin("round robin", 0), 0, 50); int subCarrierNb = 100;
List<User> users = generateUsers(20, timeSlotNb, subCarrierNb);
ResourceBlock[][] frame = new ResourceBlock[timeSlotNb][subCarrierNb];
Scheduler scheduler = new RoundRobin("round robin", 0, frame, users);
AccessPoint accessPoint = new AccessPoint(scheduler, frame, users, timeSlotNb, subCarrierNb, 0, 50);
accessPoint.startSimulation(numberOfTicks, maximumLoad); accessPoint.startSimulation(numberOfTicks, maximumLoad);
} else { }
else {
System.err.println("Please give launch arguments"); System.err.println("Please give launch arguments");
System.err.println("gradle run --args=\"<number of ticks> <number of users>\""); System.err.println("gradle run --args=\"<number of ticks> <number of users>\"");
System.exit(1); System.exit(1);
} }
} }
private static List<User> generateUsers(int nbUsers, int timeSlotNb, int subCarrierNb) {
List<User> users = new ArrayList<>();
// 2 groupes d'utilisateurs, proches et éloignés
double[] distance = { 200d, 1000d };
for (double v : distance) {
for (int j = 0; j < nbUsers; j++) {
User user = new User(v, timeSlotNb, subCarrierNb);
users.add(user);
}
}
return users;
}
} }

View File

@ -2,18 +2,26 @@ package fr.ntr;
public class ResourceBlock { public class ResourceBlock {
private User user; private User user;
private double bandwith; private double bandwidth;
public ResourceBlock (User user, double bandwith) { public ResourceBlock (User user, double bandwidth) {
this.user = user; this.user = user;
this.bandwith = bandwith; this.bandwidth = bandwidth;
} }
public void setUser(User user) { public void setUser(User user) {
this.user = user; this.user = user;
} }
public void setBandwith(double bandwith) { public void setBandwidth(double bandwidth) {
this.bandwith = bandwith; this.bandwidth = bandwidth;
}
public User getUser() {
return user;
}
public double getBandwidth() {
return bandwidth;
} }
} }

View File

@ -1,18 +1,27 @@
package fr.ntr.scheduler; package fr.ntr.scheduler;
import java.util.List; import java.util.List;
import fr.ntr.ResourceBlock;
import fr.ntr.User; import fr.ntr.User;
public class MaxSNR extends Scheduler { public class MaxSNR extends Scheduler {
private List<User> users; private List<User> users;
private ResourceBlock[][] frame;
@Override @Override
public void scheduling() { public void scheduling() {
User userMax = null; User userMax = null;
for(int ts = 0; ts < 2; ts++){ for(int ts = 0; ts < 2; ts++){
for(int sp = 0; sp < 100; sp++){ for(int sp = 0; sp < 100; sp++){
userMax = selectionUtilisateur(sp, ts, users); userMax = selectionUtilisateur(sp, ts, users);
userMax.getPacketsSent().add(userMax.getPacketsToSend().get(0));
userMax.getPacketsToSend().remove(userMax.getPacketsToSend().get(0));
frame[ts][sp].setUser(selectionUtilisateur(sp, ts, users));
if (userMax.getPacketsToSend() == null) {
users.remove(userMax);
}
} }
} }
} }

View File

@ -23,7 +23,7 @@ public class ProportionalFair extends Scheduler {
} }
@Override @Override
protected void TraitementDonnées() { protected void TraitementDonnees() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }

View File

@ -15,9 +15,11 @@ public class RoundRobin extends Scheduler {
private List<User> users; private List<User> users;
private ResourceBlock[][] frame; private ResourceBlock[][] frame;
public RoundRobin(String name, int index) { public RoundRobin(String name, int index, ResourceBlock[][] frame, List<User> users) {
this.name = name; this.name = name;
this.index = index; this.index = index;
this.frame = frame;
this.users = users;
} }
/** /**
@ -29,20 +31,21 @@ public class RoundRobin extends Scheduler {
public void scheduling() { public void scheduling() {
//selection aleatoire du premier utilisateur //selection aleatoire du premier utilisateur
Random random = new Random(); Random random = new Random();
index = random.nextInt(users.size()-1); index = random.nextInt(users.size());
//Pour chaque time slot et sous porteuses //Pour chaque time slot et sous porteuses
for (int Ts = 0; Ts < AccessPoint.getTimeSlotNb(); Ts++) { for (int Ts = 0; Ts < AccessPoint.getTimeSlotNb(); Ts++) {
for(int Sp = 0; Sp < AccessPoint.getSubCarrierNb(); Sp++) { for(int Sp = 0; Sp < AccessPoint.getSubCarrierNb(); Sp++) {
// on enlève le packet transmis de la liste
// TODO Verify sub the packet send need Set packet
users.get(index).getPacketsSent().add(users.get(index).getPacketsToSend().get(0));
users.get(index).getPacketsToSend().remove(users.get(index).getPacketsToSend().get(0));
//on ajoute l'utilisateur a la frame
frame[Ts][Sp].setUser(UserSelection(Ts, Sp, users));
//si un utilisateur n'a plus de packet a transmettre on supprime l'utilisateur de la liste
if (users.get(index).getPacketsToSend() == null) { if (users.get(index).getPacketsToSend() == null) {
users.remove(index); users.remove(index);
}else{
//sub the packet send need Set packet
users.get(index).getPacketsToSend();
} }
frame[Ts][Sp].setUser(UserSelection(Ts, Sp, users));
} }
} }
} }
@ -52,12 +55,13 @@ public class RoundRobin extends Scheduler {
* Return the user in function of TS and SP selected * Return the user in function of TS and SP selected
*/ */
private User UserSelection(int Ts, int Sp, List<User> users) { private User UserSelection(int Ts, int Sp, List<User> users) {
//compte le nombre de bloc attribue
for (int i = 0; i < Ts; i++){ for (int i = 0; i < Ts; i++){
for (int j = 0; j < Sp; j++) { for (int j = 0; j < Sp; j++) {
index++; index++;
} }
} }
//on retourne l'utilisateur
return users.get(index%(users.size() - 1)); return users.get(index%(users.size() - 1));
} }

View File

@ -8,7 +8,7 @@ public abstract class Scheduler {
* Return * Return
*/ */
public abstract void scheduling(); public abstract void scheduling();
protected void TraitementDonnées() { protected void TraitementDonnees() {
} }
} }