Skip to content

Commit 70f45bc

Browse files
committed
5-15.1
5-15.1
1 parent 65517a1 commit 70f45bc

File tree

3 files changed

+64
-31
lines changed

3 files changed

+64
-31
lines changed

CAPalloction.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from random import random,uniform
33
import numpy as np
44
import matplotlib.pyplot as plt
5-
from coverage import Draw
5+
# from coverage import Draw ##用户和基站的坐标已改成从文件中直接读取,不需要使用的时候随机生成了2017年5月15日09:19:37改
66
from SINR import distance
77
from numpy import log2
88
from memory_profiler import profile
@@ -44,11 +44,12 @@
4444

4545
macroAveragePower = macroPower/channelnum ##宏基站的信道平均功率
4646
microAveragePower = picoPower/channelnum ##微基站的信道平均功率
47-
print "宏基站信道平均功率:%s,picomeanPower:%s"%(macroAveragePower,microAveragePower)
47+
# print "宏基站信道平均功率:%s,picomeanPower:%s"%(macroAveragePower,microAveragePower)
4848
channelbandwidth = bandwidth/channelnum ##每个信道的带宽
4949

5050
#-----------------------------用 户 的 坐 标 位 置 和 基 站 的 坐 标 位 置 --------------------------------
51-
UserX,UserY, BSX,BSY = Draw(samples_num= usernum,R = 500)#接收用户坐标和基站坐标(不包括宏基站)
51+
'''这些信息已经改成从文件中获取,不需要每次运行的时候重新生成了'''
52+
# UserX,UserY, BSX,BSY = Draw(samples_num= usernum,R = 500)#接收用户坐标和基站坐标(不包括宏基站)2017年5月15日09:20:02改
5253

5354
'''
5455
# ------------------------------------此 函 数 已 经 废 弃----------------------------------------
@@ -81,11 +82,11 @@ def readFile(*filename):
8182
L1 = line1.rstrip("\n").split(" ")
8283
bsx.append(float(L1[1]))
8384
bsy.append(float(L1[2]))
84-
return userx,usery,bsx,bsy
85+
return userx,usery,bsx,bsy##基站坐标中不含有宏基站坐标
8586

8687

8788
#---------------------------------定 义 分 类 函 数----------------------------------------------
88-
def classifyUser(r,ux=UserX,uy=UserY,bsx=BSX,bsy=BSY):##定义一个分类函数
89+
def classifyUser(r,ux,uy,bsx,bsy):##定义一个分类函数
8990
'''
9091
将用户按照:是否处于某个基站覆盖范围分类,r基站的半径
9192
基站坐标不能包含宏基站坐标,宏基站用户需等待所有其他类型的基站分类完毕之后才能得到
@@ -344,7 +345,8 @@ def channelAllocate(BSCover,bsx,bsy):
344345
print "All channels are busy"
345346
exit(0)
346347
except:
347-
print "Error"
348+
print "Error"
349+
exit(0)
348350
return BSchanAllocate
349351
#------------------------------产 生 随 机 功 率 矩 阵 的 函 数 -----------------------------
350352
def getPower(chanlist):
@@ -373,11 +375,13 @@ def getPower(chanlist):
373375

