ctkDependencyGraph.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkDependencyGraph_h
  15. #define __ctkDependencyGraph_h
  16. // Qt includes
  17. #include <QString>
  18. #include <QList>
  19. // CTK includes
  20. #include "CTKCoreExport.h"
  21. class CTK_CORE_EXPORT ctkDependencyGraph
  22. {
  23. public:
  24. ctkDependencyGraph(int nvertices);
  25. ~ctkDependencyGraph();
  26. void printAdditionalInfo();
  27. void printGraph();
  28. /// Get the number of vertices associated with current graph
  29. int numberOfVertices();
  30. /// Get the number of edges associated with current graph
  31. int numberOfEdges();
  32. /// Traverse graph and check for cycle
  33. bool checkForCycle();
  34. /// Return true if there is at least one cycle
  35. bool cycleDetected();
  36. /// If a cycle has been detected, return the origin of the cycle otherwise 0.
  37. int cycleOrigin();
  38. /// If a cycle has been detected, return the end of the cycle otherwise 0.
  39. int cycleEnd();
  40. // The traverse of the tree will print information on standard output
  41. void setVerbose(bool verbose);
  42. /// Insert edge
  43. /// (from, to) indicate a relation between two vertices
  44. /// Note also that vertex id should be >= 1
  45. void insertEdge(int from, int to);
  46. /// Retrieve the paths between two vertices
  47. /// Caller is responsible to clear paths list
  48. void findPaths(int from, int to, QList<QList<int>* >& paths);
  49. /// Retrieve the path between two vertices
  50. void findPath(int from, int to, QList<int>& path);
  51. /// List of edge to exclude
  52. /// An edge is specified using its extremity
  53. void setEdgeListToExclude(const QList<int>& list);
  54. /// The default implementation check if 'edge' is in the list of edge to exclude
  55. /// See setEdgeListToExclude
  56. virtual bool shouldExcludeEdge(int edge);
  57. /// Called each time an edge is visited
  58. virtual void processEdge(int /*from*/, int /*to*/){}
  59. /// Perform a topological search
  60. /// Return false if the graph contains cycles
  61. /// See cycleDetected, cycleOrigin, cycleEnd
  62. bool topologicalSort(QList<int>& sorted);
  63. private:
  64. class ctkInternal;
  65. ctkInternal* Internal;
  66. };
  67. #endif