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

123 lines
2.9 KiB
Java
Raw Normal View History

2023-03-03 10:38:35 +01:00
package fr.ntr;
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, 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;
2023-03-03 12:12:18 +01:00
this.frame = new ResourceBlock[timeSlotNb][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
analyseData();
}
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-10 08:30:28 +01:00
private void analyseData() {
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
}