374376
#------------------------------主 函 数 ---------------------------------------
375377
if __name__=="__main__":
376-
377-
# BSCover = classifyUser(r=100)
378-
#
379-
# BSX = BSX+[0.0]
380-
# BSY = BSY+[0.0]
378+
379+
filename = ['user.txt','bs.txt']
380+
UserX,UserY,BSX,BSY = readFile(*filename)
381+
BSCover = classifyUser(100,UserX,UserY,BSX,BSY)
382+
####将宏基站的坐标加入到基站的坐标列表中
383+
BSX = BSX+[0.0]
384+
BSY = BSY+[0.0]
381385
# ##将用户按照基站的覆盖范围分类之后,将宏基站的坐标加入到基站坐标列表中去
382386
# # s = 0
383387
# # for i in BSCover:
@@ -386,22 +390,19 @@ def getPower(chanlist):
386390
# # print "len(i)=%d"%len(i)
387391
# # print "sum user:%d"%s
388392
#
389-
# An_k_s=[[0 for i in xrange(channelnum)] for j in xrange(TotalNum)]
390-
# BSchanAllocate = channelAllocate(BSCover,BSX,BSY)
391-
# for i in xrange(len(BSchanAllocate)):
392-
# print BSchanAllocate[i]
393-
# for j in xrange(len(BSchanAllocate[i])):
394-
# if BSchanAllocate[i][j]!=-1:
395-
# An_k_s[i][j]=1
396-
# # print "\n"
397-
# # for i in xrange(len(An_k_s)):
398-
# # print An_k_s[i]
399-
#
400-
# ##既然信道分配已经确定了,那么平均功率所组成的一个粒子可以算作一个初始化粒子,然后针对这些已经分配信道的的用户的信道功率多做几次(20次)功率随机分配,就会产生许多不同的初始化
393+
An_k_s=[[0 for i in xrange(channelnum)] for j in xrange(TotalNum)]
394+
BSchanAllocate = channelAllocate(BSCover,BSX,BSY)
395+
for i in xrange(len(BSchanAllocate)):
396+
print BSchanAllocate[i]
397+
for j in xrange(len(BSchanAllocate[i])):
398+
if BSchanAllocate[i][j]!=-1:
399+
An_k_s[i][j]=1
401400
# print "\n"
402-
# p = getPower(BSchanAllocate)
403-
# for i in p:
404-
# print i
405-
filename = ['user.txt','BS.txt']
406-
UserX,UserY,BSX,BSY = readFile(*filename)
407-
print len(UserX),len(BSX)
401+
# for i in xrange(len(An_k_s)):
402+
# print An_k_s[i]
403+
404+
##既然信道分配已经确定了,那么平均功率所组成的一个粒子可以算作一个初始化粒子,然后针对这些已经分配信道的的用户的信道功率多做几次(20次)功率随机分配,就会产生许多不同的初始化
405+
print "\n"
406+
p = getPower(BSchanAllocate)
407+
for i in p:
408+
print i

multithread.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding: UTF-8 -*-
2+
'''
3+
Created on 2017年5月15日
4+
5+
@author: Administrator
6+
'''
7+
8+
9+
import thread
10+
import time
11+
12+
# 为线程定义一个函数
13+
def print_time( threadName, delay):
14+
count = 0
15+
while count < 5:
16+
time.sleep(delay)
17+
count += 1
18+
print "%s: %s" % ( threadName, time.ctime(time.time()) )
19+
20+
# 创建两个线程
21+
try:
22+
thread.start_new_thread( print_time, ("Thread-1", 2, ) )
23+
thread.start_new_thread( print_time, ("Thread-2", 4, ) )
24+
thread.start_new_thread( print_time, ("Thread-3", 6, ) )
25+
thread.start_new_thread( print_time, ("Thread-4", 8, ) )
26+
thread.start_new_thread( print_time, ("Thread-4", 8, ) )
27+
28+
except:
29+
print "Error: unable to start thread"
30+
31+
while 1:
32+
pass

pso.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ def __init__(self,pN,dim,max_iter):
3939
self.fit = 1e10 #全局最佳适应值
4040

4141
#---------------------目标函数Sphere函数-----------------------------
42-
# def function(self,x): #x是列表
42+
def function(self,x): #x是列表
4343
# sum = 0
4444
# length = len(x)
4545
# x = x**2
4646
# for i in range(length):
4747
# sum += x[i]
4848
# return sum
49-
#
49+
pass
5050
#---------------------初始化种群----------------------------------
5151
def init_Population(self):
5252
for i in range(self.pN):

0 commit comments

Comments
 (0)