HiPOP 2.0.0__tar.gz → 3.0.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 (71) hide show
  1. {hipop-2.0.0 → hipop-3.0.1}/.clang-tidy +7 -0
  2. {hipop-2.0.0 → hipop-3.0.1}/.github/workflows/deploy.yaml +1 -1
  3. {hipop-2.0.0 → hipop-3.0.1}/PKG-INFO +1 -1
  4. hipop-3.0.1/VERSION.txt +1 -0
  5. {hipop-2.0.0 → hipop-3.0.1}/cpp/examples/ParallelKShortestPath.cpp +11 -16
  6. hipop-3.0.1/cpp/include/hipop/create.h +62 -0
  7. {hipop-2.0.0 → hipop-3.0.1}/cpp/include/hipop/graph.h +152 -36
  8. hipop-3.0.1/cpp/include/hipop/graph_path.h +452 -0
  9. {hipop-2.0.0 → hipop-3.0.1}/cpp/include/hipop/graph_path_cost.h +10 -17
  10. {hipop-2.0.0 → hipop-3.0.1}/cpp/include/hipop/shortest_path.h +70 -45
  11. {hipop-2.0.0 → hipop-3.0.1}/cpp/src/graph.cpp +31 -36
  12. {hipop-2.0.0 → hipop-3.0.1}/cpp/src/graph_path_cost.cpp +5 -6
  13. {hipop-2.0.0 → hipop-3.0.1}/cpp/src/shortest_path.cpp +286 -310
  14. {hipop-2.0.0 → hipop-3.0.1}/cpp/tests/CMakeLists.txt +1 -0
  15. {hipop-2.0.0 → hipop-3.0.1}/cpp/tests/helpers.h +40 -27
  16. {hipop-2.0.0 → hipop-3.0.1}/cpp/tests/testAStar.cpp +20 -18
  17. {hipop-2.0.0 → hipop-3.0.1}/cpp/tests/testDijkstra.cpp +36 -35
  18. {hipop-2.0.0 → hipop-3.0.1}/cpp/tests/testDijkstraSingleSource.cpp +77 -36
  19. {hipop-2.0.0 → hipop-3.0.1}/cpp/tests/testGraph.cpp +38 -51
  20. hipop-3.0.1/cpp/tests/testGraphPath.cpp +577 -0
  21. {hipop-2.0.0 → hipop-3.0.1}/cpp/tests/testKShortestPath.cpp +4 -3
  22. {hipop-2.0.0 → hipop-3.0.1}/cpp/tests/testYenKShortestPath.cpp +4 -3
  23. {hipop-2.0.0 → hipop-3.0.1}/pyproject.toml +1 -1
  24. {hipop-2.0.0 → hipop-3.0.1}/python/hipop/cpp/graph.cpp +170 -15
  25. {hipop-2.0.0 → hipop-3.0.1}/python/hipop/cpp/shortest_path.cpp +16 -3
  26. {hipop-2.0.0 → hipop-3.0.1}/python/hipop/graph.py +5 -0
  27. hipop-3.0.1/python/tests/test_GraphPath.py +222 -0
  28. {hipop-2.0.0 → hipop-3.0.1}/python/tests/test_ShortestPath.py +32 -17
  29. hipop-2.0.0/VERSION.txt +0 -1
  30. hipop-2.0.0/cpp/include/hipop/create.h +0 -8
  31. {hipop-2.0.0 → hipop-3.0.1}/.gitattributes +0 -0
  32. {hipop-2.0.0 → hipop-3.0.1}/.github/workflows/ci.yaml +0 -0
  33. {hipop-2.0.0 → hipop-3.0.1}/.gitignore +0 -0
  34. {hipop-2.0.0 → hipop-3.0.1}/.pre-commit-config.yaml +0 -0
  35. {hipop-2.0.0 → hipop-3.0.1}/CMakeLists.txt +0 -0
  36. {hipop-2.0.0 → hipop-3.0.1}/CONTRIBUTING.md +0 -0
  37. {hipop-2.0.0 → hipop-3.0.1}/DEVELOPMENT.md +0 -0
  38. {hipop-2.0.0 → hipop-3.0.1}/LICENSE +0 -0
  39. {hipop-2.0.0 → hipop-3.0.1}/README.md +0 -0
  40. {hipop-2.0.0 → hipop-3.0.1}/cmake/ClangTidySettings.cmake +0 -0
  41. {hipop-2.0.0 → hipop-3.0.1}/cmake/IPOSettings.cmake +0 -0
  42. {hipop-2.0.0 → hipop-3.0.1}/cmake/MainSettings.cmake +0 -0
  43. {hipop-2.0.0 → hipop-3.0.1}/conda/env.yaml +0 -0
  44. {hipop-2.0.0 → hipop-3.0.1}/cpp/CMakeLists.txt +0 -0
  45. {hipop-2.0.0 → hipop-3.0.1}/cpp/cmake/HipopConfig.cmake.in +0 -0
  46. {hipop-2.0.0 → hipop-3.0.1}/cpp/examples/.clang-tidy +0 -0
  47. {hipop-2.0.0 → hipop-3.0.1}/cpp/examples/CMakeLists.txt +0 -0
  48. {hipop-2.0.0 → hipop-3.0.1}/cpp/include/hipop/string_util.h +0 -0
  49. {hipop-2.0.0 → hipop-3.0.1}/cpp/src/create.cpp +0 -0
  50. {hipop-2.0.0 → hipop-3.0.1}/cpp/tests/.clang-tidy +0 -0
  51. {hipop-2.0.0 → hipop-3.0.1}/cpp/tests/sample_graphs.h +0 -0
  52. {hipop-2.0.0 → hipop-3.0.1}/cpp/tests/testGraphMerge.cpp +0 -0
  53. {hipop-2.0.0 → hipop-3.0.1}/cpp/tests/testManhattan.cpp +0 -0
  54. {hipop-2.0.0 → hipop-3.0.1}/cpp/tests/testStringUtil.cpp +0 -0
  55. {hipop-2.0.0 → hipop-3.0.1}/cpp/tests/testparallelKShortestPath.cpp +0 -0
  56. {hipop-2.0.0 → hipop-3.0.1}/pyrefly.toml +0 -0
  57. {hipop-2.0.0 → hipop-3.0.1}/pytest.toml +0 -0
  58. {hipop-2.0.0 → hipop-3.0.1}/python/CMakeLists.txt +0 -0
  59. {hipop-2.0.0 → hipop-3.0.1}/python/examples/UpdateCosts.py +0 -0
  60. {hipop-2.0.0 → hipop-3.0.1}/python/examples/ksp.py +0 -0
  61. {hipop-2.0.0 → hipop-3.0.1}/python/examples/merge.py +0 -0
  62. {hipop-2.0.0 → hipop-3.0.1}/python/examples/render.py +0 -0
  63. {hipop-2.0.0 → hipop-3.0.1}/python/examples/test.py +0 -0
  64. {hipop-2.0.0 → hipop-3.0.1}/python/hipop/__init__.py.template +0 -0
  65. {hipop-2.0.0 → hipop-3.0.1}/python/hipop/cpp/main.cpp +0 -0
  66. {hipop-2.0.0 → hipop-3.0.1}/python/hipop/py.typed +0 -0
  67. {hipop-2.0.0 → hipop-3.0.1}/python/hipop/render.py +0 -0
  68. {hipop-2.0.0 → hipop-3.0.1}/python/hipop/shortest_path.py +0 -0
  69. {hipop-2.0.0 → hipop-3.0.1}/python/tests/test_Graph.py +0 -0
  70. {hipop-2.0.0 → hipop-3.0.1}/python/tests/test_VersionConsistency.py +0 -0
  71. {hipop-2.0.0 → hipop-3.0.1}/ruff.toml +0 -0
