功率分配迭代算法的python结果问题

功率分配迭代算法的python结果问题,python,Python,以下算法适用于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

以下算法适用于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

您能提供一些示例输入,以及您期望的输出类型吗?输入为B0=20000000#基站的带宽Rreq=10000000#所需速率P#max=20#最大分配功率nb#max#iter=1000 P#om[0,0]=2输出功率为P_om,单位为瓦特,速率为Rom bit/sOk,所以我一直在努力解决这个问题。我有一些问题:1。你能修正一下你的代码缩进吗?所有代码都缩进了一次。2.在你发布的代码的第124行,你写了
u0=u0-t(P\u max-P0)
你的意思是
u0=u0-t*(P\u max-P0)
?3.在第121行,您使用
Cm[b-1,m-1]
作为数组或2D张量,但是您没有初始化数组,只有
Cm()
作为函数4。在第126行,您使用变量
Interf
,它在while循环之前计算过一次,并且永远不会再更新,对吗?至于指针,我会确保您的所有函数输出都是浮动的,并且没有整数的数值计算,因为
1/2
将为您提供
0
,依此类推。他们会四舍五入,然后一个微小的错误会导致到处都是零乘法。对于你的第二个问题,是的,我想写u0=u0-t*(P_max-P0)。对于第三个问题,Cm[b-1,m-1]是一个矩阵,我把函数Cm的结果放在一个列表Cm.append(Cm(Bs,Vo))中,因为结果应该是一个标量,对于Interf它是一个常数(float)
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