Skip to content

Commit

Permalink
Merge pull request #5 from mit-ll/master
Browse files Browse the repository at this point in the history
Performance improvements
  • Loading branch information
aweinert-MIT authored Jul 19, 2021
2 parents e9f470c + 5bde149 commit 99a03b2
Show file tree
Hide file tree
Showing 32 changed files with 1,089 additions and 601 deletions.
221 changes: 210 additions & 11 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,14 +1,213 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
## GITATTRIBUTES FOR WEB PROJECTS
#
# These settings are for any web project.
#
# Details per file setting:
# text These files should be normalized (i.e. convert CRLF to LF).
# binary These files are binary and should be left untouched.
#
# Note that binary is a macro for -text -diff.
######################################################################

# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.c text
*.h text
# Original source
# https://github.com/alexkaratarakis/gitattributes

# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=lf
# Auto detect
## Handle line endings automatically for files detected as
## text and leave all files detected as binary untouched.
## This will handle all files NOT defined below.
* text=auto

# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
# Source code
*.bash text eol=lf
*.bat text eol=crlf
*.cmd text eol=crlf
*.coffee text
*.css text diff=css
*.htm text diff=html
*.html text diff=html
*.inc text
*.ini text
*.js text
*.json text
*.jsx text
*.less text
*.ls text
*.map text -diff
*.od text
*.onlydata text
*.php text diff=php
*.pl text
*.ps1 text eol=crlf
*.py text diff=python
*.rb text diff=ruby
*.sass text
*.scm text
*.scss text diff=css
*.sh text eol=lf
*.sql text
*.styl text
*.tag text
*.ts text
*.tsx text
*.xml text
*.xhtml text diff=html

# Docker
Dockerfile text

# Documentation
*.ipynb text
*.markdown text diff=markdown
*.md text diff=markdown
*.mdwn text diff=markdown
*.mdown text diff=markdown
*.mkd text diff=markdown
*.mkdn text diff=markdown
*.mdtxt text
*.mdtext text
*.txt text
AUTHORS text
CHANGELOG text
CHANGES text
CONTRIBUTING text
COPYING text
copyright text
*COPYRIGHT* text
INSTALL text
license text
LICENSE text
NEWS text
readme text
*README* text
TODO text

# Templates
*.dot text
*.ejs text
*.haml text
*.handlebars text
*.hbs text
*.hbt text
*.jade text
*.latte text
*.mustache text
*.njk text
*.phtml text
*.tmpl text
*.tpl text
*.twig text
*.vue text

# Configs
*.cnf text
*.conf text
*.config text
.editorconfig text
.env text
.gitattributes text
.gitconfig text
.htaccess text
*.lock text -diff
package.json text eol=lf
package-lock.json text -diff
pnpm-lock.yaml text eol=lf -diff
yarn.lock text -diff
*.toml text
*.yaml text
*.yml text
browserslist text
Makefile text
makefile text

# Heroku
Procfile text

# Graphics
*.ai binary
*.bmp binary
*.eps binary
*.gif binary
*.gifv binary
*.ico binary
*.jng binary
*.jp2 binary
*.jpg binary
*.jpeg binary
*.jpx binary
*.jxr binary
*.pdf binary
*.png binary
*.psb binary
*.psd binary
# SVG treated as an asset (binary) by default.
*.svg text
# If you want to treat it as binary,
# use the following line instead.
# *.svg binary
*.svgz binary
*.tif binary
*.tiff binary
*.wbmp binary
*.webp binary

# Audio
*.kar binary
*.m4a binary
*.mid binary
*.midi binary
*.mp3 binary
*.ogg binary
*.ra binary

# Video
*.3gpp binary
*.3gp binary
*.as binary
*.asf binary
*.asx binary
*.fla binary
*.flv binary
*.m4v binary
*.mng binary
*.mov binary
*.mp4 binary
*.mpeg binary
*.mpg binary
*.ogv binary
*.swc binary
*.swf binary
*.webm binary

# Archives
*.7z binary
*.gz binary
*.jar binary
*.rar binary
*.tar binary
*.zip binary

# Fonts
*.ttf binary
*.eot binary
*.otf binary
*.woff binary
*.woff2 binary

# Executables
*.exe binary
*.pyc binary

# RC files (like .babelrc or .eslintrc)
*.*rc text

# Ignore files (like .npmignore or .gitignore)
*.*ignore text

# MATLAB
*.mat binary

# Declare files that will always have LF line endings on checkout.
*.ini text eol=lf
*.txt text eol=lf
*.csv text eol=lf
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ octave-workspace
~*.tmp

