Mercurial > hg > nsaunier > traffic-intelligence
comparison scripts/safety-analysis.py @ 881:8ba82b371eea
work on storing PET
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Tue, 14 Mar 2017 17:48:40 -0400 |
| parents | 6d89520e269f |
| children | e2452abba0e7 |
comparison
equal
deleted
inserted
replaced
| 880:000555430b28 | 881:8ba82b371eea |
|---|---|
| 12 | 12 |
| 13 parser = argparse.ArgumentParser(description='The program processes indicators for all pairs of road users in the scene') | 13 parser = argparse.ArgumentParser(description='The program processes indicators for all pairs of road users in the scene') |
| 14 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file', required = True) | 14 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file', required = True) |
| 15 parser.add_argument('-n', dest = 'nObjects', help = 'number of objects to analyse', type = int) | 15 parser.add_argument('-n', dest = 'nObjects', help = 'number of objects to analyse', type = int) |
| 16 # TODO analyze only | 16 # TODO analyze only |
| 17 parser.add_argument('--prediction-method', dest = 'predictionMethod', help = 'prediction method (constant velocity (vector computation), constant velocity, normal adaptation, point set prediction)', choices = ['cvd', 'cv', 'na', 'ps']) | 17 parser.add_argument('--prediction-method', dest = 'predictionMethod', help = 'prediction method (constant velocity (cvd: vector computation (approximate); cve: equation solving; cv: discrete time (approximate)), normal adaptation, point set prediction)', choices = ['cvd', 'cve', 'cv', 'na', 'ps']) |
| 18 parser.add_argument('--pet', dest = 'computePET', help = 'computes PET', action = 'store_true') | |
| 18 parser.add_argument('--display-cp', dest = 'displayCollisionPoints', help = 'display collision points', action = 'store_true') | 19 parser.add_argument('--display-cp', dest = 'displayCollisionPoints', help = 'display collision points', action = 'store_true') |
| 19 parser.add_argument('--nthreads', dest = 'nProcesses', help = 'number of processes to run in parallel', type = int, default = 1) | 20 parser.add_argument('--nthreads', dest = 'nProcesses', help = 'number of processes to run in parallel', type = int, default = 1) |
| 20 args = parser.parse_args() | 21 args = parser.parse_args() |
| 21 | 22 |
| 22 params = storage.ProcessParameters(args.configFilename) | 23 params = storage.ProcessParameters(args.configFilename) |
| 30 def accelerationDistribution(): | 31 def accelerationDistribution(): |
| 31 return random.triangular(-params.maxNormalAcceleration, params.maxNormalAcceleration, 0.) | 32 return random.triangular(-params.maxNormalAcceleration, params.maxNormalAcceleration, 0.) |
| 32 def steeringDistribution(): | 33 def steeringDistribution(): |
| 33 return random.triangular(-params.maxNormalSteering, params.maxNormalSteering, 0.) | 34 return random.triangular(-params.maxNormalSteering, params.maxNormalSteering, 0.) |
| 34 | 35 |
| 35 if predictionMethod == 'cvd': # TODO add cve: constant velocity exact (Sohail's) | 36 if predictionMethod == 'cvd': |
| 36 predictionParameters = prediction.CVDirectPredictionParameters() | 37 predictionParameters = prediction.CVDirectPredictionParameters() |
| 38 if predictionMethod == 'cve': | |
| 39 predictionParameters = prediction.CVExactPredictionParameters() | |
| 37 elif predictionMethod == 'cv': | 40 elif predictionMethod == 'cv': |
| 38 predictionParameters = prediction.ConstantPredictionParameters(params.maxPredictedSpeed) | 41 predictionParameters = prediction.ConstantPredictionParameters(params.maxPredictedSpeed) |
| 39 elif predictionMethod == 'na': | 42 elif predictionMethod == 'na': |
| 40 predictionParameters = prediction.NormalAdaptationPredictionParameters(params.maxPredictedSpeed, | 43 predictionParameters = prediction.NormalAdaptationPredictionParameters(params.maxPredictedSpeed, |
| 41 params.nPredictedTrajectories, | 44 params.nPredictedTrajectories, |
| 62 interactions = events.createInteractions(objects) | 65 interactions = events.createInteractions(objects) |
| 63 for inter in interactions: | 66 for inter in interactions: |
| 64 inter.computeIndicators() | 67 inter.computeIndicators() |
| 65 inter.computeCrossingsCollisions(predictionParameters, params.collisionDistance, params.predictionTimeHorizon, params.crossingZones, nProcesses = args.nProcesses) | 68 inter.computeCrossingsCollisions(predictionParameters, params.collisionDistance, params.predictionTimeHorizon, params.crossingZones, nProcesses = args.nProcesses) |
| 66 | 69 |
| 70 if args.computePET: | |
| 71 for inter in Interactions: | |
| 72 inter.computePET() | |
| 73 | |
| 67 storage.saveIndicators(params.databaseFilename, interactions) | 74 storage.saveIndicators(params.databaseFilename, interactions) |
| 68 | 75 |
| 69 if args.displayCollisionPoints: | 76 if args.displayCollisionPoints: |
| 70 plt.figure() | 77 plt.figure() |
| 71 allCollisionPoints = [] | 78 allCollisionPoints = [] |