@@ -7,6 +7,7 @@ Checks: # See https://clang.llvm.org/extra/clang-tidy/checks/list.html
7
7
 
8
8
  - cppcoreguidelines-*
9
9
  - misc-include-cleaner # The other misc-* are worth enabling, but that would mean significant code refactoring.
10
+ - misc-non-private-member-variables-in-classes
10
11
  - modernize-*
11
12
  - performance-*
12
13
 
@@ -49,3 +50,9 @@ CheckOptions:
49
50
  # The nanobind STL headers provide the C++ <-> Python type casters through template specializations:
50
51
  # no symbol from them is referenced directly, but they must be included where the conversions happen.
51
52
  misc-include-cleaner.IgnoreHeaders: 'nanobind/stl/.*'
53
+
54
+ # Classes whose fields are ALL public are accepted as plain data structures (to avoid writing
55
+ # trivial getters). Still, this exception to the general rule should be reserved for simple small classes,
56
+ # with no abstraction, and no non-trivial logic implemented in the class.
57
+ # Complex classes MUST keep their fields private (although this check will miss them if they are all public).
58
+ misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: true
@@ -37,7 +37,7 @@ jobs:
37
37
  - ubuntu-latest # Arch: x64
38
38
  - ubuntu-24.04-arm # Arch: arm64
