Skip to main content

CrossTraffic transportations library

Project description

Transportations Library

A comprehensive Rust-based library implementing transportation engineering methodologies (e.g. the Highway Capacity Manual (HCM)) with Python bindings.

What this covers

Currently implements:

  • Highway Capacity Manual (HCM) Chapter 15: Two-Lane Highways analysis
  • Other chapters are to be added in future releases

Installation

Prerequisites

  • Rust: Install from rustup.rs
  • Python: 3.10 or higher
  • UV: Modern Python package manager (recommended)

Using UV (Recommended)

# Clone the repository
git clone https://github.com/crosstraffic/transportations-library
cd transportations-library

# Create and activate virtual environment
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install in development mode
uv pip install maturin pytest
maturin develop --release

Using pip

# Install dependencies
pip install maturin pytest

# Build and install
maturin develop --release

From PyPI

pip install transportations-library

Quick Start

For Two Lane Highways.

Python Usage

import transportations_library as tl

# Create a highway segment
segment = tl.Segment(
    passing_type=0,     # Passing Constrained
    length=1.5,         # 1.5 miles
    grade=2.0,          # 2% grade
    spl=55.0,           # 55 mph speed limit
    volume=800.0,       # 800 veh/hr
    phf=0.95,           # Peak hour factor
    phv=5.0             # 5% heavy vehicles
)

# Create highway facility
highway = tl.TwoLaneHighways([segment])

# Perform complete analysis
seg_num = 0
demand_flow, opposing_flow, capacity = highway.determine_demand_flow(seg_num)
ffs = highway.determine_free_flow_speed(seg_num)
avg_speed, _ = highway.estimate_average_speed(seg_num)
percent_followers = highway.estimate_percent_followers(seg_num)
follower_density = highway.determine_follower_density_pc_pz(seg_num)
los = highway.determine_segment_los(seg_num, avg_speed, capacity)

print(f"Level of Service: {los}")
print(f"Average Speed: {avg_speed:.1f} mph")
print(f"Follower Density: {follower_density:.1f} followers/mile")

Subsegment sections.

# Highway with horizontal curves
subsegments = [
    tl.SubSegment(length=2640.0, design_rad=800.0, sup_ele=4.0),  # Curved section
    tl.SubSegment(length=2640.0, design_rad=0.0, sup_ele=0.0)     # Tangent section
]

segment_with_curves = tl.Segment(
    passing_type=0, length=1.0, grade=3.0, spl=55.0,
    is_hc=True,  # Has horizontal curves
    subsegments=subsegments,
    volume=900.0, phf=0.92, phv=8.0
)

highway = tl.TwoLaneHighways([segment_with_curves])
# ... perform analysis

Parameter Constraints

The library exports all HCM/AASHTO parameter constraints as JSON, which can be used by validators and knowledge graphs:

import transportations_library as tl
import json

# Get all constraints
constraints = json.loads(tl.get_constraints())
print(f"Version: {constraints['version']}")

# Access specific constraint
lane_width = constraints['two_lane_highways']['lane_width']
print(f"Lane width: {lane_width['min']}-{lane_width['max']} {lane_width['unit']}")
print(f"Source: {lane_width['source']}")
# Output: Lane width: 9.0-12.0 ft
# Output: Source: HCM 7th Edition, Exhibit 15-8

# Validate inputs directly
errors = tl.validate_input(lane_width=8.0)  # Invalid - below 9 ft
print(errors)
# Output: ['lane_width = 8 ft is outside valid range [9, 12]. Source: HCM 7th Edition, Exhibit 15-8']

Available constraints include:

  • lane_width, shoulder_width (range)
  • passing_type, horizontal_class, vertical_class (enum)
  • grade, phf, phv, speed_limit (range)
  • speed_radius (table lookup - AASHTO Table 3-7)

Testing

Run Tests

# Rust tests
cargo test

# Python tests
pytest tests/

# With coverage
pytest tests/ --cov=transportations_library

# Integration tests for chapter 15
cargo test --test chapter15_integration

Note: If you want to have changes in the Rust code to be reflected in Python, you need to run cargo clean and maturin develop again after making changes.

