Mercurial Hosting > traffic-intelligence
diff python/events.py @ 613:306db0f3c7a2
move 4 functions from trajLearning file
author | MohamedGomaa |
---|---|
date | Thu, 04 Dec 2014 19:07:55 -0500 |
parents | 0dc36203973d |
children | dc2d0a0d7fe1 |
line wrap: on
line diff
--- a/python/events.py Thu Dec 04 18:52:07 2014 -0500 +++ b/python/events.py Thu Dec 04 19:07:55 2014 -0500 @@ -9,14 +9,36 @@ import itertools import moving, prediction, indicators, utils -import trajLearning __metaclass__ = type +def findRoute(prototypes,objects,i,j,noiseEntryNums,noiseExitNums,minSimilarity= 0.3, spatialThreshold=1.0, delta=180): + if i[0] not in noiseEntryNums: + prototypesRoutes= [ x for x in sorted(prototypes.keys()) if i[0]==x[0]] + elif i[1] not in noiseExitNums: + prototypesRoutes=[ x for x in sorted(prototypes.keys()) if i[1]==x[1]] + else: + prototypesRoutes=[x for x in sorted(prototypes.keys())] + routeSim={} + lcss = utils.LCSS(similarityFunc=lambda x,y: (distanceForLCSS(x,y) <= spatialThreshold),delta=delta) + for y in prototypesRoutes: + if y in prototypes.keys(): + prototypesIDs=prototypes[y] + similarity=[] + for x in prototypesIDs: + s=lcss.computeNormalized(objects[j].positions, objects[x].positions) + similarity.append(s) + routeSim[y]=max(similarity) + route=max(routeSim, key=routeSim.get) + if routeSim[route]>=minSimilarity: + return route + else: + return i + def getRoute(obj,prototypes,objects,noiseEntryNums,noiseExitNums,useDestination=True): route=(obj.startRouteID,obj.endRouteID) if useDestination: if route not in prototypes.keys(): - route= trajLearning.findRoute(prototypes,objects,route,obj.getNum(),noiseEntryNums,noiseExitNums) + route= findRoute(prototypes,objects,route,obj.getNum(),noiseEntryNums,noiseExitNums) return route class Interaction(moving.STObject):