Mercurial > hg > nsaunier > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 612:6ee8765bb8db | 613:306db0f3c7a2 |
|---|---|
| 7 | 7 |
| 8 import multiprocessing | 8 import multiprocessing |
| 9 import itertools | 9 import itertools |
| 10 | 10 |
| 11 import moving, prediction, indicators, utils | 11 import moving, prediction, indicators, utils |
| 12 import trajLearning | |
| 13 __metaclass__ = type | 12 __metaclass__ = type |
| 13 | |
| 14 def findRoute(prototypes,objects,i,j,noiseEntryNums,noiseExitNums,minSimilarity= 0.3, spatialThreshold=1.0, delta=180): | |
| 15 if i[0] not in noiseEntryNums: | |
| 16 prototypesRoutes= [ x for x in sorted(prototypes.keys()) if i[0]==x[0]] | |
| 17 elif i[1] not in noiseExitNums: | |
| 18 prototypesRoutes=[ x for x in sorted(prototypes.keys()) if i[1]==x[1]] | |
| 19 else: | |
| 20 prototypesRoutes=[x for x in sorted(prototypes.keys())] | |
| 21 routeSim={} | |
| 22 lcss = utils.LCSS(similarityFunc=lambda x,y: (distanceForLCSS(x,y) <= spatialThreshold),delta=delta) | |
| 23 for y in prototypesRoutes: | |
| 24 if y in prototypes.keys(): | |
| 25 prototypesIDs=prototypes[y] | |
| 26 similarity=[] | |
| 27 for x in prototypesIDs: | |
| 28 s=lcss.computeNormalized(objects[j].positions, objects[x].positions) | |
| 29 similarity.append(s) | |
| 30 routeSim[y]=max(similarity) | |
| 31 route=max(routeSim, key=routeSim.get) | |
| 32 if routeSim[route]>=minSimilarity: | |
| 33 return route | |
| 34 else: | |
| 35 return i | |
| 14 | 36 |
| 15 def getRoute(obj,prototypes,objects,noiseEntryNums,noiseExitNums,useDestination=True): | 37 def getRoute(obj,prototypes,objects,noiseEntryNums,noiseExitNums,useDestination=True): |
| 16 route=(obj.startRouteID,obj.endRouteID) | 38 route=(obj.startRouteID,obj.endRouteID) |
| 17 if useDestination: | 39 if useDestination: |
| 18 if route not in prototypes.keys(): | 40 if route not in prototypes.keys(): |
| 19 route= trajLearning.findRoute(prototypes,objects,route,obj.getNum(),noiseEntryNums,noiseExitNums) | 41 route= findRoute(prototypes,objects,route,obj.getNum(),noiseEntryNums,noiseExitNums) |
| 20 return route | 42 return route |
| 21 | 43 |
| 22 class Interaction(moving.STObject): | 44 class Interaction(moving.STObject): |
| 23 '''Class for an interaction between two road users | 45 '''Class for an interaction between two road users |
| 24 or a road user and an obstacle | 46 or a road user and an obstacle |
