bfs.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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
  11. //
  12. // Inputs:
  13. // A #V list of adjacency lists or #V by #V adjacency matrix
  14. // s starting node (index into A)
  15. // Outputs:
  16. // D #V list of indices into rows of A in the order in which graph nodes
  17. // are discovered.
  18. // P #V list of indices into rows of A of predecessor in resulting
  19. // spanning tree {-1 indicates root/not discovered), order corresponds to
  20. // V **not** D.
  21. template <
  22. typename AType,
  23. typename DerivedD,
  24. typename DerivedP>
  25. IGL_INLINE void bfs(
  26. const AType & A,
  27. const size_t s,
  28. Eigen::PlainObjectBase<DerivedD> & D,
  29. Eigen::PlainObjectBase<DerivedP> & P);
  30. template <
  31. typename AType,
  32. typename DType,
  33. typename PType>
  34. IGL_INLINE void bfs(
  35. const std::vector<std::vector<AType> > & A,
  36. const size_t s,
  37. std::vector<DType> & D,
  38. std::vector<PType> & P);
  39. template <
  40. typename AType,
  41. typename DType,
  42. typename PType>
  43. IGL_INLINE void bfs(
  44. const Eigen::SparseMatrix<AType> & A,
  45. const size_t s,
  46. std::vector<DType> & D,
  47. std::vector<PType> & P);
  48. }
  49. #ifndef IGL_STATIC_LIBRARY
  50. # include "bfs.cpp"
  51. #endif
  52. #endif