Fix userSelection in RR

This commit is contained in:
Quentin Legot 2023-03-28 09:30:21 +02:00
parent 6442356450
commit c778fcb6da
4 changed files with 36 additions and 38 deletions

View File

@ -33,16 +33,8 @@ def rb_available() -> np.ndarray:
data = pd.read_csv(".." + os.sep + "export" + os.sep + i, delimiter=';').to_numpy()
nb_users = i.split(".")[0]
available[nb, 0] = int(nb_users)
available[nb, 1] = data.shape[0] / (200 * 10000)
available[nb, 1] = (data.shape[0] / (200 * 10000)) * 100
nb += 1
"""for j in range(0, 2):
for k in range(0, 10000):
nb_users = i.split(".")[0]
available[nb, 0] = int(nb_users)
if j == data[nb, 1] and k == data[:, 2]:
available[nb, 1] += 1
"""
return available

View File

@ -26,11 +26,12 @@ public class Main {
}
int timeSlotNb = 2;
int subCarrierNb = 100;
for(int i = 2; i < maximumLoad; i+=2) {
for(int i = 2; i <= maximumLoad; i += 2) {
List<User> users = generateUsers(i, timeSlotNb, subCarrierNb);
ResourceBlock[][] frame = new ResourceBlock[timeSlotNb][subCarrierNb];
//Scheduler scheduler = new MaxSNR(frame, users);
Scheduler scheduler = new ProportionalFair(frame, users);
// Scheduler scheduler = new ProportionalFair(frame, users);
Scheduler scheduler = new RoundRobin(frame, users);
AccessPoint accessPoint = new AccessPoint(scheduler, frame, users, timeSlotNb, subCarrierNb, 0, 50);
accessPoint.startSimulation(numberOfTicks);
}

View File

@ -19,21 +19,25 @@ public class MaxSNR extends Scheduler {
@Override
public void scheduling(int ticks) {
User userMax = null;
User userMax;
for(int ts = 0; ts < 2; ts++){
for(int sp = 0; sp < 100; sp++){
userMax = userSelection(ts, sp, users);
userMax = userSelection(ts, sp);
allocateRessource(userMax, frame, ts, sp, ticks);
}
}
}
private User userSelection(int ts, int sp, List<User> Users) {
double MaxSnr = 0.0;
/**
* Sélectionne le prochain utilisateur en fonction du contexte
* @return the user with the best bandwidth
*/
private User userSelection(int ts, int sp) {
double maxSnr = 0.0;
User userMax = null;
for(User u: Users){
if (MaxSnr < u.getBandwidthTable()[ts][sp]){
MaxSnr = u.getBandwidthTable()[ts][sp];
for(User u: users){
if (maxSnr < u.getBandwidthTable()[ts][sp]) {
maxSnr = u.getBandwidthTable()[ts][sp];
userMax = u;
}
}

View File

@ -9,17 +9,17 @@ import fr.ntr.User;
public class RoundRobin extends Scheduler {
private String name;
private final Random random;
private int index;
private List<User> users;
private ResourceBlock[][] frame;
private final List<User> users;
private final ResourceBlock[][] frame;
public RoundRobin(String name, int index, ResourceBlock[][] frame, List<User> users) {
this.name = name;
this.index = index;
public RoundRobin(ResourceBlock[][] frame, List<User> users) {
this.index = 0;
this.frame = frame;
this.users = users;
this.random = new Random();
}
/**
@ -29,14 +29,14 @@ public class RoundRobin extends Scheduler {
*/
@Override
public void scheduling(int ticks) {
//selection aleatoire du premier utilisateur
Random random = new Random();
//selection aléatoire du premier utilisateur
index = random.nextInt(users.size());
//Pour chaque time slot et sous porteuses
for (int ts = 0; ts < AccessPoint.getTimeSlotNb(); ts++) {
for(int sp = 0; sp < AccessPoint.getSubCarrierNb(); sp++) {
User userSelected = userSelection(ts, sp, users);
User userSelected = userSelection();
allocateRessource(userSelected, frame, ts, sp, ticks);
}
}
@ -45,16 +45,17 @@ public class RoundRobin extends Scheduler {
/**
* Entry Time slot (int), Sous porteuse(int), and users ( List<User>)
* Return the user in function of TS and SP selected
*
* @return the next user which have something to send, null otherwise
*/
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 j = 0; j < sp; j++) {
index++;
private User userSelection() {
for(int i = index; i < index + users.size(); i++) {
User user = users.get(index % (users.size()));
if(!user.getPacketsToSend().isEmpty()) {
index = i;
return user;
}
}
//on retourne l'utilisateur
return users.get(index%(users.size() - 1));
return null;
}
}