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 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