forked from xiaosongshaokao/ProjectOfAlgorithm
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.py
More file actions
Latest commit
39 lines (34 loc) · 1.69 KB
/
Copy pathsolution.py
File metadata and controls
39 lines (34 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#这个文件中需要写一个解类,此类需要包含一个解中所有的AP分布,并包含适应度函数
location_set= [[0,0],[1,1],[2,2],[3,3]]
classsolution:
def__init__(self, location=None):
iflocationisNone:
location=location_set
self.location=location
self.fit_number=0
self.emission_intensity=100
defThroughTheWall(self, AP, TestPoint, background):#计算从信号发射点到信号检测点穿墙次数
count=0
returncount
# 计算从信号发射点到信号检测点的信号强度衰减
#根据公式,我舍去了常数部分,PLE暂设为0.5, 每穿过一堵墙的损耗暂设为10dB,均为经验值
defreduction(self, times, distance):
reduce=1
loss= (distance) **0.5*10**times
reduce=reduce/loss
returnreduce
deffitness(self, background):#适应度函数,返回值为修改过的fit_number
results_in_background= []
forroominbackground.rooms:#计算每个房间的每个信号检测点的信号强度
results= []
TestPoint=background.points(room)
forpointinTestPoint:
result_at_the_point=0
forAPinlocation_set:
times=self.ThroughTheWall(AP, point, background)
distance= ((AP[0] -point[0])**2+ (AP[1] -point[1]))**0.5
reduction=self.reduction(times, distance)
result_at_the_point+=self.emission_intensity*reduction
results.append(result_at_the_point)
results_in_background.append(results)
returnresults_in_background