bfs.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef IGL_BFS_H
  2. #define IGL_BFS_H
  3. #include "igl_inline.h"
  4. #include <Eigen/Core>
  5. #include <vector>
  6. #include <Eigen/Sparse>
  7. namespace igl
  8. {
  9. /// Traverse a **directed** graph represented by an adjacency list using.
  10. /// breadth first search; outputs Eigen types.
  11. ///
  12. /// @param[in] A #V list of adjacency lists or #V by #V adjacency matrix
  13. /// @param[in] s starting node (index into A)
  14. /// @param[out] D #V list of indices into rows of A in the order in which graph nodes
  15. /// are discovered.
  16. /// @param[out] P #V list of indices into rows of A of predecessor in resulting
  17. /// spanning tree {-1 indicates root/not discovered), order corresponds to
  18. /// V **not** D.
  19. template <
  20. typename AType,
  21. typename DerivedD,
  22. typename DerivedP>
  23. IGL_INLINE void bfs(
  24. const AType & A,
  25. const size_t s,
  26. Eigen::PlainObjectBase<DerivedD> & D,
  27. Eigen::PlainObjectBase<DerivedP> & P);
  28. /// Traverse a **directed** graph represented by an adjacency list using.
  29. /// breadth first search; inputs adjacency lists, outputs lists.
  30. ///
  31. /// @param[in] A #V list of adjacency lists
  32. /// @param[in] s starting node (index into A)
  33. /// @param[out] D #V list of indices into rows of A in the order in which graph nodes
  34. /// are discovered.
  35. /// @param[out] P #V list of indices into rows of A of predecessor in resulting
  36. /// spanning tree {-1 indicates root/not discovered), order corresponds to
  37. /// V **not** D.
  38. template <
  39. typename AType,
  40. typename DType,
  41. typename PType>
  42. IGL_INLINE void bfs(
  43. const std::vector<std::vector<AType> > & A,
  44. const size_t s,
  45. std::vector<DType> & D,
  46. std::vector<PType> & P);
  47. /// \overload
  48. template <
  49. typename AType,
  50. typename DType,
  51. typename PType>
  52. IGL_INLINE void bfs(
  53. const Eigen::SparseCompressedBase<AType> & A,
  54. const size_t s,
  55. std::vector<DType> & D,
  56. std::vector<PType> & P);
  57. }
  58. #ifndef IGL_STATIC_LIBRARY
  59. # include "bfs.cpp"
  60. #endif
  61. #endif