ctkDependencyGraph.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef __ctkDependencyGraph_h
  2. #define __ctkDependencyGraph_h
  3. // QT includes
  4. #include <QString>
  5. #include <QList>
  6. /// CTK includes
  7. #include "CTKCoreExport.h"
  8. class CTK_CORE_EXPORT ctkDependencyGraph
  9. {
  10. public:
  11. ctkDependencyGraph(int nvertices, int nedges);
  12. ~ctkDependencyGraph();
  13. void printAdditionalInfo();
  14. void printGraph();
  15. /// Get the number of vertices associated with current graph
  16. int numberOfVertices();
  17. /// Get the number of edges associated with current graph
  18. int numberOfEdges();
  19. /// Traverse graph and check for cycle
  20. bool checkForCycle();
  21. /// Return true if there is at least one cycle
  22. bool cycleDetected();
  23. /// If a cycle has been detected, return the origin of the cycle otherwise 0.
  24. int cycleOrigin();
  25. /// If a cycle has been detected, return the end of the cycle otherwise 0.
  26. int cycleEnd();
  27. // The traverse of the tree will print information on standard output
  28. void setVerbose(bool verbose);
  29. /// Insert edge
  30. /// (from, to) indicate a relation between two vertices
  31. /// Note also that vertex id should be >= 1
  32. void insertEdge(int from, int to);
  33. /// Retrieve the path between two vertices
  34. void findPath(int from, int to, QList<int>& path);
  35. /// List of edge to exclude
  36. /// An edge is specified using its extremity
  37. void setEdgeListToExclude(const QList<int>& list);
  38. /// The default implementation check if 'edge' is in the list of edge to exclude
  39. /// See setEdgeListToExclude
  40. virtual bool shouldExcludeEdge(int edge);
  41. /// Called each time an edge is visited
  42. virtual void processEdge(int /*from*/, int /*to*/){}
  43. /// Perform a topological search
  44. /// Return false if the graph contains cycles
  45. /// See cycleDetected, cycleOrigin, cycleEnd
  46. bool topologicalSort(QList<int>& sorted);
  47. private:
  48. class ctkInternal;
  49. ctkInternal* Internal;
  50. };
  51. #endif