39
39
  - windows-latest # Arch: x64
40
- - macos-14 # Arch: arm64
40
+ - macos-15 # Arch: arm64
41
41
  # Do not use the latest macOS runner to ensure backward compatibility.
42
42
  # See comment on MACOSX_DEPLOYMENT_TARGET in pyproject.toml for more details.
43
43
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: HiPOP
3
- Version: 2.0.0
3
+ Version: 3.0.1
4
4
  Summary: High Performance Optimal Path module
5
5
  Keywords: graph,graph-theory,shortest-path,dijkstra
6
6
  Maintainer-Email: Cécile Becarie <cecile.becarie@univ-eiffel.fr>
@@ -0,0 +1 @@
1
+ 3.0.1
@@ -4,6 +4,7 @@
4
4
  #include <cstdlib>
5
5
  #include <iostream>
6
6
  #include <limits>
7
+ #include <optional>
7
8
  #include <string>
8
9
  #include <unordered_map>
9
10
  #include <vector>
@@ -41,15 +42,12 @@ int main()
41
42
 
42
43
  //auto paths = hipop::parallelKShortestPath(G, origins, destinations, "time", vecMapLabelCosts, {}, 0.1, 0.95, 10, 10, kPaths, 4);
43
44
  auto paths = hipop::parallelDijkstra(G, origins, destinations, vecMapLabelCosts, "time", 1, {});
45
+ const std::optional<hipop::PathCost> &path = paths[0];
44
46
 
