Compare commits
8 Commits
83e4ccdd22
...
431248b0a4
Author | SHA1 | Date | |
---|---|---|---|
|
431248b0a4 | ||
|
cc73eb8a93 | ||
|
376c76b17c | ||
|
5b695174a6 | ||
b073d58f21 | |||
05d51acdc0 | |||
5597bfa93e | |||
af11fa37f3 |
36
plot/main.py
36
plot/main.py
@ -45,6 +45,21 @@ def delay(arr: list[tuple[int, np.ndarray]]) -> np.ndarray:
|
|||||||
nb += 1
|
nb += 1
|
||||||
return delays
|
return delays
|
||||||
|
|
||||||
|
def rb_allocate_distance(arr: list[tuple[int, np.ndarray]], distance) -> np.ndarray:
|
||||||
|
allocate = np.zeros((size, 2))
|
||||||
|
nb = 0
|
||||||
|
arr.sort()
|
||||||
|
for nb_users, data in arr:
|
||||||
|
n = 0
|
||||||
|
for x in data[:,6]:
|
||||||
|
if int(x) == distance:
|
||||||
|
n+=1
|
||||||
|
allocate[nb, 0] = nb_users
|
||||||
|
allocate[nb, 1] = n
|
||||||
|
print(n/data.shape[0])
|
||||||
|
nb += 1
|
||||||
|
return allocate
|
||||||
|
|
||||||
|
|
||||||
np_arr: list[tuple[int, np.ndarray]] = list()
|
np_arr: list[tuple[int, np.ndarray]] = list()
|
||||||
for i in nb_files:
|
for i in nb_files:
|
||||||
@ -52,6 +67,13 @@ for i in nb_files:
|
|||||||
|
|
||||||
averages = mean_mkn(np_arr)
|
averages = mean_mkn(np_arr)
|
||||||
available = rb_available(np_arr)
|
available = rb_available(np_arr)
|
||||||
|
|
||||||
|
allocate_lp1 = rb_allocate_distance(np_arr, 200)
|
||||||
|
allocate_lp2 = rb_allocate_distance(np_arr, 400)
|
||||||
|
allocate_total = allocate_lp1[:, 1] + allocate_lp2[:, 1]
|
||||||
|
|
||||||
|
print(allocate_total)
|
||||||
|
|
||||||
delays = delay(np_arr)
|
delays = delay(np_arr)
|
||||||
delays.sort(axis=0)
|
delays.sort(axis=0)
|
||||||
# Data for plotting
|
# Data for plotting
|
||||||
@ -70,4 +92,18 @@ ax[1, 0].scatter(delays[:, 0], delays[:, 1])
|
|||||||
ax[1, 0].set(xlabel='number of users', ylabel='delays(ms)', title='Delay')
|
ax[1, 0].set(xlabel='number of users', ylabel='delays(ms)', title='Delay')
|
||||||
ax[1, 0].grid()
|
ax[1, 0].grid()
|
||||||
|
|
||||||
|
available.sort(axis=0)
|
||||||
|
|
||||||
|
#ax[1, 1].scatter(allocate_lp1[:, 0], (allocate_lp1[:, 1]/(allocate_lp1[:, 1])+allocate_lp2[:, 1])*100)
|
||||||
|
|
||||||
|
ax[1, 1].plot(available[:, 0], (allocate_lp1[:, 1]/(allocate_lp1[:, 1]+allocate_lp2[:, 1])*100))
|
||||||
|
|
||||||
|
#ax[1, 1].scatter(allocate_lp2[:, 0], (allocate_lp2[:, 1]/(allocate_lp1[:, 1])+allocate_lp2[:, 1])*100)
|
||||||
|
|
||||||
|
ax[1, 1].plot(available[:, 0], (allocate_lp2[:, 1]/(allocate_lp1[:, 1]+allocate_lp2[:, 1])*100))
|
||||||
|
|
||||||
|
ax[1, 1].set(xlabel='number of users', ylabel='RB utilisés proche/loin/total', title='RB utilisés distance')
|
||||||
|
ax[1, 1].grid()
|
||||||
|
|
||||||
|
plt.ylim(0, 100)
|
||||||
plt.show()
|
plt.show()
|
@ -1,5 +1,7 @@
|
|||||||
package fr.ntr;
|
package fr.ntr;
|
||||||
|
|
||||||
|
import fr.ntr.scheduler.MaxSNR;
|
||||||
|
import fr.ntr.scheduler.ProportionalFair;
|
||||||
import fr.ntr.scheduler.RoundRobin;
|
import fr.ntr.scheduler.RoundRobin;
|
||||||
import fr.ntr.scheduler.Scheduler;
|
import fr.ntr.scheduler.Scheduler;
|
||||||
|
|
||||||
@ -10,6 +12,7 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
@ -44,16 +47,23 @@ public class Main {
|
|||||||
});
|
});
|
||||||
AccessPoint.setTimeSlotNb(timeSlotNb);
|
AccessPoint.setTimeSlotNb(timeSlotNb);
|
||||||
AccessPoint.setSubCarrierNb(subCarrierNb);
|
AccessPoint.setSubCarrierNb(subCarrierNb);
|
||||||
try(ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())) {
|
ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||||
for(int i = 2; i <= maximumLoad; i += 2) {
|
for(int i = 2; i <= maximumLoad; i += 2) {
|
||||||
List<User> users = generateUsers(i, timeSlotNb, subCarrierNb);
|
List<User> users = generateUsers(i, timeSlotNb, subCarrierNb);
|
||||||
ResourceBlock[][] frame = new ResourceBlock[timeSlotNb][subCarrierNb];
|
ResourceBlock[][] frame = new ResourceBlock[timeSlotNb][subCarrierNb];
|
||||||
// Scheduler scheduler = new MaxSNR(frame, users);
|
//Scheduler scheduler = new MaxSNR(frame, users);
|
||||||
// Scheduler scheduler = new ProportionalFair(frame, users);
|
//Scheduler scheduler = new ProportionalFair(frame, users);
|
||||||
Scheduler scheduler = new RoundRobin(frame, users);
|
Scheduler scheduler = new RoundRobin(frame, users);
|
||||||
AccessPoint accessPoint = new AccessPoint(scheduler, frame, users);
|
AccessPoint accessPoint = new AccessPoint(scheduler, frame, users);
|
||||||
executor.submit(() -> accessPoint.startSimulation(numberOfTicks));
|
executor.submit(() -> accessPoint.startSimulation(numberOfTicks));
|
||||||
|
}
|
||||||
|
executor.shutdown();
|
||||||
|
try {
|
||||||
|
if(!executor.awaitTermination(2, TimeUnit.MINUTES)) {
|
||||||
|
executor.shutdownNow();
|
||||||
}
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.err.println("Please give launch arguments");
|
System.err.println("Please give launch arguments");
|
||||||
@ -75,4 +85,6 @@ public class Main {
|
|||||||
|
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,18 +1,18 @@
|
|||||||
package fr.ntr.scheduler;
|
package fr.ntr.scheduler;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import fr.ntr.Packets;
|
import fr.ntr.AccessPoint;
|
||||||
import fr.ntr.ResourceBlock;
|
import fr.ntr.ResourceBlock;
|
||||||
import fr.ntr.User;
|
import fr.ntr.User;
|
||||||
|
|
||||||
public class MaxSNR extends Scheduler {
|
public class MaxSNR extends Scheduler {
|
||||||
|
|
||||||
private List<User> users;
|
private final List<User> users;
|
||||||
|
|
||||||
private ResourceBlock[][] frame;
|
private final ResourceBlock[][] frame;
|
||||||
|
|
||||||
|
|
||||||
public MaxSNR( ResourceBlock[][] frame, List<User> users) {
|
public MaxSNR(ResourceBlock[][] frame, List<User> users) {
|
||||||
this.frame = frame;
|
this.frame = frame;
|
||||||
this.users = users;
|
this.users = users;
|
||||||
}
|
}
|
||||||
@ -20,8 +20,8 @@ public class MaxSNR extends Scheduler {
|
|||||||
@Override
|
@Override
|
||||||
public void scheduling(int ticks) {
|
public void scheduling(int ticks) {
|
||||||
User userMax;
|
User userMax;
|
||||||
for(int ts = 0; ts < 2; ts++){
|
for(int ts = 0; ts < AccessPoint.getTimeSlotNb(); ts++){
|
||||||
for(int sp = 0; sp < 100; sp++){
|
for(int sp = 0; sp < AccessPoint.getSubCarrierNb(); sp++){
|
||||||
userMax = userSelection(ts, sp);
|
userMax = userSelection(ts, sp);
|
||||||
allocateRessource(userMax, frame, ts, sp, ticks);
|
allocateRessource(userMax, frame, ts, sp, ticks);
|
||||||
}
|
}
|
||||||
@ -36,11 +36,10 @@ public class MaxSNR extends Scheduler {
|
|||||||
double maxSnr = 0.0;
|
double maxSnr = 0.0;
|
||||||
User userMax = null;
|
User userMax = null;
|
||||||
for(User u: users) {
|
for(User u: users) {
|
||||||
if (!u.getPacketsToSend().isEmpty()) {
|
if (!u.getPacketsToSend().isEmpty() && (maxSnr < u.getBandwidthTable()[ts][sp])) {
|
||||||
if (maxSnr < u.getBandwidthTable()[ts][sp]) {
|
maxSnr = u.getBandwidthTable()[ts][sp];
|
||||||
maxSnr = u.getBandwidthTable()[ts][sp];
|
userMax = u;
|
||||||
userMax = u;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return userMax;
|
return userMax;
|
||||||
|
@ -3,57 +3,51 @@ package fr.ntr.scheduler;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import fr.ntr.AccessPoint;
|
||||||
import fr.ntr.ResourceBlock;
|
import fr.ntr.ResourceBlock;
|
||||||
import fr.ntr.User;
|
import fr.ntr.User;
|
||||||
|
|
||||||
public class ProportionalFair extends Scheduler {
|
public class ProportionalFair extends Scheduler {
|
||||||
|
|
||||||
|
private final List<User> users;
|
||||||
|
|
||||||
private List<User> users;
|
private final ResourceBlock[][] frame;
|
||||||
|
|
||||||
private ResourceBlock[][] frame;
|
|
||||||
|
|
||||||
public ProportionalFair(ResourceBlock[][] frame, List<User> users) {
|
public ProportionalFair(ResourceBlock[][] frame, List<User> users) {
|
||||||
this.frame = frame;
|
this.frame = frame;
|
||||||
this.users = users;
|
this.users = users;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void scheduling(int ticks) {
|
public void scheduling(int ticks) {
|
||||||
ArrayList<Double> averageBandwiths = new ArrayList<Double>();
|
for(int ts = 0; ts < AccessPoint.getTimeSlotNb(); ts++){
|
||||||
for(User u : users){
|
for(int sp = 0; sp < AccessPoint.getSubCarrierNb(); sp++){
|
||||||
double avg = 0d;
|
User selectedUser = userSelection(ts, sp, users);
|
||||||
double[][] bandwidthTable = u.getBandwidthTable();
|
|
||||||
for(int i = 0; i < bandwidthTable.length; i++){
|
|
||||||
for(int j = 0; j < bandwidthTable[i].length; j++){
|
|
||||||
avg += bandwidthTable[i][j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
avg = avg / (bandwidthTable.length * bandwidthTable[0].length);
|
|
||||||
averageBandwiths.add(avg);
|
|
||||||
}
|
|
||||||
for(int ts = 0; ts < 2; ts++){
|
|
||||||
for(int sp = 0; sp < 100; sp++){
|
|
||||||
User selectedUser = userSelection(ts, sp, users, averageBandwiths);
|
|
||||||
allocateRessource(selectedUser, frame, ts, sp, ticks);
|
allocateRessource(selectedUser, frame, ts, sp, ticks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private User userSelection(int ts, int sp, List<User> users, List<Double> averageBandwiths) {
|
private User userSelection(int ts, int sp, List<User> users) {
|
||||||
double PF = 0.0;
|
double PF = 0.0;
|
||||||
User selectedUser = null;
|
User selectedUser = null;
|
||||||
for(int i = 0; i < users.size(); i++){
|
for (User u : users) {
|
||||||
User u = users.get(i);
|
double avg = 0d;
|
||||||
|
double[][] bandwidthTable = u.getBandwidthTable();
|
||||||
|
for (double[] doubles : bandwidthTable) {
|
||||||
|
for (double aDouble : doubles) {
|
||||||
|
avg += aDouble;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
avg = avg / (bandwidthTable.length * bandwidthTable[0].length);
|
||||||
double mkn = u.getBandwidthTable()[ts][sp];
|
double mkn = u.getBandwidthTable()[ts][sp];
|
||||||
double averageMkn = averageBandwiths.get(i);
|
double pf = mkn / avg;
|
||||||
double pf = mkn / averageMkn;
|
if (PF < pf) {
|
||||||
if (PF < pf){
|
|
||||||
PF = pf;
|
PF = pf;
|
||||||
selectedUser = u;
|
selectedUser = u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return selectedUser;
|
return selectedUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,18 +16,8 @@ public abstract class Scheduler {
|
|||||||
protected void allocateRessource(User userMax, ResourceBlock[][] frame, int ts, int sp, int ticks) {
|
protected void allocateRessource(User userMax, ResourceBlock[][] frame, int ts, int sp, int ticks) {
|
||||||
if (userMax != null && !userMax.getPacketsToSend().isEmpty()) {
|
if (userMax != null && !userMax.getPacketsToSend().isEmpty()) {
|
||||||
Packets p = userMax.getPacketsToSend().get(userMax.getPacketsToSend().size()-1);
|
Packets p = userMax.getPacketsToSend().get(userMax.getPacketsToSend().size()-1);
|
||||||
if(p.getBitsNumberRemaining() >= 0){
|
p.decreaseBitsNumberRemaining((int) userMax.getBandwidthTable()[ts][sp]);
|
||||||
p.decreaseBitsNumberRemaining((int) userMax.getBandwidthTable()[ts][sp]);
|
if(p.getBitsNumberRemaining() <= 0) {
|
||||||
if(p.getBitsNumberRemaining() <= 0) {
|
|
||||||
if(ticks == 0){
|
|
||||||
p.setDurationSending(1);
|
|
||||||
}else {
|
|
||||||
p.setDurationSending(ticks);
|
|
||||||
}
|
|
||||||
userMax.getPacketsSent().add(p);
|
|
||||||
userMax.getPacketsToSend().remove(p);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(ticks == 0){
|
if(ticks == 0){
|
||||||
p.setDurationSending(1);
|
p.setDurationSending(1);
|
||||||
}else {
|
}else {
|
||||||
|
Reference in New Issue
Block a user