def calculateScore(QueryTuple,CandidateTuple,ShortestPath): ''' ST Algorithm 核心部分 时空得分计算 ''' #空间得分计算 TimeInc = abs(QueryTuple[0][2]-QueryTuple[1][2])#时间增量计算 if TimeInc==0: return -1 QueryLength = calculateLength(QueryTuple[0],QueryTuple[1]) #采样点欧氏距离计算 NormDistance = calculateLength(QueryTuple[1],CandidateTuple[1]) #正态分布距离计算 SpatialArgument = normalDistribution(NormDistance)*(QueryLength/ShortestPath[1]) #ShortestPath[1]是路段距离记录 #****************************************************************************** #时间得分计算 AverageSpeed = ShortestPath[1]/TimeInc #候选点平均速度计算 SpeedProductSum = 0 SpeedPowerSum = 0 AverageSpeedSum = 0 for i in ShortestPath[0]:#这里是最大速度的记录列表 SpeedProductSum += i*AverageSpeed SpeedPowerSum += i**2 AverageSpeedSum += AverageSpeed**2 if (sqrt(SpeedPowerSum)*sqrt(AverageSpeedSum))==0: return -1 TimeArgument = SpeedProductSum/(sqrt(SpeedPowerSum)*sqrt(AverageSpeedSum)) return TimeArgument*SpatialArgument
def calculateScore(QueryTuple, CandidateTuple, ShortestPath): ''' ST Algorithm 核心部分 时空得分计算 ''' #空间得分计算 TimeInc = abs(QueryTuple[0][2] - QueryTuple[1][2]) #时间增量计算 if TimeInc == 0: return -1 QueryLength = calculateLength(QueryTuple[0], QueryTuple[1]) #采样点欧氏距离计算 NormDistance = calculateLength(QueryTuple[1], CandidateTuple[1]) #正态分布距离计算 SpatialArgument = normalDistribution(NormDistance) * (QueryLength / ShortestPath[1]) #ShortestPath[1]是路段距离记录 #****************************************************************************** #时间得分计算 AverageSpeed = ShortestPath[1] / TimeInc #候选点平均速度计算 SpeedProductSum = 0 SpeedPowerSum = 0 AverageSpeedSum = 0 for i in ShortestPath[0]: #这里是最大速度的记录列表 SpeedProductSum += i * AverageSpeed SpeedPowerSum += i**2 AverageSpeedSum += AverageSpeed**2 if (sqrt(SpeedPowerSum) * sqrt(AverageSpeedSum)) == 0: return -1 TimeArgument = SpeedProductSum / (sqrt(SpeedPowerSum) * sqrt(AverageSpeedSum)) return TimeArgument * SpatialArgument
def judgeOutOfDistance(self): ''' 判断距离是否超出预期 ''' JuageLength1 = calculateLength(self.Point, self.Road[0]) JuageLength2 = calculateLength(self.Point, self.Road[1]) if JuageLength1 > 5.0 or JuageLength2 > 5.0: return False else: return True
def judgeOutOfDistance(self): ''' 判断距离是否超出预期 ''' JuageLength1 = calculateLength(self.Point,self.Road[0]) JuageLength2 = calculateLength(self.Point,self.Road[1]) if JuageLength1>5.0 or JuageLength2>5.0: return False else: return True
def calculateZeroScore(QueryTuple,CandidateTuple): TimeInc = abs(QueryTuple[0][2]-QueryTuple[1][2])#时间增量计算 if TimeInc==0: return -1 QueryLength = calculateLength(QueryTuple[0],QueryTuple[1]) #采样点欧氏距离计算 NormDistance = calculateLength(QueryTuple[1],CandidateTuple[1]) #正态分布距离计算 CandidateLength = calculateLength(CandidateTuple[0],CandidateTuple[1]) SpatialArgument = normalDistribution(NormDistance)*(QueryLength/CandidateLength) #****************************************************************************** return SpatialArgument
def calculateZeroScore(QueryTuple, CandidateTuple): TimeInc = abs(QueryTuple[0][2] - QueryTuple[1][2]) #时间增量计算 if TimeInc == 0: return -1 QueryLength = calculateLength(QueryTuple[0], QueryTuple[1]) #采样点欧氏距离计算 NormDistance = calculateLength(QueryTuple[1], CandidateTuple[1]) #正态分布距离计算 CandidateLength = calculateLength(CandidateTuple[0], CandidateTuple[1]) SpatialArgument = normalDistribution(NormDistance) * (QueryLength / CandidateLength) #****************************************************************************** return SpatialArgument
def findShortestPath(Point1,Point2,Graph): ''' 寻找最短路径,并记录最大速度限制和路径长度 ''' try: ShortestPath = nx.astar_path(Graph,Point1,Point2) ShortestPathLength = 0 if len(ShortestPath)==1: return 0 MaxSpeed = [] for i in range(len(ShortestPath)-1): ShortestPathLength += calculateLength(ShortestPath[i],ShortestPath[i+1]) #记录路段距离 MaxSpeed.append(Graph.get_edge_data(ShortestPath[i],ShortestPath[i+1])['MAX_SPEED']) #记录最大速度限制 #return ShortestPath,ShortestPathLength 条件使用 return MaxSpeed,ShortestPathLength except Exception, e:#处理不可达情况 pass
def findShortestPath(Point1, Point2, Graph): ''' 寻找最短路径,并记录最大速度限制和路径长度 ''' try: ShortestPath = nx.astar_path(Graph, Point1, Point2) ShortestPathLength = 0 if len(ShortestPath) == 1: return 0 MaxSpeed = [] for i in range(len(ShortestPath) - 1): ShortestPathLength += calculateLength(ShortestPath[i], ShortestPath[i + 1]) #记录路段距离 MaxSpeed.append( Graph.get_edge_data(ShortestPath[i], ShortestPath[i + 1])['MAX_SPEED']) #记录最大速度限制 #return ShortestPath,ShortestPathLength 条件使用 return MaxSpeed, ShortestPathLength except Exception, e: #处理不可达情况 pass