Example #1
0
def main():
    ### Global ###
    plotting = False
    configPath = 'configure/settingsRAPSmulticell.cfg'
    shutil.copyfile(configPath, outpath +
                    os.path.basename(configPath))  # save configuration
    np.set_printoptions(precision=2)
    repetitions = 1  # usually, condor handles the repetitions

    ### Prealloc ###
    init_logging(outpath)
    wconf = wconfig.Wconfig(configPath)
    phy_ = phy.PHY(configPath)
    rate = wconf.user_rate  # bps
    iterations = phy_.iterations
    resultRAPS = np.empty(
        [repetitions + 1, iterations + 1]
    )  # one repetition for the axis. one iteration for the starting consumption.
    resultAchieved = np.empty(
        [repetitions + 1, iterations + 1]
    )  # one repetition for the axis. one iteration for the starting consumption.
    resultRAPS[0, :] = np.arange(iterations +
                                 1) + 1  # print index in first row
    resultAchieved[0, :] = np.arange(iterations +
                                     1) + 1  # print index in first row
    resultAchieved[1:, 0] = np.nan
    resultBA = np.empty([repetitions])

    if wconf.initial_power == 'zero':
        resultRAPS[1:, 0] = wconf.pS  # we assume the BS was asleep
    elif wconf.initial_power == 'full':
        resultRAPS[1:, 0] = wconf.p0 + wconf.m * 40  # the BS was at full power
    else:
        resultRAPS[1:, 0] = np.nan
    mobileSINRs = []
    mobile_effSINRs = []
    widebandSINRlist = []

    for i in np.arange(iterations + 1):  # prealloc list of lists
        mobileSINRs.append([])
        mobile_effSINRs.append([])
        widebandSINRlist.append([])
    mobileSINRs.pop()

    for r in np.arange(repetitions) + 1:
        ### Generate world ###
        if wconf.load_world:
            logger.info('Loading world from file: ' + wconf.load_world)
            wrld = loadprecomputedworld.load(wconf.load_world)
            wrld.update_operating_parameters(wconf)
        else:
            wrld = world.World(wconf, phy_)
            wrld.associatePathlosses()
            wrld.calculateSINRs()
            wrld.fix_center_cell_users()  # set 0 in settings file to disable

        ### Show world ###
        if plotting:
            from plotting import networkplotter
            networkplotter.NetworkPlotter().plotAssociatedMobiles(
                wrld, outpath + 'rep' + str(r) + '_associatedMobiles')
            for cell in wrld.consideredCells:
                plotPowerProfile(cell, 1, 0, resultRAPS[1, 0])

        # collect SINRs for CDF
        li = [
            list(mob.OFDMA_effSINR.ravel()) for mob in wrld.consideredMobiles
        ]
        li = sum(li, [])  # flatten list of lists
        mobile_effSINRs[0].extend(li)
        widebandSINRlist[0].append(
            [mob.SINR for mob in wrld.consideredMobiles])

        ### Run ###
        for i in np.arange(1, iterations + 1):

            logger.info('*' * 80)
            logger.info('Iteration ' + str(i) + ':')
            logger.info('Considered cells: ' + str(wrld.consideredCells))
            logger.info('*' * 80)

            ### Each cell performs RAPS independently ###
            for cell in wrld.cells:
                logger.info('Cell ID: ' + str(cell.cellid))
                mobiles = [mob for mob in wrld.mobiles if mob.cell == cell]

                try:
                    resultOpt, resultQu = raps.raps(
                        wrld, cell, mobiles, rate,
                        plotting=plotting)  # changes the wrld object
                    resBA = ba.ba(
                        rate, wrld, cell, mobiles, len(mobiles)
                    )  # BA ignores the actual cell transmission powers
                except ValueError as err:
                    logger.warning(err)
                    resultOpt = np.nan
                    resultQu = np.nan
                    resBA = np.nan
                    # no solution could be found
                except IndexError:
                    logger.info('By chance there is no mobile in the cell.')
                    cell.OFDMA_power[:] = 0
                except:
                    logger.error(sys.exc_info())
                    raise
                if cell in wrld.consideredCells:
                    if plotting:
                        plotPowerProfile(cell, r, i, resultQu)

                    # collect data
                    resultRAPS[r, i] = resultQu
                    resultBA[r - 1] = resBA
                    # TODO: collect number of used RBs

            if i != iterations:
                # all cells should have adjusted their transmission powers, so there are new SINRs
                wrld.updateMobileFSF(i)

            # collect SINRs for CDF
            wrld.calculateSINRs()
            li = [
                list(mob.OFDMA_SINR.ravel()) for mob in wrld.consideredMobiles
            ]
            li = sum(li, [])  # flatten list of lists
            mobileSINRs[i - 1].extend(li)
            li = [
                list(mob.OFDMA_effSINR.ravel())
                for mob in wrld.consideredMobiles
            ]
            li = sum(li, [])  # flatten list of lists
            mobile_effSINRs[i].extend(li)

            # check actual achieved rates with this allocation
            for cell in wrld.cells:
                mobiles = [mob for mob in wrld.mobiles if mob.cell == cell]
                target = rate * len(mobiles) * wrld.PHY.simulationTime
                raise NotImplementedError  # capacity must be calculated with actual power allocation
                achieved = ba.achieved_capacity_in_cell(wrld, cell, mobiles)
                if cell in wrld.consideredCells:  # store data
                    resultAchieved[r, i] = achieved
                txt = 'MISS!' if (target > achieved) else 'PASS!'
                logger.info('Target vs. achieved capacity in cell ' +
                            str(cell.cellid) + ': ' + str(target) + ', ' +
                            str(achieved) + '. --> ' + txt)

                # DEBUG
                if achieved > 2 * target:
                    import pdb
                    pdb.set_trace()

    #        plotPowerProfiles(wrld, i)
    #        import pdb; pdb.set_trace()

    ### Finish up ###
    sumrate_data = np.mean(
        resultRAPS[1:, -1])  # average power consumption at the last iteration
    writeFile(outpath + 'sumrateRAPS.csv', sumrate_data)
    np.savetxt(outpath + 'resultRAPS.csv', resultRAPS, delimiter=",")
    np.savetxt(outpath + 'resultBA.csv', resultBA, delimiter=",")
    delivered_data = np.mean(
        resultAchieved[1:,
                       -1])  # average power consumption at the last iteration
    writeFile(outpath + 'delivered_final.csv', str(delivered_data))
    np.savetxt(outpath + 'delivered_individual.csv',
               resultAchieved,
               delimiter=",")
    save_lol(mobileSINRs, outpath + 'mobileSINRs.csv')
    save_lol(mobile_effSINRs, outpath + 'mobile_effSINRs.csv')
    save_lol(widebandSINRlist, outpath + 'wideband_mobileSINRs.csv')

    logger.info('*' * 80)
    logger.info('*' * 80)
    logger.info('Runtime %.0f seconds' % (time.time() - start))
