ctkDependencyGraph.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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.commontk.org/LICENSE
  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. #if !defined(NO_SYMBOL_EXPORT)
  21. #include "CTKCoreExport.h"
  22. #else
  23. #define CTK_CORE_EXPORT
  24. #endif
  25. class CTK_CORE_EXPORT ctkDependencyGraph
  26. {
  27. public:
  28. ctkDependencyGraph(int nvertices);
  29. virtual ~ctkDependencyGraph();
  30. void printAdditionalInfo();
  31. void printGraph();
  32. /// Get the number of vertices associated with current graph
  33. int numberOfVertices();
  34. /// Get the number of edges associated with current graph
  35. int numberOfEdges();
  36. /// Traverse graph and check for cycle
  37. bool checkForCycle();
  38. /// Return true if there is at least one cycle
  39. bool cycleDetected();
  40. /// If a cycle has been detected, return the origin of the cycle otherwise 0.
  41. int cycleOrigin();
  42. /// If a cycle has been detected, return the end of the cycle otherwise 0.
  43. int cycleEnd();
  44. // The traverse of the tree will print information on standard output
  45. void setVerbose(bool verbose);
  46. /// Insert edge
  47. /// (from, to) indicate a relation between two vertices
  48. /// Note also that vertex id should be >= 1
  49. void insertEdge(int from, int to);
  50. /// Retrieve the paths between two vertices
  51. /// Caller is responsible to clear paths list
  52. void findPaths(int from, int to, QList<QList<int>* >& paths);
  53. /// Retrieve the path between two vertices
  54. void findPath(int from, int to, QList<int>& path);
  55. /// List of edge to exclude
  56. /// An edge is specified using its extremity
  57. void setEdgeListToExclude(const QList<int>& list);
  58. /// The default implementation check if 'edge' is in the list of edge to exclude
  59. /// See setEdgeListToExclude
  60. virtual bool shouldExcludeEdge(int edge);
  61. /// Called each time an edge is visited
  62. virtual void processEdge(int /*from*/, int /*to*/){}
  63. /// Perform a topological sort
  64. /// Return false if the graph contains cycles
  65. /// If a rootId is given, the subgraph starting at the root id is sorted
  66. /// See cycleDetected, cycleOrigin, cycleEnd
  67. bool topologicalSort(QList<int>& sorted, int rootId = -1);
  68. /// Retrieve all vertices with indegree 0
  69. void sourceVertices(QList<int>& sources);
  70. private:
  71. class ctkInternal;
  72. ctkInternal* Internal;
  73. };
  74. #endif