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
2023-03-17 10:29:36 +01:00

123 lines
2.9 KiB
Java

package fr.ntr;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import fr.ntr.scheduler.Scheduler;
public class AccessPoint {
private List<User> users;
private Scheduler scheduler;
/**
* nombre de slots
*/
private static int timeSlotNb;
/**
* Nombre de sous-porteuses
*/
private static int subCarrierNb;
/**
* trame
*/
private ResourceBlock[][] frame;
/**
* Reste pour la prochaine source
*/
private double leftForNextSource;
/**
* Portée minimum et maximum de l'antenne
*/
private final double min, max;
public AccessPoint(Scheduler scheduler, double min, double max) {
this.min = min;
this.max = max;
this.users = new ArrayList<>();
this.scheduler = scheduler;
this.frame = new ResourceBlock[timeSlotNb][subCarrierNb];
}
/**
* Lancer la simulation
* @param duration
*/
public void startSimulation(int duration, int nbUsers) {
init(nbUsers);
for (int ticks = 0; ticks < duration; ++ticks) {
// Simulation
reset();
updateBandwidth(ticks);
schedule();
// traite les données et les enregistre dans un fichier
analyseData();
}
}
private void updateBandwidth(int ticks) {
int n = 200;
Random random = new Random();
int timeInterval = 50 + random.nextInt(51);
for(User user : users) {
// On régénère le tableau de débits toutes les 50 ms
if(ticks % 50 == 0){
user.generateBandwidth();
}
// On régénère les sources toutes les 50-100 ms
if(ticks % timeInterval == 0){
n = user.createPackets(n);
timeInterval = 50 + random.nextInt(51);
}
}
}
/**
* Génération du débit et des paquets
*/
private void init(int nbUsers) {
// 2 groupes d'utilisateurs, proches et éloignés
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);
}
}
}
private void schedule() {
scheduler.scheduling();
}
private void analyseData() {
}
private void plotData() {
}
private void reset() {
this.users = new ArrayList<>();
this.frame = new ResourceBlock[timeSlotNb][subCarrierNb];
}
public int getFrameSize() {
return this.timeSlotNb * this.subCarrierNb;
}
public ResourceBlock[][] getFrame() {
return frame;
}
public static int getTimeSlotNb() {
return timeSlotNb;
}
public static int getSubCarrierNb() {
return subCarrierNb;
}
}