Example #2
0
def main():
    ### Global ###
    plotting = False 
    configPath  = 'configure/settingsRAPSmulticell.cfg'
    shutil.copyfile(configPath, outpath+os.path.basename(configPath)) # save configuration
    np.set_printoptions(precision=2)
    repetitions = 1 # usually, condor handles the repetitions

    ### Prealloc ###
    init_logging(outpath)
    wconf = wconfig.Wconfig(configPath) 
    phy_ = phy.PHY(configPath)
    rate = wconf.user_rate # bps
    iterations = phy_.iterations
    resultRAPS = np.empty([repetitions+1, iterations+1]) # one repetition for the axis. one iteration for the starting consumption.
    resultAchieved = np.empty([repetitions+1, iterations+1]) # one repetition for the axis. one iteration for the starting consumption.
    resultRAPS[0,:] = np.arange(iterations+1)+1 # print index in first row
    resultAchieved[0,:] = np.arange(iterations+1)+1 # print index in first row
    resultAchieved[1:,0] = np.nan
    resultBA = np.empty([repetitions]) 
    
    if wconf.initial_power == 'zero':
        resultRAPS[1:,0] = wconf.pS # we assume the BS was asleep
    elif wconf.initial_power == 'full':
        resultRAPS[1:,0] = wconf.p0 + wconf.m * 40 # the BS was at full power
    else:
        resultRAPS[1:,0] = np.nan
    mobileSINRs = []
    mobile_effSINRs = []
    widebandSINRlist = []

    for i in np.arange(iterations+1): # prealloc list of lists 
        mobileSINRs.append([])
        mobile_effSINRs.append([])
        widebandSINRlist.append([])
    mobileSINRs.pop()

    for r in np.arange(repetitions)+1:
        ### Generate world ###
        if wconf.load_world:
            logger.info('Loading world from file: ' + wconf.load_world)
            wrld = loadprecomputedworld.load(wconf.load_world)
            wrld.update_operating_parameters(wconf)
        else:
            wrld = world.World(wconf, phy_)
            wrld.associatePathlosses()
            wrld.calculateSINRs()
            wrld.fix_center_cell_users() # set 0 in settings file to disable

        ### Show world ###
        if plotting:
            from plotting import networkplotter
            networkplotter.NetworkPlotter().plotAssociatedMobiles(wrld, outpath+'rep'+str(r)+'_associatedMobiles')
            for cell in wrld.consideredCells:
                plotPowerProfile(cell, 1, 0, resultRAPS[1,0])

        # collect SINRs for CDF
        li = [list(mob.OFDMA_effSINR.ravel()) for mob in wrld.consideredMobiles]
        li = sum(li,[]) # flatten list of lists
        mobile_effSINRs[0].extend(li)
        widebandSINRlist[0].append( [mob.SINR for mob in wrld.consideredMobiles])
            
        ### Run ###
        for i in np.arange(1,iterations+1):

            logger.info( '*'*80 )
            logger.info( 'Iteration ' + str(i) + ':' ) 
            logger.info( 'Considered cells: ' + str(wrld.consideredCells) )
            logger.info( '*'*80 )


            ### Each cell performs RAPS independently ###
            for cell in wrld.cells:
                logger.info( 'Cell ID: ' + str(cell.cellid) )
                mobiles = [mob for mob in wrld.mobiles if mob.cell == cell]

                try:
                    resultOpt, resultQu = raps.raps(wrld, cell, mobiles, rate, plotting=plotting) # changes the wrld object
                    resBA = ba.ba(rate, wrld, cell, mobiles, len(mobiles)) # BA ignores the actual cell transmission powers 
                except ValueError as err:
                    logger.warning( err )
                    resultOpt = np.nan 
                    resultQu  = np.nan 
                    resBA  = np.nan 
                    # no solution could be found
                except IndexError:
                    logger.info( 'By chance there is no mobile in the cell.' )
                    cell.OFDMA_power[:] = 0
                except:
                    logger.error(sys.exc_info())
                    raise
                if cell in wrld.consideredCells:
                    if plotting:
                        plotPowerProfile(cell, r, i, resultQu)

                    # collect data
                    resultRAPS[r,i] = resultQu
                    resultBA[r-1] = resBA
                    # TODO: collect number of used RBs

            if i != iterations:
                # all cells should have adjusted their transmission powers, so there are new SINRs
                wrld.updateMobileFSF(i)
        
            # collect SINRs for CDF
            wrld.calculateSINRs()
            li = [list(mob.OFDMA_SINR.ravel()) for mob in wrld.consideredMobiles] 
            li = sum(li,[]) # flatten list of lists
            mobileSINRs[i-1].extend(li)
            li = [list(mob.OFDMA_effSINR.ravel()) for mob in wrld.consideredMobiles] 
            li = sum(li,[]) # flatten list of lists
            mobile_effSINRs[i].extend(li)
            

            # check actual achieved rates with this allocation
            for cell in wrld.cells:
                mobiles = [mob for mob in wrld.mobiles if mob.cell == cell]
                target = rate * len(mobiles) * wrld.PHY.simulationTime
                raise NotImplementedError # capacity must be calculated with actual power allocation
                achieved = ba.achieved_capacity_in_cell(wrld, cell, mobiles)
                if cell in wrld.consideredCells: # store data
                    resultAchieved[r,i] = achieved
                txt = 'MISS!' if (target > achieved) else 'PASS!'
                logger.info('Target vs. achieved capacity in cell ' + str(cell.cellid) + ': ' 
                        + str(target) + ', ' + str(achieved) + '. --> ' + txt) 
                
                # DEBUG
                if achieved > 2 * target:
                    import pdb; pdb.set_trace()

    #        plotPowerProfiles(wrld, i)
    #        import pdb; pdb.set_trace()
        
    ### Finish up ###
    sumrate_data = np.mean(resultRAPS[1:,-1]) # average power consumption at the last iteration
    writeFile(outpath+'sumrateRAPS.csv', sumrate_data)
    np.savetxt(outpath+'resultRAPS.csv', resultRAPS, delimiter=",")
    np.savetxt(outpath+'resultBA.csv', resultBA, delimiter=",")
    delivered_data = np.mean(resultAchieved[1:,-1]) # average power consumption at the last iteration
    writeFile(outpath+'delivered_final.csv', str(delivered_data))
    np.savetxt(outpath+'delivered_individual.csv', resultAchieved, delimiter=",")
    save_lol(mobileSINRs, outpath+'mobileSINRs.csv')
    save_lol(mobile_effSINRs, outpath+'mobile_effSINRs.csv')
    save_lol(widebandSINRlist, outpath+'wideband_mobileSINRs.csv')

    logger.info( '*'*80 )
    logger.info( '*'*80 )
    logger.info( 'Runtime %.0f seconds' % (time.time() - start) )
