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.
Files changed (27) hide show
  1. {scgraph-3.2.0 → scgraph-3.2.2}/CMakeLists.txt +5 -1
  2. {scgraph-3.2.0 → scgraph-3.2.2}/PKG-INFO +1 -1
  3. {scgraph-3.2.0 → scgraph-3.2.2}/build/cp314-cp314-linux_x86_64/CMakeFiles/CheckCXX/CMakeLists.txt +1 -1
  4. {scgraph-3.2.0 → scgraph-3.2.2}/pyproject.toml +1 -1
  5. {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/cpp/bindings/graph_bindings.cpp +3 -0
  6. {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/cpp/src/contraction_hierarchies.hpp +1 -0
  7. {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/cpp/src/graph.cpp +3 -1
  8. {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/cpp/src/graph.hpp +2 -0
  9. {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/cpp/src/graph_utils.cpp +1 -0
  10. {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/cpp/src/transit_node_routing.cpp +21 -7
  11. {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/cpp/src/transit_node_routing.hpp +1 -0
  12. {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/transit_node_routing.py +15 -11
  13. {scgraph-3.2.0 → scgraph-3.2.2}/LICENSE +0 -0
  14. {scgraph-3.2.0 → scgraph-3.2.2}/README.md +0 -0
  15. {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/__init__.py +0 -0
  16. {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/contraction_hierarchies.py +0 -0
  17. {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/cpp/src/bmssp.hpp +0 -0
  18. {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/cpp/src/contraction_hierarchies.cpp +0 -0
  19. {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/cpp/src/graph_utils.hpp +0 -0
  20. {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/geograph.py +0 -0
  21. {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/graph.py +0 -0
  22. {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/graph_utils.py +0 -0
  23. {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/grid.py +0 -0
  24. {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/helpers/__init__.py +0 -0
  25. {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/helpers/geojson.py +0 -0
  26. {scgraph-3.2.0 → scgraph-3.2.2}/scgraph/helpers/visvalingam.py +0 -0
  27. {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
- set(CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -DNDEBUG")
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scgraph
3
- Version: 3.2.0
3
+ Version: 3.2.2
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
@@ -1,4 +1,4 @@
1
- cmake_minimum_required(VERSION 4.3.1)
1
+ cmake_minimum_required(VERSION 4.3.2)
2
2
  set(CMAKE_MODULE_PATH "")
3
3
 
4
4
  project(CheckCXX LANGUAGES CXX)
@@ -26,7 +26,7 @@ include = [
26
26
 
27
27
  [project]
28
28
  name = "scgraph"
29
- version = "3.2.0"
29
+ version = "3.2.2"
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"}
@@ -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"
@@ -5,6 +5,7 @@
5
5
  #include <string>
6
6
  #include <functional>
7
7
  #include <optional>
8
+ #include <tuple>
8
9
  #include "graph_utils.hpp"
9
10
 
10
11
  class CHGraph {
@@ -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
- throw std::runtime_error("TNRGraph has not been set. Use set_tnr_graph() first.");
469
+ create_tnr_hierarchy();
468
470
  }
469
471
  return __tnr_graph__->search(origin_id, destination_id, length_only);
470
472
  }
@@ -1,4 +1,6 @@
1
1
  #pragma once
2
+ #include <vector>
3
+ #include <unordered_map>
2
4
  #include <set>
3
5
  #include <functional>
4
6
  #include <optional>
@@ -1,6 +1,7 @@
1
1
  #include "graph_utils.hpp"
2
2
  #include <stdexcept>
3
3
  #include <algorithm>
4
+ #include <string>
4
5
 
5
6
  std::set<int> get_origin_ids(const std::variant<int, std::set<int>>& origin_id) {
6
7
  if (std::holds_alternative<int>(origin_id)) {
@@ -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
- 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;
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
 
@@ -4,6 +4,7 @@
4
4
  #include <utility>
5
5
  #include <set>
6
6
  #include <optional>
7
+ #include <functional>
7
8
  #include "contraction_hierarchies.hpp"
8
9
 
9
10
  class TNRGraph : public CHGraph {
@@ -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