![]() |
python result problem of an iteration algorithm for power allocation - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: python result problem of an iteration algorithm for power allocation (/thread-12690.html) |
python result problem of an iteration algorithm for power allocation - Jessica - Sep-07-2018 The following algorithm is for power allocation in a 5G network 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 += 1The problem that I have is that the simulation results gives me all zeros in every iteration. I changed the algorithm and tried to find where the exact problem is, but I couldn't. I even tried to initialize the path-loss betaom[0][0] and the rate Rom[0][0] but nothing help. Can you please help me to find the problem? it's been a month now
RE: python result problem of an iteration algorithm for power allocation - micseydel - Sep-07-2018 Can you reproduce your problem in 20 or fewer lines? Debugging 100+ lines is very difficult, even for professional software engineers with years of experience. Any simplification is progress, the shorter the better, and no code after the problem pops up is necessary for initial debugging. (Also, please use code tags for any new code you post.) Also, can you provide a snippet of text which represents what you type into the keyboard? On Linux / OS X at least, it's very easy to run a whole script with an input file rather than having to type it out again each time. |