以下算法用于5G网络中的功率分配
N=int(input("the number of station in the cell is "))
M=int(input("the number of users in the cell is "))
Bs=int(input("the number of base station BS is "))
Vo=int(input("the number of users connected to the base station BS is "))
d_om = np.zeros((Bs,Vo)) # distance between the users and the base station
P_om = np.zeros((Bs,Vo)) # the power allocated from the BS to the user
beta_om = np.zeros((Bs,Vo)) # the path-loss between the BS and the user
X_om=np.zeros((Bs,Vo)) # user association if the user is connected x_om=1 else x_om=0
Rom = np.zeros((Bs,Vo)) # the rate of the user from the BS
am= np.zeros((Bs,Vo)) # the base station itself if am>0 x_om=1
numm=np.zeros((Bs,Vo))
rate=np.zeros((Bs,Vo))
B0= np.zeros((Bs,Vo)) # the bandwidth of the BS
Rreq=10000000 # the required rate
P_max=20 # the maximum allocated power
nb_max_iter = 1000
P_om[0,0]=2 # initialization of the allocated power
for b in range(1,Bs+1):
for m in range(1,Vo+1):
B0[b-1][m-1]=20000000
dom=[]
for b in range(1,Bs+1):
for m in range(1,Vo+1):
d_om[b-1][m-1]=random.uniform(5,10)
dom= d_om.tolist()
def pathlossOM(Bs,Vo):
betaom=[]
for b in range (1,Bs+1):
for l in range(1,Vo+1):
beta_om[b-1][m-1]= 0.25**2/(1 + (16*((3.18)**2) * math.log (d_om[b-1][m-1])))
betaom= beta_om.tolist()
print('pathloss=',betaom)
return(betaom)
def I0 (Bs,Vo): # interference of the BS 0
I0=0
sumBS = 0
beta_om = pathlossOM(Bs,Vo)
for b in range (1,Bs+1):
for m in range(1,Vo+1):
sumBS = sumBS+ beta_om[b-1][m-1]
I0= I0 +7*20*sumBS
print('interference I0=',I0)
return(I0)
def Cm(Bs,Vo): # constant to calculate the allocated power
Interf = I0 (Bs,Vo)
beta_om = pathlossOM(Bs,Vo)
for b in range(1,Bs+1):
for m in range (1,Vo+1):
Cm = beta_om[b-1][m-1]/Interf
return (Cm)
nb_max_iter = 1000 # Nb max d'iteration
eps = 0.0001 # stop condition
a0=0
n_a0=0
n0=0
m0=0
l0=0
u0=0
aL=[]
n_a0List=[]
n0List=[]
m0List=[]
l0List=[]
Ra=[]
cond = eps + 10.0 # start with cond greater than eps (assumption)
t = 0
Power=[]
P_om[0][0]=2
X_om[0][0]=0
X0=0
P0=0
u0=1
cm=[]
cm.append(Cm(Bs,Vo))
Interf = I0 (Bs,Vo)
while t < nb_max_iter:
for b in range(1,Bs+1):
for m in range(1,Vo+1):
am[b-1,m-1]=Rom[b-1,m-1] - n0 + (m0 * Rom[b-1,m-1])
print('station a0m=', am)
aL=am.tolist()
print('liste des station aL',aL)
a0=np.argmax(aL[b-1][m-1]) # helps UEs to determine which station am (BS) is delivering the best service to each of them.
n_a0 = n_a0+ np.argmax(n0) # used by station a0 (BS) to choose the specific number of UEs with which to associate.
print('nbr of connected users n0=', n_a0)
n_a0List.append(n_a0)
n0= n0- t*(n_a0 - X0) # Lagrangian multiplier
print('LM nu0=', n0)
n0List.append(n0)
print('liste of LM n0list=',n0List)
m0= m0- t*(X_om[b-1,m-1]* Rom[b-1,m-1] - Rreq) # Lagrangian multiplier
m0List.append(m0)
print('liste des LM m0list=',m0List)
l0= l0- t*(P_max - (X0* P0 )) # Lagrangian multiplier
l0List.append(l0)
print('liste des LM l0list=',l0List)
if a0 > 0:
X_om[b-1,m-1] =1
X0 =X0+ X_om[b-1,m-1]
if X_om[b-1,m-1] == 1:
P_om[b-1,m-1]= ((B0[b-1,m-1]/u0)- (1/Cm[b-1,m-1]))
Power=P_om.tolist()
u0= u0 - t (P_max - P0 ) # Lagrangian multiplier
Rom[b-1,m-1]= B0[b-1,m-1] * math.log2(1+((P_om[b-1,m-1] * beta_om[b-1,m-1])/Interf)) # rate of user m
Ra= Rom.tolist() # list of rate of every connected user
print('liste de rate daccess link R', Ra)
P0=P0+ P_om[b-1,m-1]
print('list de power POM=', Power)
print('rate Rom=',Rom[b-1,m-1] )
print('list of rate of the access link R', Ra)
t += 1
我遇到的问题是,仿真结果在每次迭代中都给我全零。我改变了算法,试图找到确切的问题在哪里,但是我找不到。
我什至尝试初始化路径损耗betaom [0] [0]和速率Rom [0] [0],但没有帮助。 您能帮我找到问题吗? 已有一个月了
number of station in the cell is 3
number of users in the cell is 5
number of base station BS is 1
number of user connected to the BS 2
pathlossOK= 0.0026769849523253556
pathloss= [[0.00017875986054110237, 0.00022240919714050438]]
inter I0= 0.056163668075424944
pathloss= [[0.00017875986054110237, 0.00022240919714050438]]
pathloss= [[0.00017875986054110237, 0.00022240919714050438]]
inter I0= 0.056163668075424944
station a0m= [[0. 0.]]
list of station aL [[0.0, 0.0]]
station a0= 0
nbr of users connected n0= 0
LM nu0= 0
t= 0
list of LM n0list= [0]
LM mu0= 0.0
list of LM m0list= [0.0]
LM lamda0= 0
list of LM l0list= [0]
power Pom= 2.0
list of power POM= []
rate Rom= 0.0
list of rate of the access link R []
station a0m= [[0. 0.]]
list of station aL [[0.0, 0.0]]
station a0= 0
nbr of users connected n0= 0
LM nu0= 0
t= 0
list of LM n0list= [0, 0]
LM mu0= 0.0
list of LM m0list= [0.0, 0.0]
LM lamda0= 0
list of LM l0list= [0, 0]
power Pom= 0.0
list of power POM= []
rate Rom= 0.0
list of rate of the access link R []
t= 1
station a0m= [[0. 0.]]
list of station aL [[0.0, 0.0]]
station a0= 0
nbr of users connected n0= 0
LM nu0= 0
t= 1
list of LM n0list= [0, 0, 0]
LM mu0= 10000000.0
list of LM m0list= [0.0, 0.0, 10000000.0]
LM lamda0= -20
list of LM l0list= [0, 0, -20]
power Pom= 2.0
list of power POM= []
rate Rom= 0.0
list of rate daccess link R []
station a0m= [[0. 0.]]
list of station aL [[0.0, 0.0]]
station a0= 0
nbr of users connected n0= 0
LM nu0= 0
t= 1
liste of LM n0list= [0, 0, 0, 0]
LM mu0= 20000000.0
liste of LM m0list= [0.0, 0.0, 10000000.0, 20000000.0]
LM lamda0= -40
liste of LM l0list= [0, 0, -20, -40]
power Pom= 0.0
list of power POM= []
rate Rom= 0.0
list of rate daccess link R []
t= 2