This repository has been archived on 2023-08-28. You can view files and clone it, but cannot push or open issues or pull requests.
ntr-interferences/src/main/java/fr/ntr/AccessPoint.java

134 lines
3.4 KiB
Java
Raw Normal View History

2023-03-03 10:38:35 +01:00
package fr.ntr;
2023-03-17 10:55:45 +01:00
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
2023-03-03 12:12:18 +01:00
import java.util.ArrayList;
2023-03-03 11:28:16 +01:00
import java.util.List;
import java.util.Random;
2023-03-03 11:28:16 +01:00
import fr.ntr.scheduler.Scheduler;
2023-03-03 10:38:35 +01:00
public class AccessPoint {
2023-03-10 10:50:46 +01:00
private List<User> users;
2023-03-03 11:28:16 +01:00
private Scheduler scheduler;
2023-03-03 11:47:53 +01:00
/**
* nombre de slots
*/
private static int timeSlotNb;
/**
* Nombre de sous-porteuses
2023-03-03 11:47:53 +01:00
*/
private static int subCarrierNb;
/**
* trame
*/
private ResourceBlock[][] frame;
/**
* Reste pour la prochaine source
2023-03-03 11:47:53 +01:00
*/
private double leftForNextSource;
/**
* Portée minimum et maximum de l'antenne
*/
private final double min, max;
2023-03-03 11:28:16 +01:00
public AccessPoint(Scheduler scheduler, ResourceBlock[][] frame, int timeSlotNb, int subCarrierNb, double min, double max) {
this.min = min;
this.max = max;
this.users = new ArrayList<>();
2023-03-03 11:28:16 +01:00
this.scheduler = scheduler;
this.frame = frame;
this.timeSlotNb = timeSlotNb;
this.subCarrierNb = subCarrierNb;
2023-03-03 11:28:16 +01:00
}
/**
* Lancer la simulation
* @param duration
*/
2023-03-10 08:30:28 +01:00
public void startSimulation(int duration, int nbUsers) {
init(nbUsers);
2023-03-10 08:30:28 +01:00
for (int ticks = 0; ticks < duration; ++ticks) {
// Simulation
reset();
updateBandwidth(ticks);
schedule();
// traite les données et les enregistre dans un fichier
2023-03-17 10:55:45 +01:00
try {
analyseData();
} catch (IOException e) {
System.out.println("Can't export data");
}
}
2023-03-03 11:28:16 +01:00
}
private void updateBandwidth(int ticks) {
int n = 200;
2023-03-17 10:29:36 +01:00
Random random = new Random();
int timeInterval = 50 + random.nextInt(51);
for(User user : users) {
2023-03-17 10:29:36 +01:00
// On régénère le tableau de débits toutes les 50 ms
if(ticks % 50 == 0){
user.generateBandwidth();
}
2023-03-17 10:29:36 +01:00
// On régénère les sources toutes les 50-100 ms
if(ticks % timeInterval == 0){
n = user.createPackets(n);
2023-03-17 10:29:36 +01:00
timeInterval = 50 + random.nextInt(51);
}
}
}
2023-03-03 12:12:18 +01:00
/**
* Génération du débit et des paquets
*/
private void init(int nbUsers) {
2023-03-11 12:04:22 +01:00
// 2 groupes d'utilisateurs, proches et éloignés
2023-03-10 10:50:46 +01:00
double[] distance = { 200d, 1000d };
for (int i = 0; i < distance.length; i++) {
for(int j = 0; j < nbUsers; j++){
User user = new User(distance[i], timeSlotNb, subCarrierNb);
this.users.add(user);
}
}
}
2023-03-10 08:30:28 +01:00
private void schedule() {
2023-03-17 09:48:38 +01:00
scheduler.scheduling();
}
2023-03-17 10:55:45 +01:00
private void analyseData() throws IOException {
FileOutputStream file = new FileOutputStream("data.csv", true);
// file.write("data1;data2".getBytes());
file.close();
2023-03-03 11:28:16 +01:00
}
2023-03-10 08:30:28 +01:00
private void plotData() {
2023-03-03 11:28:16 +01:00
}
2023-03-10 08:30:28 +01:00
private void reset() {
2023-03-17 09:57:17 +01:00
this.users = new ArrayList<>();
this.frame = new ResourceBlock[timeSlotNb][subCarrierNb];
2023-03-03 11:28:16 +01:00
}
2023-03-03 12:12:18 +01:00
2023-03-10 08:30:28 +01:00
public int getFrameSize() {
2023-03-03 12:12:18 +01:00
return this.timeSlotNb * this.subCarrierNb;
}
2023-03-10 08:30:28 +01:00
public ResourceBlock[][] getFrame() {
return frame;
}
2023-03-10 11:38:52 +01:00
public static int getTimeSlotNb() {
return timeSlotNb;
}
public static int getSubCarrierNb() {
return subCarrierNb;
2023-03-10 08:30:28 +01:00
}
2023-03-03 10:38:35 +01:00
}