Example #1
0
def generateWorld(configfile):
    """Generate a world according to configfile"""
    wrld = world.World(wconfig.Wconfig(configfile), phy.PHY(configfile))
    wrld.associatePathlosses()
    wrld.calculateSINRs()
    wrld.fix_center_cell_users()  # set 0 in settings file to disable
    return wrld
def main():
    """Generate world and figure"""

    configPath = 'configure/settings_network_plot.cfg'
    wconf = wconfig.Wconfig(configPath)
    phy_ = phy.PHY(configPath)
    wconf.enablefrequencyselectivefading = False

    wrld = world.World(wconf, phy_)
    wrld.associatePathlosses()
    wrld.calculateSINRs()

    networkplotter.NetworkPlotter().plotAssociatedMobiles(
        wrld, outpath + 'assocation_plot')
    networkplotter.NetworkPlotter().plotBasicWorld(wrld,
                                                   outpath + 'basic_plot')
    networkplotter.NetworkPlotter().plotAssociatedConsideredMobiles(
        wrld, outpath + 'association_considered')
    networkplotter.NetworkPlotter().plotConsideredWorld(
        wrld, outpath + 'considered')
Example #3
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 #4
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))
Example #5
0
    if theta > 0:
        x = min(x1, x2) + d * math.cos(theta)
        y = min(y1, y2) + d * math.sin(theta)
    elif theta < 0:
        x = max(x1, x2) - d * cos(-theta)
        y = min(y1, y2) + d * sin(-theta)

    return x, y, d, theta


if __name__ == '__main__':

    print 'World with single sector base stations:'
    configPath = 'configure/settings1tier1sector.cfg'
    phyy = phy.PHY(configPath)
    wconf = wconfig.Wconfig(configPath)
    world1 = World(wconf, phyy)
    #    print 'Base stations: ', world1.baseStationCoordinates
    #    print 'Mobiles: ', world1.mobileCoordinates
    print 'World1:', len(
        world1.baseStations), 'base stations remaining, covering ', len(
            world1.hexagons), 'cells.'

    print 'World with three sectors per base station:'
    configPath = 'configure/settings3tier3sectors.cfg'
    phyy = phy.PHY(configPath)
    wconf = wconfig.Wconfig(configPath)
    wconf.hexTiers = 3
    wconf.userPerCell = 5
    world2 = World(wconf, phyy)
Example #6
0
import ConfigParser
import sys
from plotting import networkplotter

# custom
from world import *
from world import world
from configure import phy, wconfig

############### Read config file #####################
configPath = 'configure/settingsBeFemtoCalibration.cfg'
############# Generate map #########################

SINRlist = []
for itr in range(1, iterations + 1):
    wrld = world.World(wconfig.Wconfig(configPath), phy.PHY(configPath))
    wrld.associatePathlosses()
    wrld.calculateSINRs()

    ### Wideband SINR ###
    SINRlist += [mob.SINR for mob in wrld.consideredMobiles]
    print '%(a)d out of %(b)d done.' % {"a": itr, "b": iterations}

    ### OFDMA SINR ###
    li = [list(mob.OFDMA_SINR.ravel()) for mob in wrld.consideredMobiles]
    li = sum(li, [])  # flatten list of lists
    mobileSINRs[i - 1].extend(li)

############### Store results to file #############

filename = 'results.txt'
Example #7
0
 def setUp(self):
     configPath = 'configure/settings1tier1sector.cfg'
     self.phy = phy.PHY(configPath)
     self.wconf = wconfig.Wconfig(configPath)
Example #8
0
    print ' '

    return pSupplyOptim, pSupplyQuant, pSupplyBA


### RUN ###

resultOptim = np.empty([iterations, rateSteps])
resultQuant = np.empty([iterations, rateSteps])
resultBAful = np.empty([iterations, rateSteps])
for itr in np.arange(iterations):
    print '\nIteration ', itr, '\n'

    # We only generate one world per iteration. All rates are optimized within this world. Since world creation takes the majority of computing time, this makes simulations much faster.
    wconf = wconfig.Wconfig(configPath)  # this should be a member of World()
    wrld = world.World(wconf, phy.PHY(configPath))
    wrld.associatePathlosses()
    wrld.calculateSINRs()
    bs = wrld.baseStations[0]
    cell = bs.cells[
        0]  # Sectors are important because they are the end of the link (not always base stations)

    ### Show world ###
    if plotting:
        from plotting import networkplotter
        networkplotter.NetworkPlotter().plotAssociatedConsideredMobiles(wrld)

    ### Generate CSI ###
    # Approximate the real-valued resource share per user
    users = len(wrld.consideredMobiles
                )  # due to the uniform distribution, this number changes