Example Test Cases

The library includes comprehensive test cases based on HCM examples:

  • Case 1: Basic passing constrained segment
  • Case 2: Segment with horizontal curves
  • Case 3: Multi-segment facility with different passing types
  • Case 4: Steep grade conditions with heavy vehicles

Development

Project Structure

transportations-library/
├── src/
│   ├── hcm/
│   │   ├── chapter15/           # Two-lane highways implementation
│   │   └── common.rs            # Shared HCM utilities
│   ├── copython/                # Python bindings
│   ├── utils.rs                 # Mathematical utilities
│   └── lib.rs                   # Library root
├── tests/                       # Integration tests
├── examples/                    # Usage examples
└── Cargo.toml                   # Rust configuration

Building from Source

# Development build
cargo build

# Release build
cargo build --release

# Build Python wheel
maturin build --release

# Development install with changes
cargo clean && maturin develop --release

Pipeline

The project uses GitHub Actions for CI/CD, including:

  • Running tests on push and pull requests
  • Building and publishing to Test PyPI on alpha releases
  • Building and publishing to Cargo and PyPI on new releases

To test the alpha release from Test PyPI, use:

pip install --no-cache-dir --verbose -i https://test.pypi.org/simple/ transportations-library==0.1.9a4

Versioning follows Semantic Versioning.

Also, you can find the latest alpha releases on Test PyPI.

Citation

If you use transportations-library or CrossTraffic in your research, please cite it as follows:

