Skip to content

Commit 4286ee5

Browse files
committed
5.13.2
5.13.2
1 parent 3d5d139 commit 4286ee5

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

CAPalloction.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -343,18 +343,14 @@ def getPower(chanlist):
343343
for j in xrange(len(chanlist[i])):
344344
k = len(chanlist[i]) - chanlist[i].count(-1)##此基站分配的信道数量
345345
##为存在信道分配的位置随机分配一个随机功率值
346-
if chanlist[i][j]!=-1:
347-
wp = uniform(0.001, ptotal*1.0/k)
348-
349-
# while(sum(p[i]) + wp > ptotal):
350-
# # wp = uniform(0.001,ptotal/k)##每个信道功率最多分配ptotal/k,这样有点不合理
351-
# print sum(p[i])+wp
352-
# wp = uniform(0.001,ptotal)
353-
p[i][j] = wp
346+
if chanlist[i][j]!=-1: ##如果当前信道已分配
347+
s = sum(p[i])##求当前的基站的的功率和
348+
#print "ptotal = %s"%ptotal
349+
wp = uniform(0.001, (ptotal-s)*0.8) ##在0.001和剩余功率之间随机产生一个功率值
350+
p[i][j] = wp*(1.0/channelnum)##不至于随机数极差太大
351+
354352
return p
355353

356-
357-
358354
#------------------------------主 函 数 ---------------------------------------
359355
if __name__=="__main__":
360356

0 commit comments

Comments
 (0)