ctkDependencyGraph.h 1.8 KB

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