Skip to main content

mobility-mode-sequence-search

Rust package for mode-sequence search in mobility.

Scope

This package owns:

  • compact indexing of mode and cost data
  • top-k mode-sequence search
  • chain-level parallelism
  • a Python extension API that accepts and returns columnar data

The main mobility repository remains responsible for orchestration, validation, and any fallback Python implementation.

How It Works

This package searches feasible mode sequences for an ordered chain of places.

For example, if someone goes from home to a shop, feasible answers might include:

  • walk, walk
  • car outbound, car return
  • bike outbound, bike return

Feasibility is constrained by a few simple rules:

  • a vehicle can only be used if it is currently at the traveler's location
  • if a vehicle leaves home, it must end back at home
  • some outbound choices come in matched pairs, requiring a linked return mode later in the same subtour

Conceptually, the algorithm has four stages:

  1. Split long chains into smaller home-to-home segments when possible.
  2. Search each segment incrementally, always expanding the cheapest partial answer first.
  3. Merge the best segment-level answers into full-chain answers.
  4. Keep only the leading answers needed to reach the requested cumulative probability threshold.

Before search, each input chain is closed internally by appending the starting location to the end. This matches the legacy Python backend, which searches a closed tour rather than the raw caller-provided chain.

Pseudocode

for each chain:
  split the chain into home-to-home segments

  for each segment:
    start with one empty partial answer

    while there are still partial answers to explore:
      take the cheapest partial answer so far

      if it already covers every leg:
        if all vehicles are back home:
          save it as a feasible full answer
        continue

      look up the next leg's available modes

      for each allowed mode:
        update vehicle locations
        update any forced future return-mode rule

        if the partial answer is still feasible:
          put the extended partial answer back into the queue

  merge the best segment answers into full-chain answers
  prune the low-probability tail
  write the retained answers as output rows

Implementation details are in rust/search.rs and rust/input.rs.

Python API

import polars as pl
from mobility_mode_sequence_search import search_mode_sequences

result = search_mode_sequences(
    location_chain_steps=pl.DataFrame(...),
    leg_mode_costs=pl.DataFrame(...),
    mode_metadata=pl.DataFrame(...),
    k_sequences=20,
    cumulative_prob_threshold=0.98,
    n_threads=None,
)

Input Schemas

location_chain_steps

Grouped form:

  • utility_profile_id: UInt32 (optional, defaults to zero)
  • dest_seq_id: UInt64
  • locations: List[UInt32]

Long-form:

  • utility_profile_id: UInt32 (optional, defaults to zero)
  • dest_seq_id: UInt64
  • seq_step_index: UInt32
  • location: UInt32

leg_mode_costs

  • utility_profile_id: UInt32 (optional, defaults to zero)
  • origin: UInt32
  • destination: UInt32
  • mode_id: UInt16
  • cost: Float64

mode_metadata

  • mode_id: UInt16
  • needs_vehicle: Boolean
  • vehicle_id: UInt8 | Utf8 | null
  • multimodal: Boolean
  • is_return_mode: Boolean
  • return_mode_id: UInt16 | null

At the package boundary, vehicle_id may be integer/null or string/null. String labels are normalized internally into numeric ids before search. Mixed integer and string representations within one call are rejected.

Several utility profiles can be searched in one call. Chains read the costs with the same utility_profile_id, while mode metadata and the Rayon thread pool are shared across all profiles. Each referenced profile must provide the mode costs needed by its chains. Calls without the column keep the original single-profile behavior.

Output Schema

  • utility_profile_id: UInt32 (when supplied on the chains)
  • dest_seq_id: UInt64
  • mode_seq_index: UInt32
  • seq_step_index: UInt32
  • location: UInt32
  • mode_index: UInt16

Development

mamba run -n mobility python -m pip install -e .[dev]
mamba run -n mobility python -m pytest
mamba run -n mobility python -m maturin build --release

Performance Fixture

A standalone synthetic performance case is available at tests/perf_synthetic_case.py.

Example:

mamba run -n mobility python tests/perf_synthetic_case.py --n-chains 2000 --chain-len 18 --n-locations 128 --k-sequences 20

Metadata

Release files for mobility-mode-sequence-search 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mobility-mode-sequence-search 0.1.2
File Size Uploaded Provenance Actions
mobility_mode_sequence_search-0.1.2.tar.gz 22.1 kB With provenance Details for mobility_mode_sequence_search-0.1.2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for mobility-mode-sequence-search 0.1.2
File Interpreter ABI Platform Actions
mobility_mode_sequence_search-0.1.2-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for mobility_mode_sequence_search-0.1.2-cp311-abi3-win_amd64.whl
mobility_mode_sequence_search-0.1.2-cp311-abi3-manylinux_2_34_x86_64.whl CPython 3.11 abi3 Linux glibc 2.34+ x86-64 Details for mobility_mode_sequence_search-0.1.2-cp311-abi3-manylinux_2_34_x86_64.whl
mobility_mode_sequence_search-0.1.2-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for mobility_mode_sequence_search-0.1.2-cp311-abi3-macosx_11_0_arm64.whl

Total release size: 852.4 kB

Release files / mobility_mode_sequence_search-0.1.2.tar.gz

Download URL mobility_mode_sequence_search-0.1.2.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
321ba2a7648339def0139d6a7797c7489441d075b598a13a4007688634f3898a
BLAKE2b-256 checksum
How to use checksums
528d41c5382731e9cbc4522023dc9dadba83e4c6f423b898d3da6dccb83613b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / mobility_mode_sequence_search-0.1.2-cp311-abi3-win_amd64.whl

Download URL mobility_mode_sequence_search-0.1.2-cp311-abi3-win_amd64.whl
Size 209.5 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
3b66fc8d0f488cf56defd652603d37a4dbd400ac35fb731cc867231e4e9e2f52
BLAKE2b-256 checksum
How to use checksums
a5a99a13d253c4fa0e8449eb93908f4f6fc043ebe0c51eee834560fb3f2e35db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / mobility_mode_sequence_search-0.1.2-cp311-abi3-manylinux_2_34_x86_64.whl

Download URL mobility_mode_sequence_search-0.1.2-cp311-abi3-manylinux_2_34_x86_64.whl
Size 329.3 kB
Tags CPython 3.11 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
b8c0888e7002837802e6c64d826b971a8df992d2e7bd52b43efc643e7fc22d6f
BLAKE2b-256 checksum
How to use checksums
08ca3991b55373a06caf77510c701d5ace289cc40b695462a9c29339166b983c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / mobility_mode_sequence_search-0.1.2-cp311-abi3-macosx_11_0_arm64.whl

Download URL mobility_mode_sequence_search-0.1.2-cp311-abi3-macosx_11_0_arm64.whl
Size 291.4 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0f1b8e8147bc887c713d25c9168cbe2b4135ccdacfb8488f90a905612181e6e5
BLAKE2b-256 checksum
How to use checksums
191812221d693816666b11bf7078161fb0f157641a3aba1aab6835b19a069eac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Security for mobility-mode-sequence-search 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for mobility_mode_sequence_search-0.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page