scgraph 3.2.0__tar.gz → 3.2.1__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.
Files changed (27) hide show
  1. {scgraph-3.2.0 → scgraph-3.2.1}/PKG-INFO +1 -1
  2. {scgraph-3.2.0 → scgraph-3.2.1}/pyproject.toml +1 -1
  3. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/cpp/src/graph.cpp +1 -1
  4. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/cpp/src/transit_node_routing.cpp +20 -7
  5. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/transit_node_routing.py +15 -11
  6. {scgraph-3.2.0 → scgraph-3.2.1}/CMakeLists.txt +0 -0
  7. {scgraph-3.2.0 → scgraph-3.2.1}/LICENSE +0 -0
  8. {scgraph-3.2.0 → scgraph-3.2.1}/README.md +0 -0
  9. {scgraph-3.2.0 → scgraph-3.2.1}/build/cp314-cp314-linux_x86_64/CMakeFiles/CheckCXX/CMakeLists.txt +0 -0
  10. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/__init__.py +0 -0
  11. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/contraction_hierarchies.py +0 -0
  12. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/cpp/bindings/graph_bindings.cpp +0 -0
  13. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/cpp/src/bmssp.hpp +0 -0
  14. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/cpp/src/contraction_hierarchies.cpp +0 -0
  15. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/cpp/src/contraction_hierarchies.hpp +0 -0
  16. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/cpp/src/graph.hpp +0 -0
  17. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/cpp/src/graph_utils.cpp +0 -0
  18. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/cpp/src/graph_utils.hpp +0 -0
  19. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/cpp/src/transit_node_routing.hpp +0 -0
  20. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/geograph.py +0 -0
  21. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/graph.py +0 -0
  22. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/graph_utils.py +0 -0
  23. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/grid.py +0 -0
  24. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/helpers/__init__.py +0 -0
  25. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/helpers/geojson.py +0 -0
  26. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/helpers/visvalingam.py +0 -0
  27. {scgraph-3.2.0 → scgraph-3.2.1}/scgraph/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scgraph
3
- Version: 3.2.0
3
+ Version: 3.2.1
4
4
  Summary: Determine an approximate distance and route between two points on earth.
5
5
  Author-Email: Connor Makowski <conmak@mit.edu>
6
6
  License-Expression: MIT
@@ -26,7 +26,7 @@ include = [
26
26
 
27
27
  [project]
28
28
  name = "scgraph"
29
- version = "3.2.0"
29
+ version = "3.2.1"
30
30
  description = "Determine an approximate distance and route between two points on earth."
31
31
  authors = [
32
32
  {name="Connor Makowski", email="conmak@mit.edu"}
@@ -464,7 +464,7 @@ void Graph::set_tnr_graph(std::shared_ptr<TNRGraph> tnr_graph) {
464
464
 
465
465
  GraphResult Graph::tnr(int origin_id, int destination_id, bool length_only) {
466
466
  if (__tnr_graph__ == nullptr) {
467
- throw std::runtime_error("TNRGraph has not been set. Use set_tnr_graph() first.");
467
+ create_tnr_hierarchy();
468
468
  }
469
469
  return __tnr_graph__->search(origin_id, destination_id, length_only);
470
470
  }
@@ -66,16 +66,29 @@ TNRGraph::TNRGraph(const std::vector<std::unordered_map<int, double>>& graph,
66
66
  backward_access_nodes[i] = compute_access_nodes(i, false);
67
67
  }
68
68
 
69
- // 3. Compute Distance Table
69
+ // 3. Compute Distance Table using full Dijkstra on original_graph (one tree per transit origin)
70
+ size_t n = original_graph.size();
70
71
  for (int origin : transit_nodes) {
71
- for (int target : transit_nodes) {
72
- if (origin == target) {
73
- distance_table[{origin, target}] = 0.0;
74
- } else {
75
- auto res = CHGraph::search(origin, target);
76
- distance_table[{origin, target}] = res.length;
72
+ std::vector<double> dist(n, std::numeric_limits<double>::infinity());
73
+ dist[origin] = 0.0;
74
+ using PQItem = std::pair<double, int>;
75
+ std::priority_queue<PQItem, std::vector<PQItem>, std::greater<PQItem>> pq;
76
+ pq.push({0.0, origin});
77
+ while (!pq.empty()) {
78
+ auto [d, u] = pq.top();
79
+ pq.pop();
80
+ if (d > dist[u]) continue;
81
+ for (const auto& [v, w] : original_graph[u]) {
82
+ double nd = d + w;
83
+ if (nd < dist[v]) {
84
+ dist[v] = nd;
85
+ pq.push({nd, v});
86
+ }
77
87
  }
78
88
  }
89
+ for (int target : transit_nodes) {
90
+ distance_table[{origin, target}] = dist[target];
91
+ }
79
92
  }
80
93
  }
81
94
 
@@ -139,22 +139,26 @@ class TNRGraphPreprocessing:
139
139
  for i in range(self.nodes_count)
140
140
  ]
141
141
 
142
- # 3. Compute Distance Table between transit nodes
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
- # We use CH search for distance
150
- # This can be optimized by using a simpler Dijkstra if we're only going transit-to-transit
151
- for target in t_nodes_list:
152
- if origin == target:
153
- self.distance_table[(origin, target)] = 0
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
- # Bidirectional CH search is very fast
156
- res = CHGraph.search(self, origin, target)
157
- self.distance_table[(origin, target)] = res["length"]
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