# Directory specific
Inputs/**/*.ini
Outputs/**/*.mat
Outputs/**/*.csv
Outputs/**/*.txt
Tests/**/*.mat
Tests/Generated_Encounters/**/*.txt
Tests/Code_Coverage/**/*.png
Expand All @@ -50,3 +54,4 @@ Tests/Test_Outputs/**/*.txt
*.js
*.html
*.css
*.png
56 changes: 56 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project should adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [1.2.0] - 2021-07-19

### Added

- `.gitattributes` added for repository management
- `preallocateEncProperties` to preallocate struct of encounter metadata
- Basic performance benchmark metrics to generateDAAEncounterSet() and plotted in RUN_DAAEncounterModelTool_serial
- Default input and output directories

### Changed

- Substantial performance boost through preallocating, minimizing use of dynamically growth of arrays, and removing large variables that are not used. On a local windows machine, these improvements reduce the time to generate 100K encounters from days to hours
- Updated mex instructions to use the -g flag
- Trajectory .csv files explicitly use UTF-8 encoding
- Updated line endings for various files to better cross platform compability
- Renamed matlab startup script
- MATLAB startip script checks for symbolic math toolbox
- MATLAB startup script to add self path using system environment variable instead of `pwd()`
- Removed various unnecessary unit conversions by [@cserres](https://github.com/cserres)

### Fixed

- Random seed sequentially updated and guaranteed to be unique up to a seed of 2^32 (the MATLAB limit)
- Fix bug when checking duplicate settings when looking if there has been any encounter model customization
- `generateDAAEncounterSet` formats input to `wpt2script` correctly

### Removed

- Remove `em_read` that was shadowed by the version in [em-model-manned-bayes](https://github.com/airspace-Encounter-Models/em-model-manned-bayes)
- `checkINIInputs()` no longer issues warnings about the uncor_1200code_v2p1 model
- Removed instances %#okgrow that suppressed warnings

## [1.1.0] - 2020-10-02

### Changed

- Updated to output original encounter model events

## [1.0.0] - 2020-09-10

### Added

- Initial public release

[1.2.0]: https://github.com/Airspace-Encounter-Models/em-pairing-uncor-importancesampling/releases/tag/v1.2
[1.1.0]: https://github.com/Airspace-Encounter-Models/em-pairing-uncor-importancesampling/releases/tag/v1.1
[1.0.0]: https://github.com/Airspace-Encounter-Models/em-pairing-uncor-importancesampling/releases/tag/v1.0
6 changes: 3 additions & 3 deletions Encounter_Generation_Tool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ The files in the following table are part of the Encounter Generation Tool. Note
| ------------- | ------------- |------------- |
| Run scripts for generating encounters | <ul><li>`generateDAAEncounterSet.m`</li><li>`ini2struct.m`</li><li>`load_constants.m`</li></ul> | `generateDAAEncounterSet.m` takes in an .INI parameter file and generates a set of encounters with the characteristics specified in the parameter file. <br><br> `ini2struct.m` is a helper function for reading in parameters in the .INI file. <br><br> `load_constants.m` defines common constants for unit conversions |
| Input validation | <ul><li>`checkEncounterModelInputs.m`</li><li>`checkINIInputs.m`</li></ul> | `checkEncounterModelInputs.m` validates user-modified Uncorrelated Encounter Model characteristics and throws an error if there are any improperly formatted variables. <br><br> `checkINIInputs.m` validates the parameters in the .INI file and throws an error if any values are invalid. |
| Sampling from the Lincoln Uncorrelated Encounter Model | <ul><li>`asub2ind.m`</li><li>`bn_dirichlet_prior.m`</li><li>`bn_sample.m`</li><li>`bn_sort.m`</li><li>`dbn_hierarchical_sample.m`</li><li>`dbn_sample.m`</li><li>`dediscretize.m`</li><li>`em_read.m`</li><li>`EncounterModelEvents.m`</li><li>`resample_events.m`</li><li>`select_random.m`</li><li>`uncor_v2p1.txt`</li></ul> | These files are used to sample trajectories from the Uncorrelated Encounter Model. <br><br>`em_read.m` is used to parse `uncor_v2p1.txt`, which contains the Uncorrelated Encounter Model. The Uncorrelated Encounter Model parameters can be tuned to change the behavior of the intruder: see the Example_Inputs [README](../Example_Inputs/README.md#encounter-model-files) for more information. See this [paper](https://apps.dtic.mil/sti/pdfs/ADA589697.pdf) for an explanation of the parameters. <br><br>`EncounterModelEvents.m` creates an event matrix for the intruder trajectory (containing the times when updates in vertical rate/turn rate/acceleration occur). <br><br> All other files are helper functions for `dbn_hierarchical_sample.m`, which is used to sample a vector of initial values (geographic region, airspace class, altitude layer, airspeed, acceleration, vertical rate, turn rate), and a matrix of events (time, vertical rate, turn rate, acceleration) for every encounter. This [paper]( https://apps.dtic.mil/sti/pdfs/ADA589697.pdf) provides a description of how samples are generated from the Uncorrelated Encounter Model. |
| Sampling from the Lincoln Uncorrelated Encounter Model | <ul><li>`asub2ind.m`</li><li>`bn_dirichlet_prior.m`</li><li>`bn_sample.m`</li><li>`bn_sort.m`</li><li>`dbn_hierarchical_sample.m`</li><li>`dbn_sample.m`</li><li>`dediscretize.m`</li><li>`em_read.m`</li><li>`EncounterModelEvents.m`</li><li>`resample_events.m`</li><li>`select_random.m`</li></ul> | These files are used to sample trajectories from the Uncorrelated Encounter Model. <br><br>`em_read.m` is used to parse the encounter model file, which contains the Uncorrelated Encounter Model. The Uncorrelated Encounter Model parameters can be tuned to change the behavior of the intruder: see the Example_Inputs [README](../Example_Inputs/README.md#encounter-model-files) for more information. See this [paper](https://apps.dtic.mil/sti/pdfs/ADA589697.pdf) for an explanation of the parameters. <br><br>`EncounterModelEvents.m` creates an event matrix for the intruder trajectory (containing the times when updates in vertical rate/turn rate/acceleration occur). <br><br> All other files are helper functions for `dbn_hierarchical_sample.m`, which is used to sample a vector of initial values (geographic region, airspace class, altitude layer, airspeed, acceleration, vertical rate, turn rate), and a matrix of events (time, vertical rate, turn rate, acceleration) for every encounter. This [paper]( https://apps.dtic.mil/sti/pdfs/ADA589697.pdf) provides a description of how samples are generated from the Uncorrelated Encounter Model. |
| Sampling from a set of trajectories | <ul><li>`ecef_to_enu.m`</li><li>`geod_to_ecef.m`</li><li>`sampleTrajectory.m`</li><li>`upsampleTrajectory.m`</li></ui> | `sampleTrajectory.m` samples one trajectory from a set of user-defined trajectories. The directory containing the trajectories must be specified in the .INI file. Tracks may be sampled uniformly or the sampling process may be weighted so that longer tracks are more likely to be sampled than shorter tracks. Filtering can also be applied at this step such that tracks that do not satisfy minimum/maximum airspeed/altitude limits are rejected. See the Example_Inputs [README](../Example_Inputs/README.md#trajectory-files) for the expected format of these trajectories.<br><br>`geod_to_ecef.m` and `ecef_to_enu.m` are used to convert the trajectories from lat/lon to x/y (east and north). The encounters are initialized and output in terms of east and north. <br> <br> `upsampleTrajectory.m` is used to convert the input trajectories from 1 Hz to 10 Hz.|
| Initializing encounters | <ul><li>`initializeUncorrelatedEncounter.m`</li><li>`UncorEncounterParameters.m`</li></ul> | `initializeUncorrelatedEncounter.m` shifts and rotates the sampled ownship and intruder trajectories so that the encounter has the sampled values of HMD and VMD at CPA. <br><br> `UncorEncounterParameters.m` is a class that contains parameters used to initialize uncorrelated encounters. |
| Simulating Dynamics | <ul><li>`minmax.h`</li><li>`run_dynamics_fast.c`</li><li>`run_dynamics_fast.mexa64`. `run_dynamics_fast.mexw64`, or `run_dynamics_fast.mexmaci64` (generated by user - see the Encounter Generation Tool [README](../README.md#mex))</li></ui> | `run_dynamics_fast.c` is an implementation of the DEGAS dynamics in C. The mexed version of this function (`run_dynamics_fast.mexa64` for Linux, `run_dynamics_fast.mexw64` for Windows, or `run_dynamics_fast.mexmaci64` for Mac) is used by the Encounter Generation Tool to convert sampled encounter model events into trajectories. The dynamics constraints in `run_dynamics_fast.c` are the same as the constraints in DEGAS. Note that the user will need to mex `run_dynamics_fast.c` if any changes are made to the file (e.g., to change the constraints). <br><br> `minmax.h` is a helper function used by the dynamics.|
| Computing metadata | <ul><li>`computeEncProperties.m`</li><li>`getCPAMetrics.m`</li><li>`getNominalManeuvers.m`</li></ui> |`computeEncProperties.m` outputs encounter metadata including intruder/ownship height and speed at TCA, encounter weight, and encounter duration. <br><br>The function calls `getCPAMetrics.m` to compute HMD, VMD, TCA, and whether an NMAC occurs. <br><br> The function also calls `getNominalManeuvers.m` to determine whether the ownship/intruder has a nominal maneuver before TCA. A nominal maneuver is any horizontal or vertical maneuver that is in the generated ownship/intruder trajectory. These are distinct from maneuvers issued by a DAA system.|
| Computing metadata | <ul><li>`computeEncProperties.m`</li><li>`preallocateEncProperties.m`</li><li>`getCPAMetrics.m`</li><li>`getNominalManeuvers.m`</li></ui> |`preallocateEncProperties.m` preallocates two structs for encounter metadata including intruder/ownship height and speed at TCA, encounter weight, and encounter duration. <br><br>`computeEncProperties.m` outputs structs populated with encounter metadata. <br><br> The function calls `getCPAMetrics.m` to compute HMD, VMD, TCA, and whether an NMAC occurs. <br><br> The function also calls `getNominalManeuvers.m` to determine whether the ownship/intruder has a nominal maneuver before TCA. A nominal maneuver is any horizontal or vertical maneuver that is in the generated ownship/intruder trajectory. These are distinct from maneuvers issued by a DAA system.|
| Outputting Encounters (Waypoints or Events) | <ul><li>`compute_delta_heading.m`</li><li>`readTrajFiles.m`</li><li>`ScriptedEncounter.m`</li><li>`wpt2script.m`</li><li>`writeTrajectoryToFile.m`</li></ui> | Generated encounters can be output as both waypoints and Uncorrelated Encounter Model events. See the Example_Outputs [README](../Example_Outputs/README.md) for the format of these outputs.<br><br>`ScriptedEncounter.m` is a class that has all the necessary properties to define a scripted encounter – i.e., initial encounter geometry and Encounter Model events.<br><br>`wpt2script.m` is used to convert waypoints to Uncorrelated Encounter Model events. <br><br> `compute_delta_heading.m` computes turn rates from waypoints, and is a helper function for `wpt2script.m`.<br><br>`writeTrajectoryToFile.m` writes the generated ownship and intruder trajectories to a text file.<br><br>`readTrajFiles.m` can be used to read the trajectory file data into a results struct.|

## 3rd Party Code
Expand All @@ -37,7 +37,7 @@ minmax.h | Min, Max macros | | GNU General Public License version 2 | No | No

DISTRIBUTION STATEMENT A. Approved for public release. Distribution is unlimited.

© 2018, 2019, 2020 Massachusetts Institute of Technology.
© 2018, 2019, 2020, 2021 Massachusetts Institute of Technology.

This material is based upon work supported by the National Aeronautics and Space Administration under Air Force Contract No. FA8702-15-D-0001. Any opinions, findings, conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Aeronautics and Space Administration .

Expand Down
13 changes: 6 additions & 7 deletions Encounter_Generation_Tool/ScriptedEncounter.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
% Copyright 2018 - 2020, MIT Lincoln Laboratory
% SPDX-License-Identifier: X11
%%
classdef ScriptedEncounter
% Copyright 2018 - 2021, MIT Lincoln Laboratory
% SPDX-License-Identifier: X11
%SCRIPTEDENCOUNTER An encounter between one or more aircraft
% The initial geometry and subsequent controls of a scripted
% encounter between two or more aircraft
Expand All @@ -20,14 +19,14 @@
pitch_rad @double% Initial pitch angle
bank_rad @double% Initial bank angle
a_ftpss @double% Initial longitudinal acceleration

% Subsequent controls

updates @ EncounterModelEvents % Array of length this.numberOfAircraft of EncounterModelEvents objects

% Metadata
runTime_s @double; % Duration of encounter
altLayer @double; % Altitude layer are 500-1200, 1200-3000, 3000-5000, 5000-18000 for uncorrelated model
altLayer @double; % Altitude layer could consist of 50-500, 500-1200, 1200-3000, 3000-5000, 5000-18000 for uncorrelated models

end

Expand All @@ -51,7 +50,7 @@
this.pitch_rad(k) = initial.( [ 'theta' num2str(k) '_rad' ] );
this.bank_rad(k) = initial.( [ 'phi' num2str(k) '_rad' ] );
this.a_ftpss(k) = initial.( [ 'a' num2str(k) '_ftpss' ] );

this.updates(k) = EncounterModelEvents( 'event', varargin{k} );
end
end
Expand Down
Loading

0 comments on commit 99a03b2

Please sign in to comment.