62#ifndef OR_TOOLS_GRAPH_SHORTEST_PATHS_H_
63#define OR_TOOLS_GRAPH_SHORTEST_PATHS_H_
70#include "absl/log/check.h"
83 std::numeric_limits<uint32_t>::max();
130 std::vector<NodeIndex>* path)
const;
155 std::unique_ptr<PathContainerImpl> container_;
159template <
class GraphType>
161 CHECK(
nodes !=
nullptr);
164 for (
typename GraphType::NodeIterator iterator(
graph); iterator.Ok();
166 nodes->push_back(iterator.Index());
170template <
class GraphType>
172 std::vector<typename GraphType::NodeIndex>*
nodes) {
173 CHECK(
nodes !=
nullptr);
176 for (
const typename GraphType::NodeIndex node :
graph.AllNodes()) {
177 nodes->push_back(node);
186template <
class GraphType>
189 typename GraphType::NodeIndex source,
191 std::vector<typename GraphType::NodeIndex> all_nodes;
198template <
class GraphType>
201 typename GraphType::NodeIndex source,
202 const std::vector<typename GraphType::NodeIndex>& destinations,
204 std::vector<typename GraphType::NodeIndex> sources(1, source);
217template <
class GraphType>
220 typename GraphType::NodeIndex source,
221 typename GraphType::NodeIndex destination) {
222 std::vector<typename GraphType::NodeIndex> sources(1, source);
223 std::vector<typename GraphType::NodeIndex> destinations(1, destination);
231 std::vector<typename GraphType::NodeIndex> path;
232 path_container.
GetPath(source, destination, &path);
238template <
class GraphType>
241 const std::vector<typename GraphType::NodeIndex>& sources,
int num_threads,
243 std::vector<typename GraphType::NodeIndex> all_nodes;
251template <
class GraphType>
254 const std::vector<typename GraphType::NodeIndex>& sources,
255 const std::vector<typename GraphType::NodeIndex>& destinations,
262 (void)path_container;
264 LOG(DFATAL) <<
"Graph type not supported";
269using ::util::ListGraph;
273 const std::vector<ListGraph<>::NodeIndex>& sources,
274 const std::vector<ListGraph<>::NodeIndex>& destinations,
int num_threads,
275 PathContainer* path_container);
277using ::util::StaticGraph;
281 const std::vector<StaticGraph<>::NodeIndex>& sources,
282 const std::vector<StaticGraph<>::NodeIndex>& destinations,
int num_threads,
283 PathContainer* path_container);
285using ::util::ReverseArcListGraph;
288 const ReverseArcListGraph<>&
graph,
290 const std::vector<ReverseArcListGraph<>::NodeIndex>& sources,
291 const std::vector<ReverseArcListGraph<>::NodeIndex>& destinations,
292 int num_threads, PathContainer* path_container);
294using ::util::ReverseArcStaticGraph;
297 const ReverseArcStaticGraph<>&
graph,
299 const std::vector<ReverseArcStaticGraph<>::NodeIndex>& sources,
300 const std::vector<ReverseArcStaticGraph<>::NodeIndex>& destinations,
301 int num_threads, PathContainer* path_container);
303using ::util::ReverseArcMixedGraph;
306 const ReverseArcMixedGraph<>&
graph,
308 const std::vector<ReverseArcMixedGraph<>::NodeIndex>& sources,
309 const std::vector<ReverseArcMixedGraph<>::NodeIndex>& destinations,
310 int num_threads, PathContainer* path_container);
313template <
class GraphType>
317 std::vector<typename GraphType::NodeIndex> all_nodes;
static void BuildInMemoryCompactPathContainer(PathContainer *path_container)
PathContainer & operator=(const PathContainer &)=delete
NodeIndex GetPenultimateNodeInPath(NodeIndex from, NodeIndex to) const
PathContainer(const PathContainer &)=delete
This type is neither copyable nor movable.
void GetPath(NodeIndex from, NodeIndex to, std::vector< NodeIndex > *path) const
PathDistance GetDistance(NodeIndex from, NodeIndex to) const
static void BuildPathDistanceContainer(PathContainer *path_container)
Builds a path container which only stores distances between path nodes.
PathContainerImpl * GetImplementation() const
For internal use only. Returns the internal container implementation.
std::vector< double > arc_lengths
In SWIG mode, we don't want anything besides these top-level includes.
const PathDistance kDisconnectedPathDistance
void GetGraphNodes(const GraphType &graph, std::vector< NodeIndex > *nodes)
Utility function which returns a vector containing all nodes of a graph.
void ComputeOneToAllShortestPaths(const GraphType &graph, const std::vector< PathDistance > &arc_lengths, typename GraphType::NodeIndex source, PathContainer *const path_container)
Computes shortest paths from the node 'source' to all nodes in the graph.
void ComputeAllToAllShortestPathsWithMultipleThreads(const GraphType &graph, const std::vector< PathDistance > &arc_lengths, int num_threads, PathContainer *const path_container)
Computes shortest paths between all nodes of the graph.
std::vector< typename GraphType::NodeIndex > ComputeOneToOneShortestPath(const GraphType &graph, const std::vector< PathDistance > &arc_lengths, typename GraphType::NodeIndex source, typename GraphType::NodeIndex destination)
void ComputeOneToManyShortestPaths(const GraphType &graph, const std::vector< PathDistance > &arc_lengths, typename GraphType::NodeIndex source, const std::vector< typename GraphType::NodeIndex > &destinations, PathContainer *const path_container)
Computes shortest paths from the node 'source' to nodes in 'destinations'.
void ComputeManyToAllShortestPathsWithMultipleThreads(const GraphType &graph, const std::vector< PathDistance > &arc_lengths, const std::vector< typename GraphType::NodeIndex > &sources, int num_threads, PathContainer *const path_container)
void GetGraphNodesFromGraph(const GraphType &graph, std::vector< typename GraphType::NodeIndex > *nodes)
void ComputeManyToManyShortestPathsWithMultipleThreads(const ListGraph<> &graph, const std::vector< PathDistance > &arc_lengths, const std::vector< ListGraph<>::NodeIndex > &sources, const std::vector< ListGraph<>::NodeIndex > &destinations, int num_threads, PathContainer *const path_container)
trees with all degrees equal to