ctkDependencyGraph.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. All rights reserved.
  5. Distributed under a BSD License. See LICENSE.txt file.
  6. This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even
  7. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the above copyright notice for more information.
  9. =========================================================================*/
  10. #ifndef __ctkDependencyGraph_h
  11. #define __ctkDependencyGraph_h
  12. // Qt includes
  13. #include <QString>
  14. #include <QList>
  15. // CTK includes
  16. #include "CTKCoreExport.h"
  17. class CTK_CORE_EXPORT ctkDependencyGraph
  18. {
  19. public:
  20. ctkDependencyGraph(int nvertices);
  21. ~ctkDependencyGraph();
  22. void printAdditionalInfo();
  23. void printGraph();
  24. /// Get the number of vertices associated with current graph
  25. int numberOfVertices();
  26. /// Get the number of edges associated with current graph
  27. int numberOfEdges();
  28. /// Traverse graph and check for cycle
  29. bool checkForCycle();
  30. /// Return true if there is at least one cycle
  31. bool cycleDetected();
  32. /// If a cycle has been detected, return the origin of the cycle otherwise 0.
  33. int cycleOrigin();
  34. /// If a cycle has been detected, return the end of the cycle otherwise 0.
  35. int cycleEnd();
  36. // The traverse of the tree will print information on standard output
  37. void setVerbose(bool verbose);
  38. /// Insert edge
  39. /// (from, to) indicate a relation between two vertices
  40. /// Note also that vertex id should be >= 1
  41. void insertEdge(int from, int to);
  42. /// Retrieve the paths between two vertices
  43. /// Caller is responsible to clear paths list
  44. void findPaths(int from, int to, QList<QList<int>* >& paths);
  45. /// Retrieve the path between two vertices
  46. void findPath(int from, int to, QList<int>& path);
  47. /// List of edge to exclude
  48. /// An edge is specified using its extremity
  49. void setEdgeListToExclude(const QList<int>& list);
  50. /// The default implementation check if 'edge' is in the list of edge to exclude
  51. /// See setEdgeListToExclude
  52. virtual bool shouldExcludeEdge(int edge);
  53. /// Called each time an edge is visited
  54. virtual void processEdge(int /*from*/, int /*to*/){}
  55. /// Perform a topological search
  56. /// Return false if the graph contains cycles
  57. /// See cycleDetected, cycleOrigin, cycleEnd
  58. bool topologicalSort(QList<int>& sorted);
  59. private:
  60. class ctkInternal;
  61. ctkInternal* Internal;
  62. };
  63. #endif