-
Notifications
You must be signed in to change notification settings - Fork 16
/
example_JSPA.py
145 lines (113 loc) · 5.01 KB
/
example_JSPA.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 26 14:11:15 2018
@author: lsalaun
© 2016 - 2020 Nokia
Licensed under Creative Commons Attribution Non Commercial 4.0 International
SPDX-License-Identifier: CC-BY-NC-4.0
"""
import numpy as np
import generate_gains
import channel_allocation_JSPA as ca_jspa
K = 2 # Number of users
L = 10 # Number of subcarriers
Multiplex = 1 # Number of users per subcarrier
# Radius of the cell
Radius = 1000
# Min distance between user and BS = 35 m
rmin = 35
np.random.seed(0) # Seed
G = generate_gains.generateGains(K,L,Radius,rmin)
# B : total bandwidth = 5 MHz
B = 5*10**6
W = np.ones(L)*B/L
# Noise value per Hertz = -174 dBm/Hz
Noise_Hz = 10**((-174-30)/10)
N = np.ones(K*L)*Noise_Hz*B/L
N_G = ca_jspa.computeN_G(G,N)
# Decoding order
pi,pi_inv = ca_jspa.computePi(G,N)
# Random weights
w = np.random.rand(K)
# Power budget
Pmax = 1
# Power budget per subcarrier
PmaxN = Pmax*np.ones(L)
print('pi =\n',pi)
print('w =',w)
print('G =\n',G)
print('\n----------------------- opt_JSPA with delta = 0.01 -----------------------')
# Power discretization step
delta = 0.01
power, wsr, countSCUS, countDP = ca_jspa.opt_JSPA(K,L,Multiplex,Pmax,PmaxN,N_G,pi,pi_inv,w,W,delta)
print()
print('WSR performance:',np.sum(wsr))
print('Power allocated to each subcarrier:',power)
print('Number of SCUS evaluations performed:',countSCUS)
print('Number of iterations (for loops) in the dynamic programming:',countDP)
print('\n----------------------- opt_JSPA with delta = 0.001 -----------------------')
# Power discretization step
delta = 0.001
power, wsr, countSCUS, countDP = ca_jspa.opt_JSPA(K,L,Multiplex,Pmax,PmaxN,N_G,pi,pi_inv,w,W,delta)
print()
print('WSR performance:',np.sum(wsr))
print('Power allocated to each subcarrier:',power)
print('Number of SCUS evaluations performed:',countSCUS)
print('Number of iterations (for loops) in the dynamic programming:',countDP)
print('\n----------------------- epsilon_JSPA with espilon = 0.1 -----------------------')
# Approx epsilon
epsilon = 0.1
power, wsr, countSCUS, countNormWSR, countDP = ca_jspa.epsilon_JSPA(K,L,Multiplex,Pmax,PmaxN,N_G,pi,pi_inv,w,W,epsilon)
print()
print('WSR performance:',np.sum(wsr))
print('Power allocated to each subcarrier:',power)
print('Number of SCUS evaluations performed:',countSCUS)
print('Number of computed WSR values:',countNormWSR)
print('Number of iterations (for loops) in the dynamic programming:',countDP)
print('\n----------------------- epsilon_JSPA with espilon = 0.01 -----------------------')
# Approx epsilon
epsilon = 0.01
power, wsr, countSCUS, countNormWSR, countDP = ca_jspa.epsilon_JSPA(K,L,Multiplex,Pmax,PmaxN,N_G,pi,pi_inv,w,W,epsilon)
print()
print('WSR performance:',np.sum(wsr))
print('Power allocated to each subcarrier:',power)
print('Number of SCUS evaluations performed:',countSCUS)
print('Number of computed WSR values:',countNormWSR)
print('Number of iterations (for loops) in the dynamic programming:',countDP)
print('\n----------------------- Grad_JSPA with delta = 0.001, with rounding_step = 0.01 -----------------------')
# Error tolerance at termination
delta = 0.001
power, wsr, countIters, countSCUS = ca_jspa.SpeedUp_Grad_JSPA(K,L,Multiplex,Pmax,N_G,pi,pi_inv,w,W,delta,rounding_step=0.01)
print()
print('WSR performance:',np.sum(wsr))
print('Power allocated to each subcarrier:',power)
print('Number of gradient iterations:',countIters)
print('Number of SCUS evaluations performed:',countSCUS)
# The following Grad_JSPA gives the same result but with larger running time since it uses the basic SCUS instead of SpeedUpSCUS
# power, wsr, countIters, countSCUS = ca_jspa.Grad_JSPA(K,L,Multiplex,Pmax,N_G,pi,pi_inv,w,W,delta,rounding_step=0.01)
# print()
# print('WSR performance:',np.sum(wsr))
# print('Power allocated to each subcarrier:',power)
# print('Number of gradient iterations:',countIters)
# print('Number of SCUS evaluations performed:',countSCUS)
print('\n----------------------- Grad_JSPA with delta = 0.001, without rounding -----------------------')
# Error tolerance at termination
delta = 0.001
power, wsr, countIters, countSCUS = ca_jspa.SpeedUp_Grad_JSPA(K,L,Multiplex,Pmax,N_G,pi,pi_inv,w,W,delta,rounding_step=None)
print()
print('WSR performance:',np.sum(wsr))
print('Power allocated to each subcarrier:',power)
print('Number of gradient iterations:',countIters)
print('Number of SCUS evaluations performed:',countSCUS)
# The following Grad_JSPA gives the same result but with larger running time since it uses the basic SCUS instead of SpeedUpSCUS
# power, wsr, countIters, countSCUS = ca_jspa.Grad_JSPA(K,L,Multiplex,Pmax,N_G,pi,pi_inv,w,W,delta,rounding_step=None)
# print()
# print('WSR performance:',np.sum(wsr))
# print('Power allocated to each subcarrier:',power)
# print('Number of gradient iterations:',countIters)
# print('Number of SCUS evaluations performed:',countSCUS)
print('\n----------------------- eqPow_JSPA -----------------------')
power, wsr = ca_jspa.eqPow_JSPA(K,L,Multiplex,Pmax,N_G,pi,pi_inv,w,W)
print()
print('WSR performance:',np.sum(wsr))
print('Power allocated to each subcarrier:',power)