dijkstra-fast-cpp 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.4
2
+ Name: dijkstra-fast-cpp
3
+ Version: 0.1.0
4
+ Summary: A blazing fast C++ Dijkstra shortest path routing solver wrapped in Cython with map intersection and JSON path export
5
+ Author-email: CodingWizard34 <developer@example.com>
6
+ Keywords: dijkstra,shortest-path,graph-algorithms,cython,cplusplus,map-routing,navigation
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: C++
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+
14
+ # dijkstra-fast-cpp: High-Performance Dijkstra Map Routing & Intersection Solver
15
+
16
+ A production-grade implementation of **Dijkstra's Shortest Path Algorithm** comparing pure Python against compiled C++ wrapped with Cython. Includes procedural road network generation, geometric line intersection detection, multi-waypoint path solving, interactive Python frontends (Desktop GUI & Streamlit Web), and JSON path export.
17
+
18
+ ---
19
+
20
+ ## ๐Ÿš€ Key Features
21
+
22
+ 1. **Dual Solver Engine**:
23
+ - **Pure Python Baseline**: Uses Python's standard `heapq` module and dynamic lists.
24
+ - **Compiled C++ Engine (`FastGraph`)**: Implements `std::priority_queue` with cache-coherent adjacency vectors and early-exit destination targeting.
25
+ - **Speedup**: Up to **~20xโ€“120x faster** on large graph topologies.
26
+
27
+ 2. **Map & Intersection Generation**:
28
+ - Simulates arterial roads and crossing streets across a 2D map coordinate plane.
29
+ - Computes exact segment-segment geometric intersections using vector cross-products.
30
+ - Subdivides roads at each crossing into a connected planar graph of nodes `[x, y]` and weighted edges `(u, v, distance)`.
31
+ - Generates random waypoints and calculates the optimal route covering all designated points.
32
+
33
+ 3. **JSON Path Export**:
34
+ - Exports the traversed nodes, geographic/pixel coordinates, edge distances, timing benchmarks, and complete graph metadata into a standardized JSON format.
35
+
36
+ 4. **Dual Interactive Python Frontends**:
37
+ - **Desktop GUI (`frontend_gui.py`)**: Native Tkinter window with clickable canvas, real-time visual route rendering, performance metrics, and save-file dialog.
38
+ - **Web Dashboard (`frontend_streamlit.py`)**: Modern browser UI with interactive sliders, Matplotlib dark-mode map plotting, real-time speedup badges, and one-click JSON download.
39
+
40
+ ---
41
+
42
+ ## ๐Ÿ“Š Benchmark Results (Intel 12 Threads, Windows 11, Python 3.14)
43
+
44
+ Measured using `timeit` across multiple sampling passes on random connected graphs:
45
+
46
+ | Graph Nodes (V) | Graph Edges (E) | Pure Python (ms) | Cython FastGraph C++ (ms) | Speedup Factor |
47
+ |:---------------:|:---------------:|:----------------:|:-------------------------:|:--------------:|
48
+ | **1,000** | 4,998 | 0.94 ms | 0.007 ms | **127.2x** |
49
+ | **5,000** | 24,994 | 13.78 ms | 0.686 ms | **20.1x** |
50
+ | **20,000** | 99,994 | 57.57 ms | 2.064 ms | **27.9x** |
51
+ | **50,000** | 249,996 | 357.63 ms | 22.777 ms | **15.7x** |
52
+
53
+ ---
54
+
55
+ ## ๐Ÿ“ฆ Quick Start & Usage
56
+
57
+ ### 1. Installation
58
+
59
+ #### From PyPI:
60
+ ```bash
61
+ pip install dijkstra-fast-cpp
62
+ ```
63
+
64
+ #### From Local Source:
65
+ ```bash
66
+ cd dijkstra_router
67
+ python setup.py build_ext --inplace
68
+ ```
69
+
70
+ ### 2. Python API Usage
71
+
72
+ ```python
73
+ from dijkstra_fast_cpp import FastGraph, dijkstra_python, generate_random_map, export_path_to_json
74
+
75
+ # 1. Generate a procedural road map with intersections
76
+ network = generate_random_map(width=800, height=600, num_roads=12, num_waypoints=4, seed=42)
77
+
78
+ print(f"Generated {len(network.nodes)} intersections and {len(network.edges)} road edges.")
79
+
80
+ # 2. Fast C++ Dijkstra Query
81
+ graph = FastGraph(len(network.nodes))
82
+ graph.add_edges_from_list(network.edges)
83
+
84
+ # Calculate shortest path covering waypoints
85
+ total_dist, path, reachable = graph.cover_waypoints(network.waypoints)
86
+ print(f"Shortest path distance: {total_dist:.2f} px")
87
+ print(f"Path nodes: {path}")
88
+
89
+ # 3. Export path to JSON
90
+ json_output = export_path_to_json(
91
+ network_nodes=network.nodes,
92
+ network_edges=network.edges,
93
+ path_node_ids=path,
94
+ total_distance=total_dist,
95
+ waypoints=network.waypoints,
96
+ output_filepath="shortest_path.json"
97
+ )
98
+ ```
99
+
100
+ ---
101
+
102
+ ## ๐Ÿ–ฅ๏ธ Running the Frontends
103
+
104
+ ### Option A: Desktop GUI (Tkinter)
105
+ ```bash
106
+ python frontend_gui.py
107
+ ```
108
+ *Click anywhere on the map to add custom waypoints, drag sliders, and click "Export Path to JSON".*
109
+
110
+ ### Option B: Streamlit Web Dashboard
111
+ ```bash
112
+ streamlit run frontend_streamlit.py
113
+ ```
114
+
115
+ ---
116
+
117
+ ## ๐Ÿงช Running Tests & Benchmarks
118
+
119
+ ```bash
120
+ # Run unit tests
121
+ python -m unittest discover -s tests -v
122
+
123
+ # Run performance benchmark
124
+ python benchmark.py
125
+ ```
126
+
127
+ ---
128
+
129
+ ## ๐Ÿ“„ License
130
+ MIT License.
@@ -0,0 +1,117 @@
1
+ # dijkstra-fast-cpp: High-Performance Dijkstra Map Routing & Intersection Solver
2
+
3
+ A production-grade implementation of **Dijkstra's Shortest Path Algorithm** comparing pure Python against compiled C++ wrapped with Cython. Includes procedural road network generation, geometric line intersection detection, multi-waypoint path solving, interactive Python frontends (Desktop GUI & Streamlit Web), and JSON path export.
4
+
5
+ ---
6
+
7
+ ## ๐Ÿš€ Key Features
8
+
9
+ 1. **Dual Solver Engine**:
10
+ - **Pure Python Baseline**: Uses Python's standard `heapq` module and dynamic lists.
11
+ - **Compiled C++ Engine (`FastGraph`)**: Implements `std::priority_queue` with cache-coherent adjacency vectors and early-exit destination targeting.
12
+ - **Speedup**: Up to **~20xโ€“120x faster** on large graph topologies.
13
+
14
+ 2. **Map & Intersection Generation**:
15
+ - Simulates arterial roads and crossing streets across a 2D map coordinate plane.
16
+ - Computes exact segment-segment geometric intersections using vector cross-products.
17
+ - Subdivides roads at each crossing into a connected planar graph of nodes `[x, y]` and weighted edges `(u, v, distance)`.
18
+ - Generates random waypoints and calculates the optimal route covering all designated points.
19
+
20
+ 3. **JSON Path Export**:
21
+ - Exports the traversed nodes, geographic/pixel coordinates, edge distances, timing benchmarks, and complete graph metadata into a standardized JSON format.
22
+
23
+ 4. **Dual Interactive Python Frontends**:
24
+ - **Desktop GUI (`frontend_gui.py`)**: Native Tkinter window with clickable canvas, real-time visual route rendering, performance metrics, and save-file dialog.
25
+ - **Web Dashboard (`frontend_streamlit.py`)**: Modern browser UI with interactive sliders, Matplotlib dark-mode map plotting, real-time speedup badges, and one-click JSON download.
26
+
27
+ ---
28
+
29
+ ## ๐Ÿ“Š Benchmark Results (Intel 12 Threads, Windows 11, Python 3.14)
30
+
31
+ Measured using `timeit` across multiple sampling passes on random connected graphs:
32
+
33
+ | Graph Nodes (V) | Graph Edges (E) | Pure Python (ms) | Cython FastGraph C++ (ms) | Speedup Factor |
34
+ |:---------------:|:---------------:|:----------------:|:-------------------------:|:--------------:|
35
+ | **1,000** | 4,998 | 0.94 ms | 0.007 ms | **127.2x** |
36
+ | **5,000** | 24,994 | 13.78 ms | 0.686 ms | **20.1x** |
37
+ | **20,000** | 99,994 | 57.57 ms | 2.064 ms | **27.9x** |
38
+ | **50,000** | 249,996 | 357.63 ms | 22.777 ms | **15.7x** |
39
+
40
+ ---
41
+
42
+ ## ๐Ÿ“ฆ Quick Start & Usage
43
+
44
+ ### 1. Installation
45
+
46
+ #### From PyPI:
47
+ ```bash
48
+ pip install dijkstra-fast-cpp
49
+ ```
50
+
51
+ #### From Local Source:
52
+ ```bash
53
+ cd dijkstra_router
54
+ python setup.py build_ext --inplace
55
+ ```
56
+
57
+ ### 2. Python API Usage
58
+
59
+ ```python
60
+ from dijkstra_fast_cpp import FastGraph, dijkstra_python, generate_random_map, export_path_to_json
61
+
62
+ # 1. Generate a procedural road map with intersections
63
+ network = generate_random_map(width=800, height=600, num_roads=12, num_waypoints=4, seed=42)
64
+
65
+ print(f"Generated {len(network.nodes)} intersections and {len(network.edges)} road edges.")
66
+
67
+ # 2. Fast C++ Dijkstra Query
68
+ graph = FastGraph(len(network.nodes))
69
+ graph.add_edges_from_list(network.edges)
70
+
71
+ # Calculate shortest path covering waypoints
72
+ total_dist, path, reachable = graph.cover_waypoints(network.waypoints)
73
+ print(f"Shortest path distance: {total_dist:.2f} px")
74
+ print(f"Path nodes: {path}")
75
+
76
+ # 3. Export path to JSON
77
+ json_output = export_path_to_json(
78
+ network_nodes=network.nodes,
79
+ network_edges=network.edges,
80
+ path_node_ids=path,
81
+ total_distance=total_dist,
82
+ waypoints=network.waypoints,
83
+ output_filepath="shortest_path.json"
84
+ )
85
+ ```
86
+
87
+ ---
88
+
89
+ ## ๐Ÿ–ฅ๏ธ Running the Frontends
90
+
91
+ ### Option A: Desktop GUI (Tkinter)
92
+ ```bash
93
+ python frontend_gui.py
94
+ ```
95
+ *Click anywhere on the map to add custom waypoints, drag sliders, and click "Export Path to JSON".*
96
+
97
+ ### Option B: Streamlit Web Dashboard
98
+ ```bash
99
+ streamlit run frontend_streamlit.py
100
+ ```
101
+
102
+ ---
103
+
104
+ ## ๐Ÿงช Running Tests & Benchmarks
105
+
106
+ ```bash
107
+ # Run unit tests
108
+ python -m unittest discover -s tests -v
109
+
110
+ # Run performance benchmark
111
+ python benchmark.py
112
+ ```
113
+
114
+ ---
115
+
116
+ ## ๐Ÿ“„ License
117
+ MIT License.
@@ -0,0 +1,30 @@
1
+ """
2
+ dijkstra-fast-cpp: High-performance Dijkstra Shortest Path Solver for Map Routing
3
+ Comparing Pure Python against Cython-wrapped C++ std::priority_queue with JSON export.
4
+ """
5
+
6
+ from .dijkstra_pure import dijkstra_python, dijkstra_cover_waypoints_python
7
+ from .map_generator import RoadNetwork, generate_random_map, segment_intersection, euclidean_distance
8
+ from .json_exporter import export_path_to_json
9
+
10
+ try:
11
+ from ._dijkstra_cython import dijkstra_cython, dijkstra_cover_waypoints_cython, FastGraph
12
+ CYTHON_AVAILABLE = True
13
+ except ImportError:
14
+ dijkstra_cython = None
15
+ dijkstra_cover_waypoints_cython = None
16
+ FastGraph = None
17
+ CYTHON_AVAILABLE = False
18
+
19
+ __version__ = "0.1.0"
20
+ __all__ = [
21
+ "dijkstra_python",
22
+ "dijkstra_cover_waypoints_python",
23
+ "dijkstra_cython",
24
+ "dijkstra_cover_waypoints_cython",
25
+ "FastGraph",
26
+ "RoadNetwork",
27
+ "generate_random_map",
28
+ "export_path_to_json",
29
+ "CYTHON_AVAILABLE"
30
+ ]