@software{tamaru2025tralib,
  title = {Transportations Library: Transportation knowledge management platform},
  author = {Tamaru, Rei},
  year = {2025},
  url = {https://github.com/crosstraffic/transportations-library},
  doi = {10.5281/zenodo.17295792},
}

You can also use the DOI to cite a specific version: DOI

Alternatively, you can find the citation information in the CITATION.cff file in this repository, which follows the Citation File Format standard.


Note: This library implements established transportation engineering methodologies for educational and professional use. Users should verify results and apply appropriate engineering judgment for real-world applications.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

transportations_library-0.1.11.tar.gz (799.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

transportations_library-0.1.11-cp312-cp312-win_amd64.whl (199.7 kB view details)

Uploaded CPython 3.12Windows x86-64

transportations_library-0.1.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (318.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

transportations_library-0.1.11-cp312-cp312-macosx_11_0_arm64.whl (293.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

transportations_library-0.1.11-cp311-cp311-win_amd64.whl (198.8 kB view details)

Uploaded CPython 3.11Windows x86-64

transportations_library-0.1.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (318.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

transportations_library-0.1.11-cp311-cp311-macosx_11_0_arm64.whl (294.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

transportations_library-0.1.11-cp310-cp310-win_amd64.whl (198.7 kB view details)

Uploaded CPython 3.10Windows x86-64

transportations_library-0.1.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (318.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

transportations_library-0.1.11-cp310-cp310-macosx_11_0_arm64.whl (294.6 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file transportations_library-0.1.11.tar.gz.

File metadata

  • Download URL: transportations_library-0.1.11.tar.gz
  • Upload date:
  • Size: 799.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for transportations_library-0.1.11.tar.gz
Algorithm Hash digest
SHA256 ba551593347e4890fc7384dbcd6f4765d9bddc81e4130e7f818711e49bc4cffa
MD5 56d789f75cc1caba69d975e82255964b
BLAKE2b-256 ebad189200d8f7d00541608ebcc74c56d5ceefc60efa06ba68926f68c7fa5d83

See more details on using hashes here.

Provenance

The following attestation bundles were made for transportations_library-0.1.11.tar.gz:

Publisher: release.yaml on crosstraffic/transportations-library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file transportations_library-0.1.11-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for transportations_library-0.1.11-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 65db80bd999f03ec1f27020a41038e9a10875099a24441945cd1854ad6412f9f
MD5 6cd1c69eeabcbdf7c7432ce35d03b9ac
BLAKE2b-256 3c190bbef2edcf1c63f2096c28d339483ad43b3eb821e4aa28fd3b1f5c18ff2f

See more details on using hashes here.

Provenance

The following attestation bundles were made for transportations_library-0.1.11-cp312-cp312-win_amd64.whl:

Publisher: release.yaml on crosstraffic/transportations-library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file transportations_library-0.1.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for transportations_library-0.1.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 165a7d56cbf33490835cbb0d53584ab7514f6eae32372286b04152eeab351c70
MD5 f1ce49cf760bcd8b8fbf76084a91349a
BLAKE2b-256 cd92a6ff11ad979713e27053116cfbe6c8d81e171744fc74dff3fdf1a305b864

See more details on using hashes here.

Provenance

The following attestation bundles were made for transportations_library-0.1.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yaml on crosstraffic/transportations-library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file transportations_library-0.1.11-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for transportations_library-0.1.11-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 249a2f7ed9b45ca3d9c614776f481229dce6121d173ad30cec32471b4305361b
MD5 97f853d695ce6ab6f425f650cf079a68
BLAKE2b-256 3f579a70dd0411a8e36d730a6e22d301cc925a47785698f74834426ee157d4af

See more details on using hashes here.

Provenance

The following attestation bundles were made for transportations_library-0.1.11-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yaml on crosstraffic/transportations-library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file transportations_library-0.1.11-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for transportations_library-0.1.11-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b4832fb65d75a84959d44cb87d71b9647a41e375707e6bc6f8e6d44255b35740
MD5 d9ef19628aec1504623ccc1ed9974337
BLAKE2b-256 f014e54c3695da5f9e5c94e8fb5ce6568c1f37e9f3440beed33c45c4dc7561a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for transportations_library-0.1.11-cp311-cp311-win_amd64.whl:

Publisher: release.yaml on crosstraffic/transportations-library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file transportations_library-0.1.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for transportations_library-0.1.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2d9986ff3dd6878c0d0d79bae309211aed46dfa121c64fb810b5bf61e57c06ff
MD5 b6a1e75734e476cee123d592465c9383
BLAKE2b-256 75f609e01ab1d579d919b5c185f91a836dc4ab6aad0622a9239374d7a06a5f79

See more details on using hashes here.

Provenance

The following attestation bundles were made for transportations_library-0.1.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yaml on crosstraffic/transportations-library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file transportations_library-0.1.11-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for transportations_library-0.1.11-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6b2de42bf5fb2cd713245b74c75882a3730a5c11a94b0400bac25fdfe16c9bca
MD5 3c1ee69b5c5773ed2838ddf6d41f5711
BLAKE2b-256 7e6ed369b7cab1d3a4985a48964719d1927ee6158648da1a87fda5d0bd3431c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for transportations_library-0.1.11-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release.yaml on crosstraffic/transportations-library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file transportations_library-0.1.11-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for transportations_library-0.1.11-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 89704637b2f848ab96214a855b71eb51a82cdab58e785e61d24be87a32613285
MD5 179309534fbed48e002052aa5d102d0e
BLAKE2b-256 9dfdabbd789f89f8ee25ed7220b1ced706bbaed54ac189676cd27ed7f88a0078

See more details on using hashes here.

Provenance

The following attestation bundles were made for transportations_library-0.1.11-cp310-cp310-win_amd64.whl:

Publisher: release.yaml on crosstraffic/transportations-library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file transportations_library-0.1.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for transportations_library-0.1.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e222edf61ab9903806525aa373e7650041822d6131750a3f049328d12bc5c907
MD5 220332d6e391e741b46d3d66734826e3
BLAKE2b-256 cb021a6500da8b402324def2d067b6f8e07079862dc50ff270ba436dd9af1615

See more details on using hashes here.

Provenance

The following attestation bundles were made for transportations_library-0.1.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yaml on crosstraffic/transportations-library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file transportations_library-0.1.11-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for transportations_library-0.1.11-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 53a3fead538327fc3824e1b5148f0e38771ba4d019dfe1c3f1d852f19d103c8b
MD5 d66fd684a4b5603c7ba22b57d4a61e29
BLAKE2b-256 adf78ff6612884233d07f45ee89c66d9c66f69e4075328b10388ad3914a896e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for transportations_library-0.1.11-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: release.yaml on crosstraffic/transportations-library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page