scgraph 3.2.0__tar.gz → 3.2.2__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.
- {scgraph-3.2.0 → scgraph-3.2.2}/CMakeLists.txt +5 -1
- {scgraph-3.2.0 → scgraph-3.2.2}/PKG-INFO +1 -1
- {scgraph-3.2.0 → scgraph-3.2.2}/build/cp314-cp314-linux_x86_64/CMakeFiles/CheckCXX/CMakeLists.txt +1 -1
- {scgraph-3.2.0 → scgraph-3.2.2}/pyproject.toml +1 -1
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/cpp/bindings/graph_bindings.cpp +3 -0
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/cpp/src/contraction_hierarchies.hpp +1 -0
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/cpp/src/graph.cpp +3 -1
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/cpp/src/graph.hpp +2 -0
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/cpp/src/graph_utils.cpp +1 -0
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/cpp/src/transit_node_routing.cpp +21 -7
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/cpp/src/transit_node_routing.hpp +1 -0
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/transit_node_routing.py +15 -11
- {scgraph-3.2.0 → scgraph-3.2.2}/LICENSE +0 -0
- {scgraph-3.2.0 → scgraph-3.2.2}/README.md +0 -0
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/__init__.py +0 -0
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/contraction_hierarchies.py +0 -0
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/cpp/src/bmssp.hpp +0 -0
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/cpp/src/contraction_hierarchies.cpp +0 -0
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/cpp/src/graph_utils.hpp +0 -0
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/geograph.py +0 -0
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/graph.py +0 -0
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/graph_utils.py +0 -0
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/grid.py +0 -0
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/helpers/__init__.py +0 -0
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/helpers/geojson.py +0 -0
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/helpers/visvalingam.py +0 -0
- {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/utils.py +0 -0
|
@@ -49,7 +49,11 @@ else()
|
|
|
49
49
|
# OPTIMIZATION FLAGS
|
|
50
50
|
# -----------------------------
|
|
51
51
|
set(CMAKE_BUILD_TYPE Release)
|
|
52
|
-
|
|
52
|
+
if(MSVC)
|
|
53
|
+
set(CMAKE_CXX_FLAGS_RELEASE "/O2 /DNDEBUG")
|
|
54
|
+
else()
|
|
55
|
+
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -DNDEBUG")
|
|
56
|
+
endif()
|
|
53
57
|
|
|
54
58
|
# -----------------------------
|
|
55
59
|
# Find Packages
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
#include <nanobind/stl/tuple.h>
|
|
11
11
|
#include <nanobind/stl/shared_ptr.h>
|
|
12
12
|
#include <nanobind/operators.h>
|
|
13
|
+
#include <string>
|
|
14
|
+
#include <stdexcept>
|
|
15
|
+
#include <memory>
|
|
13
16
|
#include "../src/graph.hpp"
|
|
14
17
|
#include "../src/contraction_hierarchies.hpp"
|
|
15
18
|
#include "../src/transit_node_routing.hpp"
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
#include <stdexcept>
|
|
7
7
|
#include <algorithm>
|
|
8
8
|
#include <iostream>
|
|
9
|
+
#include <cmath>
|
|
10
|
+
#include <functional>
|
|
9
11
|
|
|
10
12
|
// Constructor
|
|
11
13
|
Graph::Graph(const std::vector<std::unordered_map<int, double>>& graph_data, bool validate)
|
|
@@ -464,7 +466,7 @@ void Graph::set_tnr_graph(std::shared_ptr<TNRGraph> tnr_graph) {
|
|
|
464
466
|
|
|
465
467
|
GraphResult Graph::tnr(int origin_id, int destination_id, bool length_only) {
|
|
466
468
|
if (__tnr_graph__ == nullptr) {
|
|
467
|
-
|
|
469
|
+
create_tnr_hierarchy();
|
|
468
470
|
}
|
|
469
471
|
return __tnr_graph__->search(origin_id, destination_id, length_only);
|
|
470
472
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
#include <algorithm>
|
|
4
4
|
#include <limits>
|
|
5
5
|
#include <iostream>
|
|
6
|
+
#include <functional>
|
|
6
7
|
|
|
7
8
|
TNRGraph::TNRGraph(const std::vector<std::unordered_map<int, double>>& graph,
|
|
8
9
|
int num_transit_nodes,
|
|
@@ -66,16 +67,29 @@ TNRGraph::TNRGraph(const std::vector<std::unordered_map<int, double>>& graph,
|
|
|
66
67
|
backward_access_nodes[i] = compute_access_nodes(i, false);
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
// 3. Compute Distance Table
|
|
70
|
+
// 3. Compute Distance Table using full Dijkstra on original_graph (one tree per transit origin)
|
|
71
|
+
size_t n = original_graph.size();
|
|
70
72
|
for (int origin : transit_nodes) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
std::vector<double> dist(n, std::numeric_limits<double>::infinity());
|
|
74
|
+
dist[origin] = 0.0;
|
|
75
|
+
using PQItem = std::pair<double, int>;
|
|
76
|
+
std::priority_queue<PQItem, std::vector<PQItem>, std::greater<PQItem>> pq;
|
|
77
|
+
pq.push({0.0, origin});
|
|
78
|
+
while (!pq.empty()) {
|
|
79
|
+
auto [d, u] = pq.top();
|
|
80
|
+
pq.pop();
|
|
81
|
+
if (d > dist[u]) continue;
|
|
82
|
+
for (const auto& [v, w] : original_graph[u]) {
|
|
83
|
+
double nd = d + w;
|
|
84
|
+
if (nd < dist[v]) {
|
|
85
|
+
dist[v] = nd;
|
|
86
|
+
pq.push({nd, v});
|
|
87
|
+
}
|
|
77
88
|
}
|
|
78
89
|
}
|
|
90
|
+
for (int target : transit_nodes) {
|
|
91
|
+
distance_table[{origin, target}] = dist[target];
|
|
92
|
+
}
|
|
79
93
|
}
|
|
80
94
|
}
|
|
81
95
|
|
|
@@ -139,22 +139,26 @@ class TNRGraphPreprocessing:
|
|
|
139
139
|
for i in range(self.nodes_count)
|
|
140
140
|
]
|
|
141
141
|
|
|
142
|
-
# 3. Compute Distance Table
|
|
142
|
+
# 3. Compute Distance Table using full Dijkstra on original_graph (one tree per transit origin)
|
|
143
143
|
self.distance_table = {}
|
|
144
144
|
t_nodes_list = list(self.transit_nodes)
|
|
145
|
+
n = len(self.original_graph)
|
|
145
146
|
|
|
146
|
-
# Note: This is O(T^2) which is slow for Python.
|
|
147
|
-
# For a production implementation, we'd use many-to-one Dijkstra.
|
|
148
147
|
for origin in t_nodes_list:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
148
|
+
dist = [float("inf")] * n
|
|
149
|
+
dist[origin] = 0
|
|
150
|
+
open_leaves = [(0, origin)]
|
|
151
|
+
while open_leaves:
|
|
152
|
+
d, u = heappop(open_leaves)
|
|
153
|
+
if d > dist[u]:
|
|
154
154
|
continue
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
155
|
+
for v, w in self.original_graph[u].items():
|
|
156
|
+
nd = d + w
|
|
157
|
+
if nd < dist[v]:
|
|
158
|
+
dist[v] = nd
|
|
159
|
+
heappush(open_leaves, (nd, v))
|
|
160
|
+
for target in t_nodes_list:
|
|
161
|
+
self.distance_table[(origin, target)] = dist[target]
|
|
158
162
|
|
|
159
163
|
|
|
160
164
|
class TNRGraphAlgorithms:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|