45
- std::cout << paths.size() << std::endl;
46
- //std::cout << paths[0].first << std::endl;
47
-
48
- if (paths.size()>0)
49
- {
50
- std::cout << "Cost: " << paths[0].second << std::endl;
51
-
52
- std::cout << "Path size: " << paths[0].first.size()<< std::endl;
47
+ if (path.has_value()) {
48
+ std::cout << "Cost: " << path->second << std::endl;
49
+ std::cout << "Path size (i.e. number of links): " << path->first.size() << std::endl;
50
+ std::cout << "Path: " << path->first << std::endl;
53
51
  }
54
52
 
55
53
  // Update costs
@@ -58,15 +56,12 @@ int main()
58
56
  G.UpdateCosts( maplinkcosts );
59
57
 
60
58
  auto paths2 = hipop::parallelDijkstra(G, origins, destinations, vecMapLabelCosts, "time", 1, {});
59
+ const std::optional<hipop::PathCost> &path2 = paths2[0];
61
60
 
62
- std::cout << paths2.size() << std::endl;
63
- //std::cout << paths[0].first << std::endl;
64
-
65
- if (paths2.size()>0)
66
- {
67
- std::cout << "Cost: " << paths2[0].second << std::endl;
68
-
69
- std::cout << "Path size: " << paths2[0].first.size()<< std::endl;
61
+ if (path2.has_value()) {
62
+ std::cout << "Cost: " << path2->second << std::endl;
63
+ std::cout << "Path size (i.e. number of links): " << path2->first.size() << std::endl;
64
+ std::cout << "Path: " << path2->first << std::endl;
70
65
  }
71
66
 
72
67
  return EXIT_SUCCESS;
@@ -0,0 +1,62 @@
1
+ #pragma once
2
+
3
+ #include <hipop/graph.h>
4
+ #include <hipop/graph_path.h>
5
+ #include <hipop/string_util.h>
6
+
7
+ #include <stdexcept>
8
+ #include <string>
9
+ #include <utility>
10
+ #include <vector>
11
+
12
+
13
+ namespace hipop {
14
+
15
+
16
+ OrientedGraph makeManhattan(int n, double linkLength);
17
+
18
+
19
+ /**
20
+ * Generate an empty path (i.e. a path with no link) relating the node corresponding to originNodeId
21
+ * to itself in the given graph.
22
+ *
23
+ * @throws std::invalid_argument if the given node ID does not exist in the graph.
24
+ */
25
+ inline OrientedGraphPath makeEmptyPath(const OrientedGraph &graph, const std::string &originNodeId) {
26
+ const Node *originNode = graph.findNode(originNodeId);
27
+ if (originNode == nullptr) {
28
+ throw std::invalid_argument(StrCat("[makeEmptyPath] Unknown node ID [", originNodeId, "]."));
29
+ }
30
+ return OrientedGraphPath(originNode);
31
+ }
32
+
33
+
34
+ /**
35
+ * Generate a path made of the links corresponding to the given link IDs in the given graph.
36
+ *
37
+ * @param linkIds Must not be empty.
38
+ * @throws std::invalid_argument if linkIds is empty, if any link ID does not exist in the graph,
39
+ * or if the sequence of links has inconsistent up/down nodes.
40
+ */
41
+ inline OrientedGraphPath makePath(const OrientedGraph &graph, const std::vector<std::string> &linkIds) {
42
+
43
+ if (linkIds.empty()) {
44
+ throw std::invalid_argument("[makePath] Link list cannot be empty.");
45
+ }
46
+
47
+ std::vector<const Link *> links;
48
+ links.reserve(linkIds.size());
49
+ for (const std::string &linkId : linkIds) {
50
+ const Link *link = graph.findLink(linkId);
51
+ if (link == nullptr) {
52
+ throw std::invalid_argument(StrCat("[makePath] Unknown link ID [", linkId, "]."));
53
+ }
54
+ links.emplace_back(link);
55
+ }
56
+
57
+ const Node *origin = links[0]->up();
58
+ return { origin, std::move(links) };
59
+ }
60
+
61
+
62
+ } // namespace hipop
@@ -25,21 +25,25 @@ namespace hipop
25
25
 
26
26
 
27
27
  class Link {
28
+
29
+ std::string id_;
30
+ Node *up_;
31
+ Node *down_;
32
+ double length_;
33
+ mapcosts costs_; // costs_[cost-family][cost-metric] -> cost-value
34
+ std::string label_;
35
+
36
+ friend class OrientedGraph; // Access to private fields is needed to add/remove node/link in the graph.
37
+
28
38
  public:
29
- std::string mid;
30
- const Node *mup;
31
- const Node *mdown;
32
- mapcosts mcosts; // mcosts[cost-family][cost-metric] -> cost-value
33
- std::string mlabel;
34
- double mlength;
35
-
36
- Link(std::string id, const Node *up, const Node *down, double length, mapcosts costs, std::string label) :
37
- mid(std::move(id)),
38
- mup(up),
39
- mdown(down),
40
- mcosts(std::move(costs)),
41
- mlabel(std::move(label)),
42
- mlength(length)
39
+
40
+ Link(std::string id, Node *up, Node *down, double length, mapcosts costs, std::string label) :
41
+ id_(std::move(id)),
42
+ up_(up),
43
+ down_(down),
44
+ length_(length),
45
+ costs_(std::move(costs)),
46
+ label_(std::move(label))
43
47
  {}
44
48
 
45
49
  // Relationships between Node and Link instances are materialized through raw pointers.
@@ -50,12 +54,49 @@ namespace hipop
50
54
  Link &operator=(Link &&other) = delete;
51
55
  ~Link() = default;
52
56
 
57
+ /**
58
+ * ID of the current link (uniqueness guaranteed among the links of a given OrientedGraph instance).
59
+ */
60
+ [[nodiscard]] const std::string &id() const {
61
+ return id_;
62
+ }
63
+
64
+ /**
65
+ * Upstream node (the current link is an outgoing link for this node).
66
+ */
67
+ [[nodiscard]] const Node *up() const {
68
+ return up_;
69
+ }
70
+
71
+ /**
72
+ * Downstream node (the current link is an incoming link for this node).
73
+ */
74
+ [[nodiscard]] const Node *down() const {
75
+ return down_;
76
+ }
77
+
78
+ /**
79
+ * Geometric length of the link.
80
+ */
81
+ [[nodiscard]] double length() const {
82
+ return length_;
83
+ }
84
+
85
+ /**
86
+ * Cost values assigned to the link.
87
+ *
88
+ * @return `costs()[cost-family][cost-metric]` -> cost value
89
+ */
90
+ [[nodiscard]] const mapcosts &costs() const {
91
+ return costs_;
92
+ }
93
+
53
94
  /**
54
95
  * Whether a cost value is set for the current link, assuming the given cost family and cost metric.
55
96
  */
56
97
  [[nodiscard]] bool hasCost(const std::string &costFamily, const std::string &costMetric) const {
57
- auto it1 = mcosts.find(costFamily);
58
- if (it1 == mcosts.end()) {
98
+ auto it1 = costs_.find(costFamily);
99
+ if (it1 == costs_.end()) {
59
100
  return false;
60
101
  }
61
102
  auto it2 = it1->second.find(costMetric);
@@ -74,8 +115,8 @@ namespace hipop
74
115
  * is explicitly set. Still, 0 is returned to match the legacy behavior.
75
116
  */
76
117
  [[nodiscard]] double cost(const std::string &costFamily, const std::string &costMetric) const {
77
- auto it1 = mcosts.find(costFamily);
78
- if (it1 == mcosts.end()) {
118
+ auto it1 = costs_.find(costFamily);
119
+ if (it1 == costs_.end()) {
79
120
  return 0;
80
121
  }
81
122
  auto it2 = it1->second.find(costMetric);
@@ -85,26 +126,38 @@ namespace hipop
85
126
  return it2->second;
86
127
  }
87
128
 
88
- void updateCosts(mapcosts costs) {
89
- mcosts = std::move(costs);
129
+ void setCosts(mapcosts costs) {
130
+ costs_ = std::move(costs);
90
131
  }
132
+
133
+ /**
134
+ * Link label (may be used to categorize links).
135
+ */
136
+ [[nodiscard]] const std::string &label() const {
137
+ return label_;
138
+ }
139
+
91
140
  };
92
141
 
93
142
 
94
143
  class Node {
144
+
145
+ std::string id_;
146
+ std::array<double, 2> position_;
147
+ std::unordered_map<std::string, const Link *> adj_;
148
+ std::unordered_map<std::string, const Link *> radj_;
149
+ std::string label_;
150
+ mapsets excludeMovements_;
151
+
152
+ friend class OrientedGraph; // Access to private fields is needed to add/remove node/link in the graph.
153
+
95
154
  public:
96
- std::string mid;
97
- std::array<double, 2> mposition;
98
- std::unordered_map<std::string, Link* > madj;
99
- std::unordered_map<std::string, Link* > mradj;
100
- std::string mlabel;
101
- mapsets mexclude_movements;
102
-
103
- Node(std::string id, double x, double y, std::string label, mapsets exclude_movements) :
104
- mid(std::move(id)),
105
- mposition{ x, y },
106
- mlabel(std::move(label)),
107
- mexclude_movements(std::move(exclude_movements))
155
+
156
+ Node(std::string id, double x, double y, std::string label, mapsets excludeMovements) :
157
+ id_(std::move(id)),
158
+ position_{ x, y },
159
+ label_(std::move(label)),
160
+ excludeMovements_(std::move(excludeMovements))
108
161
  {}
109
162
 
110
163
  // Relationships between Node and Link instances are materialized through raw pointers.
@@ -115,6 +168,69 @@ namespace hipop
115
168
  Node &operator=(Node &&other) = delete;
116
169
  ~Node() = default;
117
170
 
171
+ /**
172
+ * ID of the current node (uniqueness guaranteed among the nodes of a given OrientedGraph instance).
173
+ */
174
+ [[nodiscard]] const std::string &id() const {
175
+ return id_;
176
+ }
177
+
178
+ /**
179
+ * X/Y coordinates of the current node.
180
+ */
181
+ [[nodiscard]] const std::array<double, 2> &position() const {
182
+ return position_;
183
+ }
184
+
185
+ /**
186
+ * Same as `position()[0]`.
187
+ */
188
+ [[nodiscard]] double x() const {
189
+ return position_[0];
190
+ }
191
+
192
+ /**
193
+ * Same as `position()[1]`.
194
+ */
195
+ [[nodiscard]] double y() const {
196
+ return position_[1];
197
+ }
198
+
199
+ /**
200
+ * Outgoing links from the current node.
201
+ *
202
+ * @return `adj()[adjacent-node-ID]` -> link from the current node to the adjacent node
203
+ */
204
+ [[nodiscard]] const std::unordered_map<std::string, const Link *> &adj() const {
205
+ return adj_;
206
+ }
207
+
208
+ /**
209
+ * Incoming links to the current node.
210
+ *
211
+ * @return `radj()[adjacent-node-ID]` -> link from the adjacent node to the current node
212
+ */
213
+ [[nodiscard]] const std::unordered_map<std::string, const Link *> &radj() const {
214
+ return radj_;
215
+ }
216
+
217
+ /**
218
+ * Node label (may be used to categorize nodes).
219
+ */
220
+ [[nodiscard]] const std::string &label() const {
221
+ return label_;
222
+ }
223
+
224
+ /**
225
+ * Movement restrictions (i.e. forbidden turns) at the current node.
226
+ *
227
+ * @return `excludeMovements()[predecessor-node-ID]` -> IDs of the downstream nodes (i.e. those in `adj()`)
228
+ * that cannot be reached from the current node when arriving from the given predecessor node
229
+ */
230
+ [[nodiscard]] const mapsets &excludeMovements() const {
231
+ return excludeMovements_;
232
+ }
233
+
118
234
  /**
119
235
  * Assuming we follow a path in the graph, and that we come from node `predecessor`,
120
236
  * this method computes all the allowed exit links from the current node, and invokes
@@ -129,10 +245,10 @@ namespace hipop
129
245
  */
130
246
  template<typename Callback>
131
247
  void forEachExit(const std::string &predecessor, Callback &&callback) const {
132
- for (const auto &l : madj) {
133
- auto it = mexclude_movements.find(predecessor);
134
- if (it == mexclude_movements.end() || it->second.find(l.second->mdown->mid) == it->second.end()) {
135
- callback(const_cast<const Link*>(l.second));
248
+ for (const auto &l : adj_) {
249
+ auto it = excludeMovements_.find(predecessor);
250
+ if (it == excludeMovements_.end() || it->second.find(l.second->down()->id()) == it->second.end()) {
251
+ callback(l.second);
136
252
  }
137
253
  }
138
254
  }