Official implementation of LETI: Learned Space-Filling Curve for Efficient Trajectory Indexing in Key-Value Databases.
- Python 3.8 or higher
- pip package manager
- Clone this repository:
git clone <repository-url>
cd LETI-RLLSFC- Install dependencies:
pip install -r requirements.txtOr install in development mode:
pip install -e .Trajectory files should be in pipe-delimited format:
trajectory_id|timestamp|longitude|latitude
1|2023-01-01 00:00:00|116.397|39.908
1|2023-01-01 00:01:00|116.398|39.909
2|2023-01-01 00:00:00|116.400|39.910
...
Query files are in JSON format:
[{"min_lon": 116.3, "min_lat": 39.8, "max_lon": 116.5, "max_lat": 40.0}]Query datasets should be organized as:
resource/queries/<dataset>/<distribution>/
queries_train.json
queries_val.json
queries_test.json
Where <distribution> is one of: gaussian, skewed, or uniform.
See resource/README.md for detailed format specifications.
The system exports learned traversal orders as JSON files. These files define the optimized space-filling curve order for trajectory indexing.
A learned order file contains two main sections: ordering and metadata.
{
"ordering": [
{
"quad_code": 0, "order": 0,
"parent": {
"alpha": 2, "beta": 2,
"level": 0, "element_code": 0,
"xmin": 0.0, "ymin": 0.0, "xmax": 1.0, "ymax": 1.0
},
"coverage": {
"effective_subtree_count": 15,
"effective_subtree_orders": [1, 2, 3, "..."]
}
},
"..."
],
"metadata": {
"total_cells": 256, "active_cells": 128,
"spatial_boundary": {"xmin": 115.29, "ymin": 39.00, "xmax": 117.83, "ymax": 41.50},
"quadtree_max_level": 7, "global_alpha": 2, "global_beta": 2,
"generation_timestamp": "20xx-xx-xxTxx:xx:xx",
"version": "1.0",
"order_source": "rl_quadorder",
"effective_subtree_contiguous": false,
"partition_search": [[2, 2], [8, 8]],
"max_partition": 64,
"max_shape_count": 16,
"min_trajs": 10
}
}Each entry in the ordering array represents a quadtree cell in the learned traversal order:
quad_code: Unique identifier for the quadtree cell, computed from its quadrant sequenceorder: Position in the traversal orderparent: Cell properties and spatial informationalpha: Horizontal partition parameter (cell width = parent_width / alpha)beta: Vertical partition parameter (cell height = parent_height / beta)level: Depth in the quadtree (0 = root)element_code: Same asquad_code, kept for compatibilityxmin,ymin,xmax,ymax: Spatial bounding box coordinates
coverage: Subtree coverage informationeffective_subtree_count: Number of descendant cells in the active treeeffective_subtree_orders: Order indices of all descendants (omitted for XZ orders)
Global information about the learned order:
total_cells: Total number of cells in the complete quadtreeactive_cells: Number of non-pruned cells in the traversal orderspatial_boundary: Global spatial extentxmin,ymin,xmax,ymax: Bounding box of the entire dataset
quadtree_max_level: Maximum depth of the quadtreeglobal_alpha: Default horizontal partition parameterglobal_beta: Default vertical partition parametergeneration_timestamp: ISO 8601 timestamp of when the order was generatedversion: Format versionorder_source: How the order was generated"rl_quadorder": Learned via reinforcement learning"default_xz_order": Standard Z-order"hilbert_order": Hilbert curve
effective_subtree_contiguous: Whether subtrees are contiguous in the order (True for XZ Order)partition_search: Range of partition parameters explored during optimizationmax_partition: Maximum partition size (alpha × beta) usedmax_shape_countMaximum number of unique signatures per cellmin_trajs: Minimum trajectory count threshold for pruning
Generate queries for a dataset:
python scripts/preprocess/generate_queries.py --dataset tdriveTrain the RL model with configuration:
python -m scripts.experiments.run_pipeline --config configs/experiments/default/config.yaml --name default