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 test_pf(self): wconf = copy.copy(self.wconf) wconf.hexTiers = 0 wconf.usersPerCell = 10 wconf.mobileVelocity = 100 world1 = world.World(wconf, self.phy) world1.associatePathlosses() world1.calculateSINRs() rate = 1 avg_rate = np.ones(len(world1.mobiles)) # when avg_rate is near zero for one user, that user 0 should receive all RBs avg_rate[0] = 1e-20 alloc = pf.pf(world1, world1.cells[0], world1.mobiles, rate, avg_rate) np.testing.assert_array_equal(alloc, np.zeros([50, 10])) rate = 1e6 pSupplyPC = pf.pf_ba(world1, world1.cells[0], world1.mobiles, rate) pSupplyDTX = pf.pf_dtx(world1, world1.cells[0], world1.mobiles, rate)
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')
def sim(): # Firstly, get rid of the start button for child in root.children.values(): if child.winfo_rootx() - root.winfo_rootx() == 0 \ and child.winfo_rooty() - root.winfo_rooty() == 0: widget = child widget.destroy() root.update() p_world.World(width, height, creatureRate, root) world = p_world.World.getInstance() world.generateWorld() world.displayWorld() while True: # Nothing is left alive, display the world one more time and then exit if not world.performTurn(): world.displayWorld() break world.displayWorld() time.sleep(.5)
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))
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))
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