Python Forum
python result problem of an iteration algorithm for power allocation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python result problem of an iteration algorithm for power allocation
#1
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 += 1
The 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

Output:
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
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Algorithm for extracting comments from Python source code Pavel1982 6 524 Feb-28-2024, 09:52 PM
Last Post: Pavel1982
  Python Coding in Power BI Visual vjrans 0 274 Jan-31-2024, 07:54 AM
Last Post: vjrans
  Power Shells vs Compile and Run programs? RockBlok 2 371 Jan-13-2024, 09:08 PM
Last Post: RockBlok
Question Python and Power BI Desktop dangermaus33 1 1,309 Jan-19-2023, 06:54 AM
Last Post: GetOnData
  Floor approximation problem in algorithm gradlon93 3 947 Dec-14-2022, 07:48 PM
Last Post: Gribouillis
  Rock paper scissors in python with "algorithm" Agat0 23 6,045 Mar-01-2022, 03:20 PM
Last Post: Agat0
  Problem using two-dimensional interpolation. Result looks bad player1682 4 2,509 Oct-12-2021, 09:27 AM
Last Post: player1682
Big Grin question about simple algorithm to my problem jamie_01 1 1,671 Oct-04-2021, 11:55 AM
Last Post: deanhystad
  Raising numbers to power ** GJG 3 2,441 Mar-23-2021, 03:43 PM
Last Post: deanhystad
  list call problem in generator function using iteration and recursive calls postta 1 1,905 Oct-24-2020, 09:33 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020