First fix of User#createPackets
This commit is contained in:
parent
aa9ea15beb
commit
d6d54dbd84
@ -48,7 +48,6 @@ def delay() -> np.ndarray:
|
||||
for x in d:
|
||||
delays[nb, 0] = int(nb_users)
|
||||
delays[nb, 1] = float(x)
|
||||
print(float(x))
|
||||
nb += 1
|
||||
return delays
|
||||
|
||||
@ -60,7 +59,6 @@ delays.sort(axis=0)
|
||||
# Data for plotting
|
||||
averages.sort(axis=0)
|
||||
|
||||
#print(averages)
|
||||
fig, ax = plt.subplots()
|
||||
ax.scatter(averages[:, 0], averages[:, 1])
|
||||
|
||||
|
@ -25,17 +25,12 @@ public class AccessPoint {
|
||||
* 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;
|
||||
|
||||
private Random random = new Random();
|
||||
|
||||
private FileOutputStream outputDataFile;
|
||||
|
||||
|
||||
@ -80,19 +75,15 @@ public class AccessPoint {
|
||||
}
|
||||
|
||||
private void updateBandwidth(int ticks) {
|
||||
int n = 200;
|
||||
int timeInterval = Math.max(1, random.nextInt(51)); // avoid div by 0
|
||||
int m = 200;
|
||||
for(User user : users) {
|
||||
// On régénère les sources toutes les 50-100 ms
|
||||
user.createPackets(m, ticks);
|
||||
// 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 0-50 ms
|
||||
if(ticks % timeInterval == 0){
|
||||
timeInterval = Math.max(1, random.nextInt(51));
|
||||
n = user.createPackets(n, ticks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ public class User {
|
||||
private final List<Packets> packetsToSend;
|
||||
private final List<Packets> packetsSent;
|
||||
private int leftForNextSource;
|
||||
private int timeInterval = 1;
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
@ -40,20 +41,24 @@ public class User {
|
||||
*
|
||||
* @param m
|
||||
* @param ticks qui va définir le temps auquel a été créé un paquet
|
||||
* @return
|
||||
*/
|
||||
public int createPackets(int m, int ticks) {
|
||||
public void createPackets(int m, int ticks) {
|
||||
timeInterval--;
|
||||
if(timeInterval == 0) {
|
||||
timeInterval = random.nextInt(50, 101);
|
||||
// On tire un nombre entre 0 et 2 * m
|
||||
int mbis = m == 0 ? 0 : random.nextInt(2 * (m + this.leftForNextSource));
|
||||
int mbis = random.nextInt(1, 2 * m) + this.leftForNextSource;
|
||||
// On calcule le nombre de paquets qu'on peut transmettre
|
||||
int nbPacketsToSend = mbis / Packets.packetSize;
|
||||
int bitsToSend = random.nextInt(2 * mbis);
|
||||
int nbPacketsToSend = bitsToSend / Packets.packetSize;
|
||||
// On conserve le nombre de bits restants pour la prochaine génération
|
||||
this.leftForNextSource = mbis % Packets.packetSize;
|
||||
this.leftForNextSource = bitsToSend % Packets.packetSize;
|
||||
// On crée les paquets
|
||||
for(int i = 0; i < nbPacketsToSend; i++){
|
||||
for(int i = 0; i < nbPacketsToSend; i++) {
|
||||
this.packetsToSend.add(new Packets(ticks));
|
||||
}
|
||||
return mbis;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public double getDistance() {
|
||||
|
Reference in New Issue
Block a user