Example #3
0
def main():
    ### Global ###
    plotting = True 
    configPath  = 'configure/settingsRAPSmulticell.cfg' # specifically use the same settings as RAPS to compare
    shutil.copyfile(configPath, outpath+'settingsPF_dtxmulticell.cfg') # save configuration
    np.set_printoptions(precision=2)
    repetitions = 1

    ### Prealloc ###
    init_logging(outpath)
    wconf = wconfig.Wconfig(configPath) 
    phy_ = phy.PHY(configPath)
    rate = wconf.user_rate # bps
    iterations = phy_.iterations
    resultPF = np.empty([repetitions+1, iterations+1]) 
    resultPF[0,:] = np.arange(iterations+1)+1
    resultPF[1:,0] = wconf.p0 + wconf.m * 40 # the BS was at full power
    mobileSINRs = []
    mobile_effSINRs = []

    for i in np.arange(iterations+1):
        mobileSINRs.append([])
        mobile_effSINRs.append([])
    mobileSINRs.pop()

    for r in np.arange(repetitions)+1:
        ### Generate world ###
        if wconf.load_world:
            logger.info('Loading world from file: ' + wconf.load_world)
            wrld = loadprecomputedworld.load(wconf.load_world)
            wrld.update_operating_parameters(wconf)
        else:
            wrld  = world.World(wconf, phy_)
            wrld.associatePathlosses()
            wrld.calculateSINRs()
            wrld.fix_center_cell_users() # set 0 to disable

        ### Show world ###
        if plotting:
            from plotting import networkplotter
            networkplotter.NetworkPlotter().plotAssociatedMobiles(wrld, outpath+'PF_rep'+str(r)+'_associatedMobiles')
            for cell in wrld.cells:
                if cell in wrld.consideredCells:
                    plotPowerProfile(cell, 1, 0, resultPF[1,0])

        # collect SINRs for CDF
        li = [list(mob.OFDMA_effSINR.ravel()) for mob in wrld.consideredMobiles]
        li = sum(li,[]) # flatten list of lists
        mobile_effSINRs[0].extend(li)

        ### Run ###
        for i in np.arange(1,iterations+1):

            logger.info( '*'*80 )
            logger.info( 'Process ID: ' + pid_ )
            logger.info( 'Iteration ' + str(i) + ':' ) 
            logger.info( '*'*80 )

            ### Each cell performs PF independently ###
            for cell in wrld.cells:
                logger.info( 'Cell ID: ' + str(cell.cellid) )
                mobiles = [mob for mob in wrld.mobiles if mob.cell == cell]

                try:
                    pSupplyPF = pf.pf_dtx(wrld, cell, mobiles, rate)
                except ValueError as err:
                    logger.warning( err )
                    pSupplyPF = np.nan 
                    # no solution could be found
                except IndexError:
                    logger.info( 'By chance there is no mobile in the cell.' )
                    cell.OFDMA_power[:] = 0
                except:
                    logger.error(sys.exc_info())
                    raise
                if cell in wrld.consideredCells:
                    if plotting:
                        plotPowerProfile(cell, r, i, pSupplyPF)

                    # collect data
                    resultPF[r,i] = pSupplyPF 
            
            if i != iterations:
                # all cells should have adjusted their transmission powers, so there are new SINRs
                wrld.updateMobileFSF(i)
                wrld.calculateSINRs()
            
            # collect SINRs for CDF
            wrld.calculateSINRs()
            li = [list(mob.OFDMA_SINR.ravel()) for mob in wrld.consideredMobiles]
            li = sum(li,[]) # flatten list of lists
            mobileSINRs[i-1].extend(li)
            li = [list(mob.OFDMA_effSINR.ravel()) for mob in wrld.consideredMobiles]
            li = sum(li,[]) # flatten list of lists
            mobile_effSINRs[i].extend(li)
        
    #        plotPowerProfiles(wrld, i)
    #        import pdb; pdb.set_trace()

    ### Finish up ###
    sumrate_data = np.mean(resultPF[1:,-1]) # average power consumption at the last iteration
    writeFile(outpath+'sumratePF.csv', sumrate_data)
    np.savetxt(outpath+'resultPF.csv', resultPF, delimiter=",")
    save_lol(mobileSINRs, outpath+'mobileSINRs.csv')
    save_lol(mobile_effSINRs, outpath+'mobile_effSINRs.csv')

    logger.info('*'*80)
    logger.info('*'*80)
    logger.info('Runtime %.0f seconds' % (time.time() - start))